Skip to content

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

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

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

Conversation

@pierluigilenoci
Copy link
Copy Markdown

@pierluigilenoci pierluigilenoci commented Apr 23, 2026

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.
  • Dependencies

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

Written for commit a378e5d. Summary will update on new commits.

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 <[email protected]>
Copy link
Copy Markdown

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

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
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

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

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 Sentry.
📢 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 <[email protected]>
Signed-off-by: Pierluigi Lenoci <[email protected]>
@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.

Copy link
Copy Markdown

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

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).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pkg/config/args_log_test.go">

<violation number="1" location="pkg/config/args_log_test.go:36">
P2: Non-fatal `assert.NotNil` is followed by unconditional dereference, which can panic and obscure the real assertion failure.</violation>
</file>

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


// legacy_stderr_threshold_behavior should be opted out
legacy := set.Lookup("legacy_stderr_threshold_behavior")
assert.NotNil(t, legacy, "expected legacy_stderr_threshold_behavior flag")
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 27, 2026

Choose a reason for hiding this comment

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

P2: Non-fatal assert.NotNil is followed by unconditional dereference, which can panic and obscure the real assertion failure.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/config/args_log_test.go, line 36:

<comment>Non-fatal `assert.NotNil` is followed by unconditional dereference, which can panic and obscure the real assertion failure.</comment>

<file context>
@@ -0,0 +1,44 @@
+
+	// legacy_stderr_threshold_behavior should be opted out
+	legacy := set.Lookup("legacy_stderr_threshold_behavior")
+	assert.NotNil(t, legacy, "expected legacy_stderr_threshold_behavior flag")
+	assert.Equal(t, "false", legacy.Value.String())
+
</file context>
Fix with Cubic

@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 <[email protected]>
Signed-off-by: Pierluigi Lenoci <[email protected]>
@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!

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