-
Notifications
You must be signed in to change notification settings - Fork 172
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
Support structured and contextual logging #154
Support structured and contextual logging #154
Conversation
7abe4a2
to
50eae47
Compare
} | ||
// add a uniquifier so that two processes on the same host don't accidentally both become active | ||
id = id + "_" + string(uuid.NewUUID()) | ||
component := provisionerName + "_" + id | ||
|
||
v1.AddToScheme(scheme.Scheme) | ||
broadcaster := record.NewBroadcaster() | ||
broadcaster.StartLogging(klog.Infof) | ||
broadcaster.StartStructuredLogging(0) |
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's a problem: we need a new API such that broadcaster
accepts a logger instead of using the global one.
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.
Let's not block the PR because of that, but a TODO would be good.
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.
You can link to kubernetes/kubernetes#120729.
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.
@pohly, I have a couple of questions regarding this:
-
Since no release tag has been created following the merge of the PR that added NewEventBroadcasterAdapterWithContext, is the adaptation to contextual logging for the event broadcaster unnecessary in this PR?
-
The interface of ResourceLockConfig.EventRecorder seems different from the new EventRecorder's interface. Would it be okay to change the interface of ResourceLockConfig.EventRecorder in a separate PR?
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.
Since no release tag has been created following the merge of the kubernetes/kubernetes#122142, is the adaptation to contextual logging for the event broadcaster unnecessary in this PR?
Perhaps wait until this repo is updated to Kubernetes 1.30, then use the WithContext call?
The interface of ResourceLockConfig.EventRecorder seems different from the new EventRecorder's interface. Would it be okay to change the interface of ResourceLockConfig.EventRecorder in a separate PR?
I would update it together with updating Kubernetes 1.30 and adapting the code.
controller/controller.go
Outdated
@@ -857,13 +862,14 @@ func (ctrl *ProvisionController) Run(ctx context.Context) { | |||
go wait.Until(func() { ctrl.runVolumeWorker(ctx) }, time.Second, ctx.Done()) | |||
} | |||
|
|||
klog.Infof("Started provisioner controller %s!", ctrl.component) | |||
logger.Info("Started provisioner controller!", "component", ctrl.component) |
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 convention is to not end the message string with punctuation because the key/value pairs follow.
controller/controller.go
Outdated
klog.Errorf("Giving up syncing claim %q because failures %v >= threshold %v", key, ctrl.claimQueue.NumRequeues(obj), ctrl.failedProvisionThreshold) | ||
klog.V(2).Infof("Removing PVC %s from claims in progress", key) | ||
logger.Error(nil, "Giving up syncing claim because failures >= threshold", "claim", key, "failures", ctrl.claimQueue.NumRequeues(obj), "threshold", ctrl.failedProvisionThreshold) | ||
logger.V(2).Info("Removing PVC from claims in progress", "pvc", key) |
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.
"pvc" is usually spelled "PVC" and refers to an object, not a string.
Let's use "key" as key here whenever a work queue refers to the work queue key.
Can you do a full pass over the PR and try to make the key names consistent?
controller/controller.go
Outdated
ctrl.volumeQueue.AddRateLimited(obj) | ||
} else { | ||
klog.Errorf("Giving up syncing volume %q because failures %v >= threshold %v", key, ctrl.volumeQueue.NumRequeues(obj), ctrl.failedDeleteThreshold) | ||
logger.Info("Giving up syncing volume because failures >= threshold", "volume", key, "failure", ctrl.volumeQueue.NumRequeues(obj), "threshold", ctrl.failedDeleteThreshold) |
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.
"failure" -> "failures" (consistency!)
@pohly Thank you for your review. I've addressed the issues you pointed out. |
I've added checks for Contextual Logging using both golangci-lint and logcheck. I wasn't sure about the best way to add logcheck, so I've set it up in the Makefile based on the script below. If there's a more appropriate method, I'd appreciate your guidance. Also, if testing with logcheck is not necessary, please let me know. |
10f85a9
to
fb3c86a
Compare
Makefile
Outdated
install-tools: $(GOBIN) | ||
cd hack/tools \ | ||
&& GOBIN=$(GOBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint \ | ||
&& go build -o "${GOBIN}/logcheck.so" -buildmode=plugin sigs.k8s.io/logtools/logcheck/plugin |
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.
You don't need golangci-lint to run logcheck.
Instead you can do:
go install sigs.k8s.io/logtools/[email protected]
logcheck -check-contextual ./...
This can go into verify
below.
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.
@bells17 can you please update the makefile with the suggestion?
fb3c86a
to
f07d971
Compare
4afa277
to
521d380
Compare
// TODO: Once the following PR is merged, change to use StartLogging and StartRecordingToSinkWithContext | ||
// https://github.com/kubernetes/kubernetes/pull/120729 |
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 PR is merged now.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bells17, jsafrane The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
New go cannot install |
@jsafrane Regarding your comment about the new Go version not being able to install gometalinter, are you considering switching to use golangci-lint as an alternative? If this understanding is correct, may I undertake the task of integrating golangci-lint? If I am allowed to proceed, I would appreciate your advice on whether I should update the repo-infra repository itself and reflect those changes in the sig-storage-lib-external-provisioner repository, or should I just introduce golangci-lint independently in the sig-storage-lib-external-provisioner repository? |
@bells17 can you please rebase? I am sorry, I updated k8s to 1.30 and removed gometalinter in a single PR, now I see they should be separate. |
521d380
to
52e8ed4
Compare
@@ -0,0 +1,37 @@ | |||
#!/usr/bin/env bash |
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.
@jsafrane Thank you. I've rebased. Additionally, after rebasing, the logcheck started to fail, so I am making the necessary corrections. |
Thanks! |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Migrate to use structured logging and contextual logging.
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?