Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error_limit() function to limit number of error lines per instance #13924

Merged
merged 3 commits into from Nov 1, 2022

Conversation

ktsaou
Copy link
Member

@ktsaou ktsaou commented Nov 1, 2022

This PR adds the function:

error_limit(ERROR_LIMIT *erl, const char *format, ...);

The ERROR_LIMIT *erl parameter can be defined as either global static variable (so that all threads logging will share the same limits) with this:

error_limit_static_global_var(var, log_every_secs, sleep_usecs);

or thread static variable (so that each thread will have its own log limits), with this:

error_limit_static_thread_var(var, log_every_secs, sleep_usecs);

It can be used like this:

            error_limit_static_global_var(erl, 10, 1000);
            error_limit(&erl, "POLLFD: LISTENER: too many open files - used by this thread %zu, max for this thread %zu",
                      p->used, p->limit);

The error_limit() function will:

  1. Sleep the defined amount of time, if sleep_usecs is not zero.
  2. Lock the global log lock to alter the ERROR_LIMIT *erl members.
  3. Respect the flood protection configured by the user.
  4. Log the line the caller wants.
  5. If the count of messages suppressed is not zero, it will append (repeated %zu times in the last %llu secs)
  6. If the sleep time is not zero, it will append (sleeping for %llu microseconds every time this happens)

thiagoftsm
thiagoftsm previously approved these changes Nov 1, 2022
Copy link
Contributor

@thiagoftsm thiagoftsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is working as expected locally. LGTM!

@ktsaou ktsaou merged commit cef305c into netdata:master Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants