Honor stderrthreshold when logtostderr is enabled#9654
Honor stderrthreshold when logtostderr is enabled#9654blackpiglet merged 2 commits intovelero-io:mainfrom
Conversation
|
Hi @Lyndon-Li, @skriss — gentle ping. Would you be able to review this when you get a chance? Thank you! |
|
Please create an issue if this was a bug/regression. And please run Please include some examples of new behaviors vs old. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@kaovilai Thanks for the feedback! I've created issue #9658 for this. Old vs New BehaviorBefore this PR (klog < v2.140.0 or legacy mode)The After this PRThe Default behavior (unchanged)With the default See: kubernetes/klog#432 for the upstream fix details. |
kaovilai
left a comment
There was a problem hiding this comment.
Note
Responses generated with Claude
| klog.InitFlags(flag.CommandLine) | ||
| // Opt into fixed stderrthreshold behavior (kubernetes/klog#212). | ||
| _ = flag.Set("legacy_stderr_threshold_behavior", "false") | ||
| _ = flag.Set("stderrthreshold", "INFO") |
There was a problem hiding this comment.
nit: Consider adding a comment clarifying that this sets the default, but users can still override it via --stderrthreshold on the command line since flag parsing happens later at Execute() time.
Note
Responses generated with Claude
There was a problem hiding this comment.
Good point! I'll add a clarifying comment. The flag.Set call here sets the programmatic default so that --stderrthreshold=ERROR is the baseline, but since this runs before cmd.Execute() invokes pflag parsing, any explicit --stderrthreshold= on the command line will override it as expected.
|
Thanks @kaovilai! I'll create an issue and add the changelog entry. Behavior comparison:
The key point: default behavior does not change. The fix only matters when users explicitly set I'll push the changelog entry shortly and create the upstream issue. |
|
@kaovilai Done! Here's what I've added:
The Is there anything else you'd like me to address? |
2826fc5 to
323021c
Compare
|
@pierluigilenoci |
|
@blackpiglet Good question. Yes, Here is why: Velero calls What this PR changes is the programmatic default: it calls In summary:
|
|
@blackpiglet Could you please approve the pending CI workflow runs when you get a chance? All checks (PR CI Check, PR Linter Check, PR Changelog Check, PR Codespell Check, E2E test) are currently in |
8330653 to
d556efb
Compare
|
Thank you @blackpiglet for the review and approval! All CI checks should be green now — could this be merged when convenient? Happy to address anything else if needed. |
|
@pierluigilenoci |
|
Sorry, clicked the |
klog v2 defaults -logtostderr to true, which silently ignores the -stderrthreshold flag — all log levels are unconditionally sent to stderr. This makes it impossible for log-aggregation systems to filter by severity. Bump klog to v2.140.0 and opt into the fixed behavior by setting legacy_stderr_threshold_behavior=false and stderrthreshold=INFO (which preserves current output while letting users override via CLI flags). Ref: kubernetes/klog#212, kubernetes/klog#432 Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
d556efb to
0fa1910
Compare
|
Hi — friendly ping. Is this PR still on the radar for a second review? Happy to rebase or make changes if needed. Thanks! |
Yes, approved. |
Add missing changelog entry for PR 9654 (fixes Changelog Check). Add explanation to //nolint:errcheck directives (fixes nolintlint). Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
What this PR does
Fixes the
-stderrthresholdflag so it is honored even when-logtostderr=true(the klog v2 default).Problem
klog v2 defaults
-logtostderrtotrue. When this flag is active, the-stderrthresholdflag is silently ignored — all log messages (INFO, WARNING, ERROR, FATAL) are unconditionally written to stderr. There is no way for users to filter which severity levels reach stderr.This has been an open issue since 2020: kubernetes/klog#212.
Fix
PR kubernetes/klog#432 introduced the fix in klog v2.140.0 via a new flag
legacy_stderr_threshold_behavior. This PR:legacy_stderr_threshold_behavior=falseandstderrthreshold=INFOafterklog.InitFlags()Setting
stderrthreshold=INFOpreserves the current default behavior (all logs go to stderr). Users can now override it on the command line (e.g.,-stderrthreshold=WARNING) and it will actually work.Changes
pkg/cmd/velero/velero.go: Addflag.CommandLine.Set()calls afterklog.InitFlags(flag.CommandLine)go.mod/go.sum: Bumpk8s.io/klog/v2v2.130.1 → v2.140.0Ref: kubernetes/klog#212, kubernetes/klog#432