Skip to content

fix: opt into fixed klog stderrthreshold behavior - #3980

Open
pierluigilenoci wants to merge 1 commit into
google:masterfrom
pierluigilenoci:fix/honor-stderrthreshold-v2
Open

pierluigilenoci wants to merge 1 commit into
google:masterfrom
pierluigilenoci:fix/honor-stderrthreshold-v2

Conversation

@pierluigilenoci

@pierluigilenoci pierluigilenoci commented Dec 3, 2026 •

Copy link
Copy Markdown

Summary

When -logtostderr=true (klog's default since v2.0), the -stderrthreshold flag is silently ignored. This was a known klog bug fixed in klog v2.140.0 via the legacy_stderr_threshold_behavior flag.

This PR opts into the fixed behavior by setting legacy_stderr_threshold_behavior=false early in initialization, before flag.Parse(). Setting stderrthreshold=INFO preserves the existing behavior (all logs still appear on stderr by default).

Users can now control stderr log verbosity by passing -stderrthreshold=WARNING or -stderrthreshold=ERROR to suppress lower-severity log lines on stderr.

Changes

  • cmd/cadvisor.go: add klog behavior opt-in after klog.InitFlags(nil), before flag.Set("v", "2")
  • client/clientexample/main.go: add klog behavior opt-in
  • integration/runner/runner.go: add klog behavior opt-in
  • integration/tests/api/test_utils.go: add "flag" import + klog behavior opt-in
  • integration/tests/crio/test_utils.go: add "flag" import + klog behavior opt-in
  • integration/tests/healthz/test_utils.go: add "flag" import + klog behavior opt-in
  • go.mod/go.sum, cmd/go.mod/cmd/go.sum, lib/go.mod/lib/go.sum: bump klog to v2.140.0

Recreated from the original PR #3859, which was closed by the stale bot.

When -logtostderr=true (klog's default since v2.0), the -stderrthreshold
flag is silently ignored. This was a known klog bug (kubernetes/klog#212)
fixed in klog v2.140.0 via the legacy_stderr_threshold_behavior flag.

This commit opts into the fixed behavior by setting
legacy_stderr_threshold_behavior=false early in initialization, before
flag.Parse(). Setting stderrthreshold=INFO preserves the existing
behavior (all logs still appear on stderr by default).

Users can now control stderr log verbosity by passing
-stderrthreshold=WARNING or -stderrthreshold=ERROR to suppress
lower-severity log lines on stderr.
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.

1 participant