-
Notifications
You must be signed in to change notification settings - Fork 40k
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
cluster-bootstrap: Support structured and contextual logging #127658
base: master
Are you sure you want to change the base?
cluster-bootstrap: Support structured and contextual logging #127658
Conversation
Hi @soma00333. 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-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: soma00333 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 |
/triage accepted |
/ok-to-test |
The error is caused by a race condition in the Test_Run_Positive_VolumeMountControllerAttachEnabledRace test. It highlights two key issues:
Try running the test again. |
/retest-required |
/assign @stlaz |
@@ -45,8 +45,8 @@ func GetData(secret *v1.Secret, key string) string { | |||
} | |||
|
|||
// HasExpired will identify whether the secret expires | |||
func HasExpired(secret *v1.Secret, currentTime time.Time) bool { | |||
_, expired := GetExpiration(secret, currentTime) | |||
func HasExpired(logger klog.Logger, secret *v1.Secret, currentTime time.Time) bool { |
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.
I believe we should use a module-level logger here instead of wiring it this way.
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.
Hmmmm, I see that that's not a pattern that kubernetes follows. That's a shame. You can ignore the above comment.
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.
I appreciate your comment.
We can pass ctx instead of logger.
e.g.
func HasExpired(ctx context.Context, secret *v1.Secret, currentTime time.Time) bool {}
Do you prefer this?
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.
I think it's ok to just use what you've got. I originally came from python where you'd set up a logger per-module so that you don't have to pass it in arguments. It's possible that that pattern would be harder to implement in golang given it's a compiled language.
klog.V(3).Infof("Unparseable expiration time (%s) in %s/%s Secret: %v. Treating as expired.", | ||
expiration, secret.Namespace, secret.Name, err) | ||
logger.V(3).Info("Unparseable expiration time in Secret. Treating as expired.", | ||
"expiration", expiration, "namespace", secret.Namespace, "secretName", secret.Name, "error", 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.
"expiration", expiration, "namespace", secret.Namespace, "secretName", secret.Name, "error", err) | |
"expirationTime", expiration, "secretNamespace", secret.Namespace, "secretName", secret.Name, "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.
I fixed here
klog.V(3).Infof("Expired bootstrap token in %s/%s Secret: %v", | ||
secret.Namespace, secret.Name, expiration) | ||
logger.V(3).Info("Expired bootstrap token in Secret.", | ||
"namespace", secret.Namespace, "secretName", secret.Name, "expiration", expiration) |
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.
"namespace", secret.Namespace, "secretName", secret.Name, "expiration", expiration) | |
"secretNamespace", secret.Namespace, "secretName", secret.Name, "expiration", expiration) |
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.
I fixed here
5ef215f
to
1a03f12
Compare
/lgtm |
LGTM label has been added. Git tree hash: dc5daf247d5f46c0bd6f03abfdb43751ba0263e1
|
What type of PR is this?
/kind feature
What this PR does / why we need it:
I implemented the support for structured and contextual logging in cluster-bootstrap, following the guideline:
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md
In addition, I've modified the log messages based on the following guideline:
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#remove-string-formatting-from-log-message
I've confirmed that they pass the logcheck tests.
You can run logcheck with
make test
ormake logcheck
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
I've confirm that they pass the logcheck tests.
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: