Skip to content

Honor stderrthreshold when logtostderr is enabled#36730

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

Honor stderrthreshold when logtostderr is enabled#36730
pierluigilenoci wants to merge 1 commit intokubernetes: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) in the triage/summarize tool.

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.

This has been an open issue since 2020: kubernetes/klog#212.

Fix

PR kubernetes/klog#432 introduced the fix in klog v2.140.0. This PR:

  1. Bumps klog from v2.10.0 to v2.140.0 in triage/go.mod
  2. Opts into the fixed behavior by setting legacy_stderr_threshold_behavior=false and stderrthreshold=INFO on the klogFlags FlagSet in setUpLogging()

Setting stderrthreshold=INFO preserves the current default behavior. Users can now override it on the command line and it will actually work.

Changes

  • triage/summarize/summarize.go: Add klogFlags.Set() calls after klog.InitFlags(klogFlags)
  • triage/go.mod / triage/go.sum: Bump k8s.io/klog/v2 v2.10.0 → v2.140.0

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

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 26, 2026
@k8s-ci-robot k8s-ci-robot requested review from aojea and upodroid March 26, 2026 23:16
@k8s-ci-robot k8s-ci-robot added area/triage sig/testing Categorizes an issue or PR as relevant to SIG Testing. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 26, 2026
@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @BenTheElder, @krzyzacy, @fejta — would you be willing to review? Thank you!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 27, 2026
@BenTheElder
Copy link
Copy Markdown
Member

Hey, @krzyzacy is emeritus these days, the CI will auto-assign current reviewers and auto-suggest a current approver for assigning after review.

Comment thread triage/summarize/summarize.go Outdated
klog.InitFlags(klogFlags) // Add the klog flags
// Opt into fixed stderrthreshold behavior (kubernetes/klog#212).
_ = klogFlags.Set("legacy_stderr_threshold_behavior", "false")
_ = klogFlags.Set("stderrthreshold", "INFO")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems ok but I don't think we're using any of this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — if triage/summarize isn't actively used, this has no practical impact. I already applied your URL nit in the previous push. Happy to close this if the code is effectively dead. What do you think?

Comment thread triage/summarize/summarize.go Outdated
func setUpLogging(logtostderr bool, v int) {
klogFlags := flag.NewFlagSet("klog", flag.PanicOnError)
klog.InitFlags(klogFlags) // Add the klog flags
// Opt into fixed stderrthreshold behavior (kubernetes/klog#212).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit can we use:

Suggested change
// Opt into fixed stderrthreshold behavior (kubernetes/klog#212).
// Opt into fixed stderrthreshold behavior (https://github.com/kubernetes/klog/issues/212).

It's not much longer but you can probably click it in your editor or at least copy-paste to the browser more easily, and it will not generate backreference noise on the issue.

@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @aojea, @upodroid — this PR adds one line to set legacy_stderr_threshold_behavior=false after klog.InitFlags(), per the upstream fix in kubernetes/klog#432. This ensures klog properly respects the stderrthreshold flag.

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

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 27, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @BenTheElder — thanks for the feedback. I applied your URL nit suggestion in the latest push. Regarding your comment about the code not being actively used: would you still like this fix applied for correctness (in case the code is exercised in the future), or would you prefer to close this PR? Happy either way — just let me know. Thank you!

@pierluigilenoci
Copy link
Copy Markdown
Author

Hi @BenTheElder — just a friendly follow-up on the open question.

Looking at the codebase, triage/summarize does appear to be actively used:

  • triage/main.go imports and calls summarize.Main() directly
  • The Dockerfile builds the triage binary and deploys it as a container image (gcr.io/.../triage:latest)
  • triage/summarize/ had commits as recently as Dec 2025 (by @dims), and the broader triage/ directory was updated in Apr 2026

So the setUpLogging code path in summarize.go is exercised whenever the triage tool runs.

The change itself is small — it opts into the fixed stderrthreshold behavior introduced in klog v2.140.0 (kubernetes/klog#432) and sets stderrthreshold=INFO to preserve backward compatibility.

Would you be willing to take another look? Thank you!

klog v2 defaults -logtostderr to true, which silently ignores the
-stderrthreshold flag — all log levels are unconditionally sent to
stderr.

Bump klog to v2.140.0 in triage/go.mod and opt into the fixed behavior
by setting legacy_stderr_threshold_behavior=false and stderrthreshold=INFO.
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 ed86f5b to 381f252 Compare April 22, 2026 10:44
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: krzyzacy, pierluigilenoci
Once this PR has been reviewed and has the lgtm label, please assign bentheelder for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/triage cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants