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

Add remaining entities to OriginIDFromAttributes #332

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/otlp/attributes/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,23 @@ 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.
liustanley marked this conversation as resolved.
Show resolved Hide resolved
// 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 {
originID = "container_image_metadata://" + containerImageName.AsString()
} else if ecsTaskArn, ok := attrs.Get(conventions.AttributeAWSECSTaskARN); ok {
originID = "ecs_task://" + ecsTaskArn.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
}
Expand Down
44 changes: 44 additions & 0 deletions pkg/otlp/attributes/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading