-
Notifications
You must be signed in to change notification settings - Fork 1.2k
🐛 Fix allowed levels for --zap-log-levels flag to align with logr levels #991
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
🐛 Fix allowed levels for --zap-log-levels flag to align with logr levels #991
Conversation
Hi @bharathi-tenneti. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/cc @joelanford @hasbro17 |
Please use unit test cases, to test this fix. |
79dabe0
to
3156051
Compare
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.
Need to clarify what --zap-stacktrace-level=disabled
is for.
Plus some nits on the test cases.
/ok-to-test |
pkg/log/zap/zap.go
Outdated
if o.Level.Enabled(zapcore.DebugLevel) { | ||
o.ZapOpts = append(o.ZapOpts, zap.Development()) | ||
} else { | ||
o.ZapOpts = append(o.ZapOpts, | ||
zap.WrapCore(func(core zapcore.Core) zapcore.Core { | ||
return zapcore.NewSampler(core, time.Second, 100, 100) | ||
})) | ||
} |
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 think its technically okay to use sampling with zapcore.DebugLevel
. It only needs to be disabled starting at zapcore.Level(-2)
.
Also, I don't think we want to force development mode based on the log level.
Given the above details, does the following work?
if o.Level.Enabled(zapcore.DebugLevel) { | |
o.ZapOpts = append(o.ZapOpts, zap.Development()) | |
} else { | |
o.ZapOpts = append(o.ZapOpts, | |
zap.WrapCore(func(core zapcore.Core) zapcore.Core { | |
return zapcore.NewSampler(core, time.Second, 100, 100) | |
})) | |
} | |
if !o.Level.Enabled(zapcore.Level(-2)) { | |
o.ZapOpts = append(o.ZapOpts, | |
zap.WrapCore(func(core zapcore.Core) zapcore.Core { | |
return zapcore.NewSampler(core, time.Second, 100, 100) | |
})) | |
} |
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.
Wouldn't this only cover Level(-2)
,We still need to handle Level(-3)
or 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.
Agree , We can remove the developement mode, and it can be as shown below.
// Disable sampling when we are in debug mode. Otherwise, this will
// cause index out of bounds errors in the sampling code.
if o.Level.Enabled(zapcore.DebugLevel) {
o.ZapOpts = append(o.ZapOpts)
} else {
o.ZapOpts = append(o.ZapOpts,
zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewSampler(core, time.Second, 100, 100)
}))
}
4690ded
to
c31ff8f
Compare
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.
It shows /lgtm /approve for me 👍
/retest |
/lgtm |
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.
/approve
/milestone v0.6.x
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bharathi-tenneti, vincepri The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/label tide/merge-method-squash |
/retest |
…vels (kubernetes-sigs#991) * Fix zap levels to align with logr * Fix sampling logic for debug levels
--Current implementation in
flags.go
has a bug, which is leading to incorrect zap log level to be set.--This PR also focuses on aligning
--zap-log-level
with logr levels.Example:
--zap-log-level=2
should map to using increased verbositylogr.V(2).Info()
.-- This PR also disables Sampling for debug levels with increased verbosity, as they will cause index out of bounds errors in sampling code.
Closes: #990