-
Notifications
You must be signed in to change notification settings - Fork 40.9k
chore(kubelet): migrate stats to contextual logging #130259
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?
chore(kubelet): migrate stats to contextual logging #130259
Conversation
Hi @liangyuanpeng. 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: liangyuanpeng 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 |
8aebf04
to
61c94fe
Compare
@@ -53,17 +54,19 @@ func (s networkStats) GetHNSEndpointStats(endpointName string) (*hnslib.HNSEndpo | |||
func (p *criStatsProvider) listContainerNetworkStats() (map[string]*statsapi.NetworkStats, error) { | |||
networkStatsProvider := newNetworkStatsProvider(p) | |||
|
|||
ctx := context.TODO() |
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.
It would be nice to have an explanation comment for every usage of context.TODO()
explaining that this is a temporary solution and when it must be changed to a permanent 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.
Thanks, updated.
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 same here - please pass context from the upper level, thanks!
/ok-to-test |
@liangyuanpeng please, fix CI failures, thanks! |
@@ -516,10 +519,11 @@ func getCadvisorContainerInfo(ca cadvisor.Interface) (map[string]cadvisorapiv2.C | |||
Recursive: true, | |||
}) | |||
if err != nil { | |||
logger := klog.FromContext(context.TODO()) |
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 have ListPodCPUAndMemoryStats()
accept a context and pass it to getCadvisorContainerInfo()
, which would avoid having to declare context.TODO()
here.
@@ -448,8 +452,9 @@ func (p *criStatsProvider) ImageFsDevice(ctx context.Context) (string, error) { | |||
// fsID. If any error occurs, this function logs the error and returns | |||
// nil. | |||
func (p *criStatsProvider) getFsInfo(fsID *runtimeapi.FilesystemIdentifier) (*cadvisorapiv2.FsInfo, error) { | |||
logger := klog.FromContext(context.TODO()) |
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.
getFsInfo()
can accept the context passed from ImageFsStats()
, thereby avoiding the need to declare context.TODO()
here.
// Rootfs and imagefs doesn't make sense for raw cgroup. | ||
s := cadvisorInfoToContainerStats(cgroupName, info, nil, nil) | ||
s := cadvisorInfoToContainerStats(ctx, cgroupName, info, nil, nil) |
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 context passed from the upper layer can be used here, thereby avoiding the need to declare context.TODO()
in this scope.
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 context passed from the upper layer can be used here
No upper layer here, This PR wan't change the parameter of method GetCgroupStats
, because this would involve modifying the interface.
@@ -505,8 +510,9 @@ func (p *criStatsProvider) addPodNetworkStats( | |||
return | |||
} | |||
|
|||
logger := klog.FromContext(context.TODO()) |
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.
Declaring ctx := context.TODO()
at the top of the function is a better practice. This ensures future developers are aware that the function may need to handle Context, particularly if cancellation logic or request scoped values might be added later.
61c94fe
to
a8a0c0a
Compare
Signed-off-by: Lan <[email protected]>
a8a0c0a
to
c439550
Compare
@@ -362,11 +364,15 @@ func buildPodRef(containerLabels map[string]string) statsapi.PodReference { | |||
|
|||
// isPodManagedContainer returns true if the cinfo container is managed by a Pod | |||
func isPodManagedContainer(cinfo *cadvisorapiv2.ContainerInfo) bool { | |||
// Use context.TODO() because we currently do not have a proper context to pass in. | |||
// Replace this with an appropriate context when refactoring this function to accept a context parameter. | |||
ctx := context.TODO() |
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.
Why not? There should be a context on the upper level, I believe.
|
||
// Use context.TODO() because we currently do not have a proper context to pass in. | ||
// Replace this with an appropriate context when refactoring this function to accept a context parameter. | ||
ctx := context.TODO() |
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.
context.TODO()
should not be used in local functions. It should be passed from the upper level.
@liangyuanpeng: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
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-sigs/prow repository. |
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 |
@liangyuanpeng Are you going to work on this PR? If so, please rebase and address review comments. If not, please let me know and I'll create new PR for this component. |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
partof #130069
/assign @bart0sh
Which 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.: