Skip to content

Honor stderrthreshold when logtostderr is enabled#3859

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

Honor stderrthreshold when logtostderr is enabled#3859
pierluigilenoci wants to merge 1 commit into
google:masterfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown

@pierluigilenoci pierluigilenoci commented Mar 26, 2026

What this PR does

Fixes the -stderrthreshold flag so it is honored even when -logtostderr=true (the klog v2 default).

Problem

klog v2 defaults -logtostderr to true. When this flag is active, the -stderrthreshold flag 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:

  1. Bumps klog from v2.130.1 to v2.140.0
  2. Opts into the fixed behavior by setting legacy_stderr_threshold_behavior=false and stderrthreshold=INFO after every klog.InitFlags() call

Setting stderrthreshold=INFO preserves 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

  • cmd/cadvisor.go: Main binary entry point
  • client/clientexample/main.go: Client example
  • utils/oomparser/oomexample/main.go: OOM parser example
  • integration/runner/runner.go: Integration test runner
  • integration/tests/api/test_utils.go: API test utilities
  • integration/tests/crio/test_utils.go: CRI-O test utilities
  • integration/tests/healthz/test_utils.go: Healthz test utilities
  • go.mod / go.sum: Bump k8s.io/klog/v2 v2.130.1 → v2.140.0

Ref: kubernetes/klog#212, kubernetes/klog#432

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Mar 26, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @vmarmol, @dashpole, @rjnagal -- would you be willing to review? Thank you!

@pierluigilenoci
Copy link
Copy Markdown
Author

@googlebot I signed it.

1 similar comment
@pierluigilenoci
Copy link
Copy Markdown
Author

@googlebot I signed it.

@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @vmarmol @dashpole @rjnagal — friendly follow-up. The CLA check is passing. This is a small change to opt into the fixed klog stderrthreshold behavior.

Would you be able to review when you get a chance? Thank you!

@dashpole
Copy link
Copy Markdown
Collaborator

I don't work on cAdvisor anymore.

@pierluigilenoci
Copy link
Copy Markdown
Author

Thank you for letting me know, @dashpole! Could @vmarmol or @rjnagal point me to the right person to review this? I see @thaJeztah and @olyazavr have been active recently — would either of you be able to take a look? It's a small klog stderrthreshold fix. Thank you!

@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @dims — friendly ping on this PR. It fixes the klog stderrthreshold behavior when logtostderr is enabled. Happy to address any feedback. Thanks!

@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @dims — gentle reminder on this PR. It fixes the klog stderrthreshold behavior when logtostderr is enabled (same fix as adopted in other k8s ecosystem projects). Happy to address any feedback. Thanks!

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 across
all binaries and test utilities. This 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>
@pierluigilenoci pierluigilenoci force-pushed the fix/honor-stderrthreshold branch from 16cb7f4 to 7641307 Compare May 7, 2026 11:21
@pierluigilenoci
Copy link
Copy Markdown
Author

Hi — friendly follow-up. CI is green and all checks pass. Would you be able to review when you get a chance? Thank you!

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.

2 participants