-
Notifications
You must be signed in to change notification settings - Fork 20.8k
internal/debug: rename flags in log namespace, fix some pprof flags #22341
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
Conversation
internal/debug/flags.go
Outdated
} | ||
if ctx.GlobalIsSet(debugFlag.Name) { | ||
log.PrintOrigins(ctx.GlobalBool(debugFlag.Name)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There configs are incorrect. GlobalIsSet
will only return true
if the user explicitly set it to something, but they will remain false
if the defaults are left as is. This means that all the flag initialization will be skipped by the code in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that all these calls have side effects, it's a bit messy, you have 4 cases that you need to handle
- no flag is set
- both are set
- legacy is set
- new flag is set
You handled 2 ok-ish. The one where nothing is set is a noop now, and the one were both is set may work, but it might have weird side effects.
What you could do is:
debug := ctx.GlobalBool(debugFlag.Name)
if ctx.GlobalIsSet(legacyDebugFlag.Name) {
log.Warn("The flag --debug is deprecated and will be removed in the future, please use --log.debug")
debug = ctx.GlobalBool(legacyDebugFlag.Name)
}
if ctx.GlobalIsSet(debugFlag.Name) {
debug := ctx.GlobalBool(debugFlag.Name)
}
log.PrintOrigins(debug)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for all the flags below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or
debug := ctx.GlobalBool(debugFlag.Name)
if ctx.GlobalIsSet(legacyDebugFlag.Name) && !ctx.GlobalIsSet(debugFlag.Name) {
log.Warn("The flag --debug is deprecated and will be removed in the future, please use --log.debug")
debug = ctx.GlobalBool(legacyDebugFlag.Name)
}
log.PrintOrigins(debug)
Though this will not warn you if both are set, so the former might be more correct, even if a bit unwieldy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had applied the solution you suggested to memprofilerate
and blockprofilerate
further down. But something I might be missing is whether the initialization methods should be invoked even when the value is empty? i.e. debug
is by default false, does log.PrintOrigins
has to be called explicitly even in that case? Because the only flag that has a non-empty default is verbosity
which is initialised in init()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha now I see that glogger.Vmodule
and glogger.BacktraceAt
set some other variables that might have side-effects if unset. Will fix.
Updated the PR to use Peter's suggested solution for all flags. |
Why should we change it at all? We've had |
…m#22341) This change adds support for logging JSON records when the --log.json flag is given. The --debug and --backtrace flags are deprecated and replaced by --log.debug and --log.backtrace. While changing this, it was noticed that the --memprofilerate and --blockprofilerate were ineffective (they were always overridden even if --pprof.memprofilerate was not set). This is also fixed. Co-authored-by: Felix Lange <fjl@twurst.com>
This PR moves the flags
--debug
,--backtrace
to thelog
namespace (i.e.--log.backtrace
, etc.). It keeps the previous ones but marks them as deprecated. In case both the current and deprecated flags are passed, the deprecated has lower precedence.I noticed that the
--memprofilerate
and--blockprofilerate
are right now ineffective (they're always overridden even if--pprof.memprofilerate
is not set). This is also fixed.