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

Support SIGUSR1 log level incrementing #3685

Merged
merged 4 commits into from
Apr 15, 2020
Merged

Conversation

echlebek
Copy link
Contributor

What is this change?

This commit adds support to sensu-backend and sensu-agent for
incrementing the log level with SIGUSR1. When the process receives
this signal, the log level will be incremented in terms of
verbosity. When the level is at TRACE, the most verbose log level,
and the log level is incremented, it will wrap around to error
level.

Why is this change necessary?

Closes #1742

Does your change need a Changelog entry?

Yes

Were there any complications while making this change?

It's unclear at this time how to support this for Windows.

Have you reviewed and updated the documentation for this change? Is new documentation required?

@hillaryfraley, we will need to document that users can now increase the log level at runtime, with the following commands for backends and agents:

kill -s SIGUSR1 $(pidof sensu-backend)
kill -s SIGUSR1 $(pidof sensu-agent)

How did you verify this change?

I ran the above commands for the backend and agent.

Is this change a patch?

No.

This commit adds support to sensu-backend and sensu-agent for
incrementing the log level with SIGUSR1. When the process receives
this signal, the log level will be incremented in terms of
verbosity. When the level is at TRACE, the most verbose log level,
and the log level is incremented, it will wrap around to error
level.

Signed-off-by: Eric Chlebek <[email protected]>
@echlebek echlebek requested a review from palourde April 13, 2020 21:09
@echlebek echlebek self-assigned this Apr 13, 2020
@echlebek echlebek added this to the 5.20.0 milestone Apr 13, 2020
@palourde
Copy link
Contributor

@echlebek looks like it broke the Windows builds 😱

@echlebek
Copy link
Contributor Author

@palourde I moved the signal handling stuff into some files that won't get built on Windows, which seems to have un-broken the build.

@palourde
Copy link
Contributor

palourde commented Apr 14, 2020

I figured this is expected, but I'm wondering if there's a way to by-pass the following behavior:

When the log level is incremented from trace --> error, the following entry is logged, which is expected:

{"level":"warning","msg":"set log level to error","time":"2020-04-14T18:38:58-04:00"}

However, when we go from error --> warning, the same entry never gets logged. I'm wondering if we could add a condition so when the current log level is error, the entry gets logged after the log level is changed. e.g.

logrus.Warnf("set log level to %s", newLevel)
logrus.SetLevel(newLevel)
// Log back the entry if the level passed from error to warning
if logrus.GetLevel() == logrus.WarningLevel {
	logrus.Warnf("set log level to %s", newLevel)
}

WDYT?

@echlebek
Copy link
Contributor Author

It's a bit of an oddity, but I like that it makes the message appear in all cases. I'll add it!

Copy link
Contributor

@palourde palourde left a comment

Choose a reason for hiding this comment

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

🚀

@echlebek echlebek merged commit 4a69ad0 into master Apr 15, 2020
@echlebek echlebek deleted the feature/log-level-from-signal branch April 15, 2020 00:45
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.

Support changing of log level during runtime
2 participants