Migrate to contextual logging
zwpaper opened this issue · comments
Area
- Scheduler
- Controller
- Helm Chart
- Documents
Other components
No response
What happened?
k/k is migrating to contextual logging, we should also follow up to add more context when logging
What did you expect to happen?
use contextual logging
How can we reproduce it (as minimally and precisely as possible)?
No response
Anything else we need to know?
No response
Kubernetes version
$ kubectl version
# paste output here
Scheduler Plugins version
/remove-kind bug
/kind feature
Hi @googs1025, thanks for the interest, I think it would be great if we can migrate all logs to contextual logging since the k/k is working hard on it.
feel free to take it and raise PRs for it!
@zwpaper thanks for reply. I want to confirm some details first. Do we need to replace the original klog.ErrorS(err, "xxxxx")
with lh := klog.FromContext(ctx).WithValues(logging.KeyPod, klog.KObj(pod), logging.KeyPodUID, logging.PodUID(pod), logging.KeyNode, nodeName)
? Is my understanding correct?
The following code
lh := klog.FromContext(ctx).WithValues(logging.KeyPod, klog.KObj(pod), logging.KeyPodUID, logging.PodUID(pod), logging.KeyNode, nodeName)
lh.V(4).Info(logging.FlowBegin)
defer lh.V(4).Info(logging.FlowEnd)
nodeTopology, ok := tm.nrtCache.GetCachedNRTCopy(ctx, nodeName, pod)
if !ok {
lh.V(2).Info("invalid topology data")
return framework.NewStatus(framework.Unschedulable, "invalid node topology data")
}
if nodeTopology == nil {
return nil
}
@zwpaper thanks for reply. I want to confirm some details first. Do we need to replace the original
klog.ErrorS(err, "xxxxx")
withlh := klog.FromContext(ctx).WithValues(logging.KeyPod, klog.KObj(pod), logging.KeyPodUID, logging.PodUID(pod), logging.KeyNode, nodeName)
? Is my understanding correct?The following code
lh := klog.FromContext(ctx).WithValues(logging.KeyPod, klog.KObj(pod), logging.KeyPodUID, logging.PodUID(pod), logging.KeyNode, nodeName) lh.V(4).Info(logging.FlowBegin) defer lh.V(4).Info(logging.FlowEnd) nodeTopology, ok := tm.nrtCache.GetCachedNRTCopy(ctx, nodeName, pod) if !ok { lh.V(2).Info("invalid topology data") return framework.NewStatus(framework.Unschedulable, "invalid node topology data") } if nodeTopology == nil { return nil }
This is how I did it in the noderesourcetopology plugin. The values (WithValues
) you need to add are likely different, and the idiom
lh.V(4).Info(logging.FlowBegin)
defer lh.V(4).Info(logging.FlowEnd)
Is something I find useful for debugging but is not universally accepted as good practice. Besides that IMO the general approach should look like that indeed.
@zwpaper thanks for reply. I want to confirm some details first. Do we need to replace the original
klog.ErrorS(err, "xxxxx")
withlh := klog.FromContext(ctx).WithValues(logging.KeyPod, klog.KObj(pod), logging.KeyPodUID, logging.PodUID(pod), logging.KeyNode, nodeName)
? Is my understanding correct?
The following codelh := klog.FromContext(ctx).WithValues(logging.KeyPod, klog.KObj(pod), logging.KeyPodUID, logging.PodUID(pod), logging.KeyNode, nodeName) lh.V(4).Info(logging.FlowBegin) defer lh.V(4).Info(logging.FlowEnd) nodeTopology, ok := tm.nrtCache.GetCachedNRTCopy(ctx, nodeName, pod) if !ok { lh.V(2).Info("invalid topology data") return framework.NewStatus(framework.Unschedulable, "invalid node topology data") } if nodeTopology == nil { return nil }This is how I did it in the noderesourcetopology plugin. The values (
WithValues
) you need to add are likely different, and the idiomlh.V(4).Info(logging.FlowBegin) defer lh.V(4).Info(logging.FlowEnd)
Is something I find useful for debugging but is not universally accepted as good practice. Besides that IMO the general approach should look like that indeed.
Thank you for your answer, it really helped me understand the background of this issue.
/assign
i will take this