Migrate to klog/v2 v2.140.0 and honor stderrthreshold when logtostderr is enabled#3801
Conversation
Migrate all direct klog v1 imports to klog/v2 and bump to v2.140.0 which includes the fix for kubernetes/klog#212. Opt into the new klog behavior by setting -legacy_stderr_threshold_behavior=false so that -stderrthreshold is honored even when -logtostderr=true (the default). Set stderrthreshold=INFO to preserve backward-compatible behavior while allowing users to override it to WARNING or ERROR to reduce stderr noise. Also wire klog flags into pflag.CommandLine in cmd/olm so that klog flags (like -v, -stderrthreshold) are actually accessible from the command line. Fix klog v1→v2 API incompatibility: klog.V() returns Verbose struct in v2, not bool — use .Enabled() for conditional checks. Fixes operator-framework#2131 Ref: kubernetes/klog#212, kubernetes/klog#432 Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @pierluigilenoci. Thanks for your PR. I'm waiting for a operator-framework member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
cc @joelanford @kevinrizza @perdasilva — would you be able to review this when you get a chance? This PR migrates from klog v1 to v2 and opts into the klog fix for kubernetes/klog#212 so that |
Summary
k8s.io/klog(v1) imports tok8s.io/klog/v2and bump to v2.140.0 which includes the fix for stderrthreshold not honored when logtostderr is set kubernetes/klog#212.-legacy_stderr_threshold_behavior=falseso that-stderrthresholdis honored even when-logtostderr=true(the klog default).stderrthreshold=INFOto preserve backward-compatible behavior (all logs still appear on stderr by default). Users can now override-stderrthresholdtoWARNINGorERRORto reduce stderr noise.pflag.CommandLineincmd/olm/main.goso that klog flags (like-v,-stderrthreshold) are actually accessible from the command line (they were previously registered but never parsed).klog.V()returnsVerbosestruct in v2 (notbool) — use.Enabled()for conditional checks.This addresses #2131 where all OLM logs are classified as ERROR by log aggregation systems (DataDog, CloudWatch, GCP Cloud Logging) because everything is unconditionally written to stderr regardless of severity.
Background
When
-logtostderr=true(klog's default), the-stderrthresholdflag was completely ignored — all log levels were written to stderr. Log aggregation systems that infer severity from the output stream (stdout=INFO, stderr=ERROR) would misclassify every OLM log message as an error.klog v2.140.0 (kubernetes/klog#432) introduced a fix behind the
-legacy_stderr_threshold_behaviorflag. Setting it tofalseenables proper severity-based filtering on the stderr path.The
stderrthreshold=INFOdefault preserves existing behavior (all logs on stderr), while giving operators the ability to set-stderrthreshold=WARNINGor-stderrthreshold=ERRORto only send higher-severity messages to stderr.Test plan
-stderrthreshold=WARNING— only WARNING and above appear on stderrFixes #2131
Ref: kubernetes/klog#212, kubernetes/klog#432