Skip to content

fix: honor klog -stderrthreshold even when -logtostderr is true#168

Open
pierluigilenoci wants to merge 5 commits into
oam-dev:masterfrom
pierluigilenoci:fix/honor-stderrthreshold
Open

fix: honor klog -stderrthreshold even when -logtostderr is true#168
pierluigilenoci wants to merge 5 commits into
oam-dev:masterfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci

@pierluigilenoci pierluigilenoci commented Apr 23, 2026

Copy link
Copy Markdown

What changed

klog v2 defaults -logtostderr to true, which silently ignores -stderrthreshold — all log levels go to stderr unconditionally. This has been an open issue since 2020.

klog v2.140.0 introduced a fix behind an opt-in flag (legacy_stderr_threshold_behavior). This PR bumps klog to v2.140.0 and enables the fix in both entry points (cmd/addon-manager/main.go and pkg/config/args_log.go) so that -stderrthreshold is honored, while preserving the current default behavior.

References


Summary by cubic

Honor -stderrthreshold when -logtostderr=true by enabling klog’s new behavior. Default stderr level stays at INFO unless overridden.

  • Bug Fixes

    • Set legacy_stderr_threshold_behavior=false and default stderrthreshold=INFO in cmd/addon-manager/main.go and pkg/config/args_log.go; add unit test for AddLogFlags and harden it with require.NotNil to avoid nil deref.
  • Dependencies

    • Bump k8s.io/klog/v2 to v2.140.0.

Written for commit 1e01bde. Summary will update on new commits.

Review in cubic

klog v2 defaults -logtostderr to true, which silently ignores
-stderrthreshold — all log levels go to stderr unconditionally.
This has been an open issue since 2020 (kubernetes/klog#212).

klog v2.140.0 introduced a fix behind an opt-in flag
(legacy_stderr_threshold_behavior). This commit bumps klog to
v2.140.0 and enables the fix in both entry points so that
-stderrthreshold is honored, while preserving the current default
behavior (stderrthreshold=INFO means all logs still go to stderr
unless the user overrides it on the command line).

Ref: kubernetes/klog#212
Ref: kubernetes/klog#432
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 4 files

@codecov

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 9.89%. Comparing base (2b04dd4) to head (1e01bde).

Additional details and impacted files
@@            Coverage Diff            @@
##           master    #168      +/-   ##
=========================================
- Coverage   10.51%   9.89%   -0.63%     
=========================================
  Files          49      49              
  Lines        7029    6501     -528     
=========================================
- Hits          739     643      -96     
+ Misses       6238    5806     -432     
  Partials       52      52              
Flag Coverage Δ
unit-test 9.89% <100.00%> (-0.63%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Cover the new klog flag overrides (legacy_stderr_threshold_behavior
and stderrthreshold) introduced in the previous commit to satisfy
the codecov patch coverage threshold (70%).

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@pierluigilenoci

Copy link
Copy Markdown
Author

Added a unit test for AddLogFlags in pkg/config/args_log_test.go to cover the new klog flag overrides (legacy_stderr_threshold_behavior and stderrthreshold). This should satisfy the codecov patch coverage threshold.

Regarding the e2e-ocm-addon-cluster-gateway failure — this is a pre-existing infrastructure issue (the addon service returns HTTP 503 / ServiceUnavailable). The same test has been consistently failing on other branches as well (e.g. user/amisingh-ocm-debug runs from July 2025). This failure is unrelated to the changes in this PR.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread pkg/config/args_log_test.go Outdated
@pierluigilenoci

Copy link
Copy Markdown
Author

@yue9944882 @Somefive — friendly ping, could one of you review this when you get a chance? The e2e-ocm-addon-cluster-gateway failure is a pre-existing infrastructure flake (same failure on unrelated branches). All other CI checks pass. Thanks!

Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@pierluigilenoci

Copy link
Copy Markdown
Author

Hi — friendly follow-up. CI is green, merge state is clean, and all checks are passing. Would you be able to review when you get a chance? Thank you!

Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@pierluigilenoci

Copy link
Copy Markdown
Author

Hi @yue9944882 @Somefive — friendly ping on this PR. All CI checks are green and the branch is up-to-date. Would you be willing to take a look when you have a chance? Happy to address any feedback. 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.

1 participant