-
Notifications
You must be signed in to change notification settings - Fork 300
Migrate verbosity-based info logging to contextual logging #9707
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
base: master
Are you sure you want to change the base?
Migrate verbosity-based info logging to contextual logging #9707
Conversation
|
Hi @anndono. Thanks for your PR. I'm waiting for a github.com 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. 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. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: anndono 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 |
|
/ok-to-test |
|
Please fix the linting issue. You may use the corresponding makefile target to check linting locally. Both for main module and pkg/azclient module (there are two makefiles separatedly). |
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.
Pull request overview
This PR migrates logging from the traditional klog.V(n).Infof/Info/InfoS pattern to contextual logging using logger.V(n).Info with structured key-value pairs. The changes also convert some Info logs to Error logs where error details are present, improving logging consistency across the codebase.
Key changes:
- Replaced
klogverbosity-based logging with contextuallogger.V(n).Infothroughout the codebase - Introduced
log.Background().WithName()pattern for logger initialization in functions - Converted formatted string messages to structured key-value logging
- Updated certain Info logs to Error logs where errors are being logged
Reviewed changes
Copilot reviewed 49 out of 52 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/util/node/node.go | Migrated PatchNodeCIDRs logging to contextual logging |
| pkg/util/controller/node/controller_utils.go | Updated RecordNodeStatusChange logging |
| pkg/provider/subnet/subnet.go | Converted SubnetsClient logging to structured format |
| pkg/provider/storage/*.go | Migrated storage-related logging across multiple files |
| pkg/provider/securitygroup/*.go | Updated security group operation logging |
| pkg/provider/azure_zones.go | Converted zone-related logging to contextual format |
| pkg/provider/azure_vmssflex*.go | Migrated VMSS Flex logging throughout |
| pkg/provider/azure_vmss*.go | Updated VMSS operation logging |
| pkg/provider/azure_standard.go | Converted availability set logging |
| pkg/provider/azure_loadbalancer*.go | Extensive migration of load balancer logging |
| pkg/provider/azure_routes.go | Updated route management logging |
| pkg/provider/azure*.go | Various provider operation logging updates |
| pkg/nodemanager/nodemanager.go | Migrated node manager logging |
| pkg/nodeipam/ipam/*.go | Updated IPAM allocator logging |
| pkg/metrics/azure_metrics.go | Converted metrics logging |
| pkg/credentialprovider/*.go | Updated credential provider logging |
| pkg/azclient/policy/retryaftermin/*.go | Migrated retry policy logging |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e60fb0a to
d51eec5
Compare
|
/retest |
1 similar comment
|
/retest |
d51eec5 to
61bc582
Compare
|
/retest |
61bc582 to
3d73d06
Compare
|
/retest |
|
@anndono azclient still failed to build |
3d73d06 to
6c70306
Compare
|
/retest |
|
/retest |
1 similar comment
|
/retest |
pkg/azclient/go.mod
Outdated
| k8s.io/klog/v2 v2.130.1 | ||
| k8s.io/utils v0.0.0-20241210054802-24370beab758 | ||
| k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d | ||
| sigs.k8s.io/cloud-provider-azure v1.34.3 |
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.
better to have a dedicated logger package in azclient (though there would be duplications) than circular import a huge package here.
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.
Reverted the import and updated the code to use the existing package instead.
6c70306 to
34229bf
Compare
|
related: #1575 |
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.
Pull request overview
Copilot reviewed 48 out of 48 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _ = az.storageAccountCache.Delete(account) // clean cache | ||
| updateParams := &armstorage.AccountUpdateParameters{Tags: newTags} | ||
| klog.V(2).Infof("add storage account(%s) with tags(%+v)", account, newTags) | ||
| logger.V(2).Info("", "account", account, "tags", newTags) |
Copilot
AI
Dec 15, 2025
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 log message is empty. Based on the context (adding storage account with tags), this should have a meaningful message like "add storage account with tags".
| _ = az.storageAccountCache.Delete(account) // clean cache | ||
| updateParams := &armstorage.AccountUpdateParameters{Tags: result.Tags} | ||
| klog.V(2).Infof("remove tag(%s) from storage account(%s)", key, account) | ||
| logger.V(2).Info("", "tag", key, "account", account) |
Copilot
AI
Dec 15, 2025
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 log message is empty. Based on the context (removing tag from storage account), this should have a meaningful message like "remove tag from storage account".
| vmss = v | ||
| } | ||
| klog.V(2).Infof("ensureBackendPoolDeletedFromVmssUniform: vmss %q, backendPoolIDs %q", ptr.Deref(vmss.Name, ""), backendPoolIDs) | ||
| logger.V(2).Info("", "vmssName", ptr.Deref(vmss.Name, ""), "backendPoolIDs", backendPoolIDs) |
Copilot
AI
Dec 15, 2025
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 log message is empty. Based on the context, this should have a meaningful message describing what is being logged about the vmss name and backendPoolIDs.
| logger.V(2).Info("", | ||
| "service", serviceName, | ||
| "LB fipConfigID", ptr.Deref(fipConfig.Name, ""), | ||
| "wantPLS", wantPLS, | ||
| "createPLS", createPLS) |
Copilot
AI
Dec 15, 2025
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 log message is empty. Based on the context, this should have a meaningful message like "reconcilePrivateLinkService for service".
| exists := !strings.EqualFold(ptr.Deref(existingPLS.ID, ""), consts.PrivateLinkServiceNotExistID) | ||
| if exists { | ||
| klog.V(4).Infof("reconcilePrivateLinkService for service(%s): found existing private link service attached(%s)", serviceName, ptr.Deref(existingPLS.Name, "")) | ||
| logger.V(4).Info("found existing private link service attached(%s)", "service", serviceName, "privateLinkService", ptr.Deref(existingPLS.Name, "")) |
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.
Please don't use %s anymore after the migration. Please double check if there are other places having this issue.
|
|
||
| // RunWrapper adapts the ccm boot logic to the leader elector call back function | ||
| func RunWrapper(s *options.CloudControllerManagerOptions, c *cloudcontrollerconfig.Config, h *controllerhealthz.MutableHealthzHandler) func(ctx context.Context) { | ||
| logger := log.Background().WithName("RunWrapper") |
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.
Shouldn't use Background context if there is an existing context. Maybe we can have another PR addressing this issue?
| // service is not on this load balancer | ||
| continue | ||
| } | ||
| logger.V(4).Info(fmt.Sprintf("getServiceLoadBalancer(%s, %s, %v): current lb IPs: %q", service.Name, clusterName, wantLb, lbIPsPrimaryPIPs)) |
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.
shouldn't use sprintf. should be key-value pairs. Check other places please.
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This PR improves logging consistency by migrating parts of the codebase from mixed plain-text and structural logging to contextual logging.
Changes:
klog.V(n).Infof/klog.V(n).Info/klog.V(n).InfoSwithlogger.V(n).Infofor contextual loggingInfologs toErrorlogs where error details are presentWhich issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: