Skip to content
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

Migrate to contextual logging #743

Open
2 of 4 tasks
zwpaper opened this issue May 18, 2024 · 7 comments
Open
2 of 4 tasks

Migrate to contextual logging #743

zwpaper opened this issue May 18, 2024 · 7 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@zwpaper
Copy link
Member

zwpaper commented May 18, 2024

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
@zwpaper zwpaper added the kind/bug Categorizes issue or PR as related to a bug. label May 18, 2024
@zwpaper
Copy link
Member Author

zwpaper commented May 18, 2024

/remove-kind bug
/kind feature

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. and removed kind/bug Categorizes issue or PR as related to a bug. labels May 18, 2024
@ffromani
Copy link
Contributor

noderesourcetopology migrated in #710 and #725

@googs1025
Copy link
Member

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

@zwpaper
Copy link
Member Author

zwpaper commented Jun 14, 2024

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!

@googs1025
Copy link
Member

@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
	}

@ffromani
Copy link
Contributor

@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.

@googs1025
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

4 participants