kubernetes-sigs / scheduler-plugins

Repository for out-of-tree scheduler plugins based on scheduler framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

kubernetes/enhancements#3077

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

v0.28.9

/remove-kind bug
/kind feature

noderesourcetopology migrated in #710 and #725

@ffromani @zwpaper Do other plugins also need log modification? If necessary, I will take it

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") 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
	}

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") 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
	}

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.

Thank you for your answer, it really helped me understand the background of this issue.

/assign

i will take this