Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

soma00333
Copy link

@soma00333 soma00333 commented Sep 26, 2024

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 or make logcheck

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

I've confirm that they pass the logcheck tests.

$GOPATH/bin/logcheck -check-contextual ./staging/src/k8s.io/cluster-bootstrap/...
$GOPATH/bin/logcheck -check-structured ./staging/src/k8s.io/cluster-bootstrap/...

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 26, 2024
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 26, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: soma00333
Once this PR has been reviewed and has the lgtm label, please assign deads2k, neolit123 for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 26, 2024
@soma00333 soma00333 marked this pull request as ready for review September 26, 2024 11:00
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 26, 2024
@bells17
Copy link
Contributor

bells17 commented Sep 27, 2024

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 27, 2024
@bells17
Copy link
Contributor

bells17 commented Sep 27, 2024

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 27, 2024
@soma00333
Copy link
Author

soma00333 commented Sep 28, 2024

The error is caused by a race condition in the Test_Run_Positive_VolumeMountControllerAttachEnabledRace test. It highlights two key issues:

  1. Volume Reconstruction Failure: The test cannot find the expected directory (fake-dir), resulting in a failure to reconstruct volumes from disk. This is shown by the error message: Cannot get volumes from disk, skip sync states for volume reconstruction.
  2. Panic Due to Closed Channel: The test encounters a panic caused by attempting to close an already closed channel, as seen in the repeated message: recovered from panic close of closed channel.

Try running the test again.

@soma00333
Copy link
Author

/retest-required

@nilekhc
Copy link
Contributor

nilekhc commented Oct 7, 2024

/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 {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Author

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?

Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"expiration", expiration, "namespace", secret.Namespace, "secretName", secret.Name, "error", err)
"expirationTime", expiration, "secretNamespace", secret.Namespace, "secretName", secret.Name, "err", err)

Copy link
Author

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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"namespace", secret.Namespace, "secretName", secret.Name, "expiration", expiration)
"secretNamespace", secret.Namespace, "secretName", secret.Name, "expiration", expiration)

Copy link
Author

Choose a reason for hiding this comment

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

I fixed here

@soma00333 soma00333 force-pushed the feature/cluster-bootstrap-structured-and-contextual-logging branch from 5ef215f to 1a03f12 Compare November 11, 2024 14:20
@stlaz
Copy link
Member

stlaz commented Nov 11, 2024

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 11, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: dc5daf247d5f46c0bd6f03abfdb43751ba0263e1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: In Progress
Status: Changes Requested
Development

Successfully merging this pull request may close these issues.

5 participants