From c37ba9c2dfd68928b1a5c68a75e7365c24e722b0 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Fri, 17 May 2024 15:11:25 -0400 Subject: [PATCH 1/4] Add rest of entities --- pkg/otlp/attributes/attributes.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/otlp/attributes/attributes.go b/pkg/otlp/attributes/attributes.go index 9b305c86..9872ba8d 100644 --- a/pkg/otlp/attributes/attributes.go +++ b/pkg/otlp/attributes/attributes.go @@ -154,8 +154,22 @@ func OriginIDFromAttributes(attrs pcommon.Map) (originID string) { // Prefixes come from pkg/util/kubernetes/kubelet and pkg/util/containers. if containerID, ok := attrs.Get(conventions.AttributeContainerID); ok { originID = "container_id://" + containerID.AsString() + } else if containerImageName, ok := attrs.Get(conventions.AttributeContainerImageName); ok { + originID = "container_image_metadata://" + containerImageName.AsString() + } else if ecsTaskArn, ok := attrs.Get(conventions.AttributeAWSECSTaskARN); ok { + originID = "ecs_task://" + ecsTaskArn.AsString() + } else if hostName, ok := attrs.Get(conventions.AttributeHostName); ok { + originID = hostName.AsString() + } else if deploymentName, ok := attrs.Get(conventions.AttributeK8SDeploymentName); ok { + originID = "deployment://" + deploymentName.AsString() + } else if namespace, ok := attrs.Get(conventions.AttributeK8SNamespaceName); ok { + originID = "namespace://" + namespace.AsString() + } else if nodeUid, ok := attrs.Get(conventions.AttributeK8SNodeUID); ok { + originID = "kubernetes_node_uid://" + nodeUid.AsString() } else if podUID, ok := attrs.Get(conventions.AttributeK8SPodUID); ok { originID = "kubernetes_pod_uid://" + podUID.AsString() + } else if processPid, ok := attrs.Get(conventions.AttributeProcessPID); ok { + originID = "process://" + processPid.AsString() } return } From 2454720b5e738563a8300bc9fead21451b88a5b7 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Fri, 17 May 2024 15:15:49 -0400 Subject: [PATCH 2/4] Fix host --- pkg/otlp/attributes/attributes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/otlp/attributes/attributes.go b/pkg/otlp/attributes/attributes.go index 9872ba8d..486d0a8a 100644 --- a/pkg/otlp/attributes/attributes.go +++ b/pkg/otlp/attributes/attributes.go @@ -159,7 +159,7 @@ func OriginIDFromAttributes(attrs pcommon.Map) (originID string) { } else if ecsTaskArn, ok := attrs.Get(conventions.AttributeAWSECSTaskARN); ok { originID = "ecs_task://" + ecsTaskArn.AsString() } else if hostName, ok := attrs.Get(conventions.AttributeHostName); ok { - originID = hostName.AsString() + originID = "host://" + hostName.AsString() } else if deploymentName, ok := attrs.Get(conventions.AttributeK8SDeploymentName); ok { originID = "deployment://" + deploymentName.AsString() } else if namespace, ok := attrs.Get(conventions.AttributeK8SNamespaceName); ok { From 0e7da163e387ea4196b8bb06c443cb9af970fe84 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Mon, 20 May 2024 08:58:35 -0400 Subject: [PATCH 3/4] Remove host and add tests --- pkg/otlp/attributes/attributes.go | 2 -- pkg/otlp/attributes/attributes_test.go | 44 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/pkg/otlp/attributes/attributes.go b/pkg/otlp/attributes/attributes.go index 486d0a8a..2369754d 100644 --- a/pkg/otlp/attributes/attributes.go +++ b/pkg/otlp/attributes/attributes.go @@ -158,8 +158,6 @@ func OriginIDFromAttributes(attrs pcommon.Map) (originID string) { originID = "container_image_metadata://" + containerImageName.AsString() } else if ecsTaskArn, ok := attrs.Get(conventions.AttributeAWSECSTaskARN); ok { originID = "ecs_task://" + ecsTaskArn.AsString() - } else if hostName, ok := attrs.Get(conventions.AttributeHostName); ok { - originID = "host://" + hostName.AsString() } else if deploymentName, ok := attrs.Get(conventions.AttributeK8SDeploymentName); ok { originID = "deployment://" + deploymentName.AsString() } else if namespace, ok := attrs.Get(conventions.AttributeK8SNamespaceName); ok { diff --git a/pkg/otlp/attributes/attributes_test.go b/pkg/otlp/attributes/attributes_test.go index c5bd0c84..3384d943 100644 --- a/pkg/otlp/attributes/attributes_test.go +++ b/pkg/otlp/attributes/attributes_test.go @@ -213,6 +213,50 @@ func TestOriginIDFromAttributes(t *testing.T) { }(), originID: "kubernetes_pod_uid://k8s_pod_uid_goes_here", }, + { + name: "only deployment name", + attrs: func() pcommon.Map { + attributes := pcommon.NewMap() + attributes.FromRaw(map[string]interface{}{ + conventions.AttributeK8SDeploymentName: "k8s_deployment_name_goes_here", + }) + return attributes + }(), + originID: "deployment://k8s_deployment_name_goes_here", + }, + { + name: "only namespace name", + attrs: func() pcommon.Map { + attributes := pcommon.NewMap() + attributes.FromRaw(map[string]interface{}{ + conventions.AttributeK8SNamespaceName: "k8s_namespace_goes_here", + }) + return attributes + }(), + originID: "namespace://k8s_namespace_goes_here", + }, + { + name: "only node UID", + attrs: func() pcommon.Map { + attributes := pcommon.NewMap() + attributes.FromRaw(map[string]interface{}{ + conventions.AttributeK8SNodeUID: "k8s_node_uid_goes_here", + }) + return attributes + }(), + originID: "kubernetes_node_uid://k8s_node_uid_goes_here", + }, + { + name: "only process pid", + attrs: func() pcommon.Map { + attributes := pcommon.NewMap() + attributes.FromRaw(map[string]interface{}{ + conventions.AttributeProcessPID: "process_pid_goes_here", + }) + return attributes + }(), + originID: "process://process_pid_goes_here", + }, { name: "none", attrs: pcommon.NewMap(), From a98342dd46631d24cb434668eb444f59aa2c11db Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Tue, 21 May 2024 10:03:12 -0400 Subject: [PATCH 4/4] Update pkg/otlp/attributes/attributes.go Co-authored-by: Pablo Baeyens --- pkg/otlp/attributes/attributes.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/otlp/attributes/attributes.go b/pkg/otlp/attributes/attributes.go index 2369754d..e022e871 100644 --- a/pkg/otlp/attributes/attributes.go +++ b/pkg/otlp/attributes/attributes.go @@ -152,6 +152,7 @@ func TagsFromAttributes(attrs pcommon.Map) []string { func OriginIDFromAttributes(attrs pcommon.Map) (originID string) { // originID is always empty. Container ID is preferred over Kubernetes pod UID. // Prefixes come from pkg/util/kubernetes/kubelet and pkg/util/containers. + // See https://github.com/DataDog/datadog-agent/tree/2b4f456/comp/core/tagger#entity-ids if containerID, ok := attrs.Get(conventions.AttributeContainerID); ok { originID = "container_id://" + containerID.AsString() } else if containerImageName, ok := attrs.Get(conventions.AttributeContainerImageName); ok {