From b9cf6991e6376695b84c8a35d9ea5889a6866122 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Fri, 11 Aug 2023 09:24:32 +0200 Subject: [PATCH] Use tracing semconv types instead of own defines To keep things in sync when adding new traces, we now use the official semconv types of OTEL rather than our own values. Nothing should change for now behavior wise. Refers to https://github.com/kubernetes/kubernetes/pull/119771 Signed-off-by: Sascha Grunert --- pkg/kubelet/kubelet.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index e8918472ee8..e5e72798434 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -36,6 +36,7 @@ import ( libcontaineruserns "github.com/opencontainers/runc/libcontainer/userns" "github.com/opencontainers/selinux/go-selinux" "go.opentelemetry.io/otel/attribute" + semconv "go.opentelemetry.io/otel/semconv/v1.12.0" "go.opentelemetry.io/otel/trace" "k8s.io/client-go/informers" @@ -1686,11 +1687,11 @@ func (kl *Kubelet) Run(updates <-chan kubetypes.PodUpdate) { // Callers should not write an event if this operation returns an error. func (kl *Kubelet) SyncPod(ctx context.Context, updateType kubetypes.SyncPodType, pod, mirrorPod *v1.Pod, podStatus *kubecontainer.PodStatus) (isTerminal bool, err error) { ctx, otelSpan := kl.tracer.Start(ctx, "syncPod", trace.WithAttributes( - attribute.String("k8s.pod.uid", string(pod.UID)), + semconv.K8SPodUIDKey.String(string(pod.UID)), attribute.String("k8s.pod", klog.KObj(pod).String()), - attribute.String("k8s.pod.name", pod.Name), + semconv.K8SPodNameKey.String(pod.Name), attribute.String("k8s.pod.update_type", updateType.String()), - attribute.String("k8s.namespace.name", pod.Namespace), + semconv.K8SNamespaceNameKey.String(pod.Namespace), )) klog.V(4).InfoS("SyncPod enter", "pod", klog.KObj(pod), "podUID", pod.UID) defer func() { @@ -1971,10 +1972,10 @@ func (kl *Kubelet) SyncTerminatingPod(_ context.Context, pod *v1.Pod, podStatus // TODO(#113606): connect this with the incoming context parameter, which comes from the pod worker. // Currently, using that context causes test failures. ctx, otelSpan := kl.tracer.Start(context.Background(), "syncTerminatingPod", trace.WithAttributes( - attribute.String("k8s.pod.uid", string(pod.UID)), + semconv.K8SPodUIDKey.String(string(pod.UID)), attribute.String("k8s.pod", klog.KObj(pod).String()), - attribute.String("k8s.pod.name", pod.Name), - attribute.String("k8s.namespace.name", pod.Namespace), + semconv.K8SPodNameKey.String(pod.Name), + semconv.K8SNamespaceNameKey.String(pod.Namespace), )) defer otelSpan.End() klog.V(4).InfoS("SyncTerminatingPod enter", "pod", klog.KObj(pod), "podUID", pod.UID) @@ -2106,10 +2107,10 @@ func (kl *Kubelet) SyncTerminatingRuntimePod(_ context.Context, runningPod *kube // kubelet restarts in the middle of the action. func (kl *Kubelet) SyncTerminatedPod(ctx context.Context, pod *v1.Pod, podStatus *kubecontainer.PodStatus) error { ctx, otelSpan := kl.tracer.Start(ctx, "syncTerminatedPod", trace.WithAttributes( - attribute.String("k8s.pod.uid", string(pod.UID)), + semconv.K8SPodUIDKey.String(string(pod.UID)), attribute.String("k8s.pod", klog.KObj(pod).String()), - attribute.String("k8s.pod.name", pod.Name), - attribute.String("k8s.namespace.name", pod.Namespace), + semconv.K8SPodNameKey.String(pod.Name), + semconv.K8SNamespaceNameKey.String(pod.Namespace), )) defer otelSpan.End() klog.V(4).InfoS("SyncTerminatedPod enter", "pod", klog.KObj(pod), "podUID", pod.UID)