-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
log: fix "panic" loglevel parsing for --zap-stacktrace-level option #3040
log: fix "panic" loglevel parsing for --zap-stacktrace-level option #3040
Conversation
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 great. It is just missing to add a fragment. See: https://github.com/operator-framework/operator-sdk/blob/master/changelog/fragments/00-template.yaml
It is used for we create the CHANGELOG for the releases.
4d6c2a8
to
36bb94c
Compare
I looked around for a new place but did not check the |
At one point, we made a decision to explicitly only support the set of zap log levels that overlap with supported I think there are cases where using levels that |
/hold |
Here's the original thread with the decision-making: #873 (comment) |
I more or less got the issue, seems to be a touchy issue, thanks for pointing out. I can use the new code only for |
@vboulineau can you describe what you're trying to accomplish? I may be misunderstanding something, but since logr specifically forbids logging with negative numbers, there's no supported way to log at any level beyond What would be gained by allowing I do wonder if it is even possible to disable stacktraces with the current flag value constraints. If that's ultimately what you're going for, perhaps we should add a new supported |
Also FWIW, we've been working to upstream the logging flags into controller-runtime, and deprecate the SDK's zap flag support as part of our work to transition to Kubebuilder's project layouts. In fact, it appears that controller-runtime may already have support for these levels. |
The original idea from #2319 was to allow disabling stack traces entirely, but as you suggested, it was better to keep stack traces for panic/fatal levels. However, now it seems unlikely that users generate these logs (though it's still possible using I've tested upstream implementation in our operator and it works fine (already available in 0.17), so if you believe that's they way forward I can close that PR. |
@vboulineau If you've got things working upstream, I think that's the best way forward. I was actually looking a little closer at that implementation though, and I think there's a bug in controller-runtime. The There's a similar discrepancy with the In SDK, we designed the level flags to align with the It also looks like it isn't currently possible to enable log levels with verbosity at If these bugs in controller-runtime were fixed such that the implementation aligned with the help text, would that break your use-case and operator again? |
Indeed you're right, upstream is buggy, running this code:
With
With
Which is indeed problematic for logging with several debug levels. I believe, fixing this would bring us back to the same state this PR aimed to solve, except if Really the only feature we'd like to keep is remove stacktraces on "error" loglevel, we'd be happy with any solution that provides that. I think two options are possible here:
I believe first option is a bit better, but not a strong opinion, both makes sense. WDYT? |
@vboulineau Option 1 sounds good to me. |
36bb94c
to
b602297
Compare
Implemented! |
c229ecb
to
b92a61c
Compare
pkg/log/zap/flags.go
Outdated
func intLogLevel(l string) (int, error) { | ||
lower := strings.ToLower(l) | ||
var lvl int | ||
switch lower { | ||
case logLevelDebug: | ||
lvl = -1 | ||
case logLevelInfo: | ||
lvl = 0 | ||
case logLevelError: | ||
lvl = 2 | ||
default: | ||
i, err := strconv.Atoi(lower) | ||
if err != nil { | ||
return lvl, fmt.Errorf("invalid log level \"%s\"", l) | ||
} | ||
|
||
if i > 0 { | ||
lvl = -1 * i | ||
} else { | ||
return lvl, fmt.Errorf("invalid log level \"%s\"", l) | ||
} | ||
} | ||
return lvl, nil | ||
} | ||
|
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.
Nit: move this function back to its original location (after Type()
) to minimize changeset.
pkg/log/zap/flags.go
Outdated
lower := strings.ToLower(l) | ||
var lvl int | ||
switch lower { | ||
case logLevelDebug: | ||
lvl = -1 | ||
case logLevelInfo: | ||
lvl = 0 | ||
case logLevelError: | ||
lvl = 2 | ||
case logLevelPanic: | ||
lvl = 4 | ||
default: | ||
return fmt.Errorf("invalid stacktrace level \"%s\"", l) |
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.
With this change, we would no longer support integer-based stacktrace levels, which would be a regression of an existing feature. Can we still support integer stacktrace levels for values greater than 0?
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 put back previous behaviour, so supporting int log level in stack trace.
7f93d7f
to
506bf0e
Compare
Fixed nits and rebased but CI is still failing on doc part, it does not seem related to this PR? |
@vboulineau Can you rebase to the latest master? I think the issue you're running into has been fixed. |
b1335c8
to
1314d54
Compare
/hold cancel |
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.
LGTM whenever CI decides it wants to pass 😄. Thanks for this!
@@ -26,6 +26,13 @@ import ( | |||
"k8s.io/klog" | |||
) | |||
|
|||
const ( |
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.
@joelanford may not be better we use here the "github.com/sirupsen/logrus" levels definition instead of creating our own const/values as it was done here for example?
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 believe these are int constants (https://github.com/sirupsen/logrus/blob/master/logrus.go#L96), string constants are directly inlined line 25
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.
We're also dealing with zap and logr levels here, not logrus. There don't appear to be string constants for the levels in zap or logr. I think what we're doing here in this PR is fine, and is in fact an improvement in that we now actually have constants rather than inlining them like we have been.
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.
fair enough
@vboulineau Sorry about this but I think we're now running into another separate CI error that will hopefully be fixed by #3158 Might have to rebase one more time after that merges. |
No worries, I'll check every now and then and rebase accordingly |
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.
/lgtm
/approve
Hi @vboulineau, The issue faced in the CI here was fixed in #3158. Could you please rebased it with the master for the pr pass in the CI and allow us to merge it? |
Signed-off-by: Vincent Boulineau <[email protected]>
1314d54
to
ead0212
Compare
New changes are detected. LGTM label has been removed. |
Thank you, CI is green now! |
Description of the change:
Delegate string parsing to zap, allowing any zap-supported level (for both
--zap-level
and--zap-stacktrace-level
)Motivation for the change:
The
--zap-stacktrace-level
option (#2319) is currently not working for any level > error as the parsing will not allow it.I also think it's cleaner to delegate this level parsing to zap itself, it allows anything supported upstream.