Skip to content

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

Merged
merged 4 commits into from
Apr 6, 2021

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Feb 17, 2021

This PR moves the flags --debug, --backtrace to the log 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.

}
if ctx.GlobalIsSet(debugFlag.Name) {
log.PrintOrigins(ctx.GlobalBool(debugFlag.Name))
}
Copy link
Member

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.

Copy link
Member

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)

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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().

Copy link
Contributor Author

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.

@s1na
Copy link
Contributor Author

s1na commented Feb 18, 2021

Updated the PR to use Peter's suggested solution for all flags.

@fjl
Copy link
Contributor

fjl commented Feb 19, 2021

Why should we change it at all? We've had --vmodule and --verbosity since the beginning, and their names are meaningful without the log. prefix.

@s1na
Copy link
Contributor Author

s1na commented Feb 19, 2021

I think @holiman suggested this to make them consistent with the new log.json flag. Also seems some other flags were also grouped under --pprof..

@fjl fjl self-assigned this Mar 30, 2021
@fjl fjl removed the status:triage label Mar 30, 2021
@fjl fjl added this to the 1.10.2 milestone Mar 30, 2021
@fjl fjl force-pushed the cli/log-namespace branch from 53aad7d to c174b4f Compare April 6, 2021 11:34
@fjl fjl merged commit 5338ce4 into ethereum:master Apr 6, 2021
atif-konasl pushed a commit to frozeman/pandora-execution-engine that referenced this pull request Oct 15, 2021
…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>
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.

3 participants