feat: [WIP] configure klog to write to stderr to prevent JSON corruption#60
feat: [WIP] configure klog to write to stderr to prevent JSON corruption#60ropatil010 wants to merge 1 commit into
Conversation
Problem: The 'list tests' command outputs JSON to stdout for consumption by CI systems. However, klog (used by imported k8s packages) defaults to stdout, causing deprecation warnings and other log messages to corrupt the JSON stream. This was discovered in openshift/cluster-authentication-operator#857 where klog warnings like "W0327 12:34:56.123456 12345 warnings.go:70] deprecation warning" appeared in stdout, breaking JSON parsers with errors like: "invalid character 'W' looking for beginning of value" Solution: Configure klog to write to stderr in pkg/cmd/cmd.go init() function, executed before any commands run. This keeps stdout clean for structured output while directing all logs/diagnostics to stderr. This approach is consistent with how pkg/ginkgo/util.go already configures GinkgoWriter to use stderr, following the Unix convention: - stdout = structured data (JSON) - stderr = logs and diagnostics Impact: CI systems can now reliably parse test lists without klog corruption. Reference: openshift/cluster-authentication-operator#857 Co-Authored-By: Rohit Patil <[email protected]>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ropatil010 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 @ropatil010. Thanks for your PR. I'm waiting for a openshift-eng 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. |
|
/ok-to-test |
|
@ropatil010: Cannot trigger testing until a trusted user reviews the PR and leaves an DetailsIn response to this:
Instructions 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. |
Remove local pkg/test/init workaround in favor of framework-level fix from openshift-eng/openshift-tests-extension#60. Temporary replace directive points to ropatil010:klog-stderr branch until the PR merges upstream. Co-Authored-By: Rohit Patil <[email protected]>
|
/ok-to-test |
|
Hm, this PR increases the vendored footprint of OTE which we were hoping to keep minimal.
Also, do we know where klog is getting set to stdout? Is that something we could fix upstream? |
|
Hi @stbenjam |
Hm, that comment says |
Remove local pkg/test/init workaround in favor of framework-level fix from openshift-eng/openshift-tests-extension#60. Temporary replace directive points to ropatil010:klog-stderr branch until the PR merges upstream. Co-Authored-By: Rohit Patil <[email protected]>
@ropatil010 @stbenjam it looks like that Overall the fix introduced in openshift/cluster-authentication-operator#859 is quite fragile as it depends on import order, however if we really need to combine the output when Any insights on this? Overall I'd also rather solve the root issue rather than fixing it at each repo that might have similar issues, but I'm not sure if this is realistic. |
|
The code you linked from origin shows we combine stdout and stderr, I think that is probably not the right thing for us to do but the existing JSON boundary detection should prevent scooping up logs. If you go back to the original PR that was reverted, it was only failing in metal jobs, so that's your clue it something specific to those. Metal IPv6 jobs are disconnected and query extensions for image mirroring information, and that seems to be where the problem is. I think openshift/origin#31009 fixes the problem |
Problem:
The 'list tests' command outputs JSON to stdout for consumption by CI systems. However, klog (used by imported k8s packages) defaults to stdout, causing deprecation warnings and other log messages to corrupt the JSON stream.
This was discovered in openshift/cluster-authentication-operator#857 where klog warnings like "W0327 12:34:56.123456 12345 warnings.go:70] deprecation warning" appeared in stdout, breaking JSON parsers with errors like: "invalid character 'W' looking for beginning of value"
Solution:
Configure klog to write to stderr in pkg/cmd/cmd.go init() function, executed before any commands run. This keeps stdout clean for structured output while directing all logs/diagnostics to stderr.
This approach is consistent with how pkg/ginkgo/util.go already configures GinkgoWriter to use stderr, following the Unix convention:
Impact:
CI systems can now reliably parse test lists without klog corruption.
Reference: openshift/cluster-authentication-operator#857