New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate apimachinery to contextual logging #115317
Conversation
Hi @yanjing1104. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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/test-infra repository. |
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
/wg structured-logging |
/assign @pohly |
@@ -600,15 +600,15 @@ func (a genericAccessor) GetOwnerReferences() []metav1.OwnerReference { | |||
var ret []metav1.OwnerReference | |||
s := a.ownerReferences | |||
if s.Kind() != reflect.Pointer || s.Elem().Kind() != reflect.Slice { | |||
klog.Errorf("expect %v to be a pointer to slice", s) | |||
klog.ErrorS(nil, "expect the ownerReference to be a pointer to slice", "ownerReference", s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one thing we need to decide here and in many other pieces of this PR: can this call here use contextual logging?
Probably not, because changing GetOwnerReference()
to GetOwnerReference(logger klog.Logger)
just because it might need to log in an error path is overkill.
But we also don't want to be left with a klog.ErrorS
call that then will show up when we search for non-contextual calls that might have to be updated.
So here we can use:
klog.ErrorS(nil, "expect the ownerReference to be a pointer to slice", "ownerReference", s) | |
klog.Background().Error(nil, "expect the ownerReference to be a pointer to slice", "ownerReference", s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -169,7 +169,7 @@ func (c *connection) newSpdyStream(stream *spdystream.Stream) { | |||
err := c.newStreamHandler(stream, replySent) | |||
rejectStream := (err != nil) | |||
if rejectStream { | |||
klog.Warningf("Stream rejected: %v", err) | |||
klog.InfoS("Stream rejected", "err", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it might make more sense to change the API. This will have implications for code, wo most likely we'll need an alternative API that accepts a logger will keeping the old one around, perhaps with a deprecation notice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is outdated, changed it to contextual logging.
- klog.Warningf("Stream rejected: %v", err)
+ klog.Background().Info("Stream rejected", "err", err)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
klog.Background().Info
is not contextual logging because it is always using the global logger, regardless of how it got called.
You need to think about ways how a caller can inject its own logger into this function, i.e. change or extend the API.
/remove-sig api-machinery |
323ba3e
to
067ccf5
Compare
067ccf5
to
a19031b
Compare
/triage accepted |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
a19031b
to
15953f6
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yanjing1104 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Jing Yan <jing1.yan@intel.com>
@pohly |
/assign @deads2k |
/unassign @deads2k |
PR needs rebase. 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/test-infra repository. |
Close the PR as I wont be able to follow it, thanks~ |
Signed-off-by: Jing Yan jing1.yan@intel.com
What type of PR is this?
/kind feature
What this PR does / why we need it:
Migrated
apimachinery
to use contextual logging.Which issue(s) this PR fixes:
Fixes # Part of kubernetes/enhancements#3077
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: