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

[pkg/otlp/attributes] Add Kubernetes DD tags to keep #334

Merged
merged 4 commits into from
May 22, 2024
Merged
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
16 changes: 16 additions & 0 deletions .chloggen/stanley.liu_add-kubernetes-dd-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component (e.g. pkg/quantile)
component: pkg/otlp/attributes

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Adds Kubernetes DD tags to keep when mapping resource attributes.

# The PR related to this change
issues: [334]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
80 changes: 80 additions & 0 deletions pkg/otlp/attributes/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,81 @@ var (
"app.kubernetes.io/part-of": "kube_app_part_of",
"app.kubernetes.io/managed-by": "kube_app_managed_by",
}

// Kubernetes out of the box Datadog tags
// https://docs.datadoghq.com/containers/kubernetes/tag/?tab=containerizedagent#out-of-the-box-tags
// https://github.com/DataDog/datadog-agent/blob/d33d042d6786e8b85f72bb627fbf06ad8a658031/comp/core/tagger/taggerimpl/collectors/workloadmeta_extract.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expose those constants and use them here? Am concerned about the tags diverge moving forward

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be difficult because comp/core/tagger isn't a module. We could ask container platform if it's possible to create a separate module for storing these constants

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, probably worth leaving an issue or ticket to track it. Would be good to keep those constants in a single source of truth

// Note: if any OTel semantics happen to overlap with these tag names, they will also be added as Datadog tags.
kubernetesDDTags = map[string]struct{}{
"architecture": {},
"availability-zone": {},
"chronos_job": {},
"chronos_job_owner": {},
"cluster_name": {},
"container_id": {},
"container_name": {},
"dd_remote_config_id": {},
"dd_remote_config_rev": {},
"display_container_name": {},
"docker_image": {},
"ecs_cluster_name": {},
"ecs_container_name": {},
"eks_fargate_node": {},
"env": {},
"git.commit.sha": {},
"git.repository_url": {},
"image_id": {},
"image_name": {},
"image_tag": {},
"kube_app_component": {},
"kube_app_instance": {},
"kube_app_managed_by": {},
"kube_app_name": {},
"kube_app_part_of": {},
"kube_app_version": {},
"kube_container_name": {},
"kube_cronjob": {},
"kube_daemon_set": {},
"kube_deployment": {},
"kube_job": {},
"kube_namespace": {},
"kube_ownerref_kind": {},
"kube_ownerref_name": {},
"kube_priority_class": {},
"kube_qos": {},
"kube_replica_set": {},
"kube_replication_controller": {},
"kube_service": {},
"kube_stateful_set": {},
"language": {},
"marathon_app": {},
"mesos_task": {},
"nomad_dc": {},
"nomad_group": {},
"nomad_job": {},
"nomad_namespace": {},
"nomad_task": {},
"oshift_deployment": {},
"oshift_deployment_config": {},
"os_name": {},
"os_version": {},
"persistentvolumeclaim": {},
"pod_name": {},
"pod_phase": {},
"rancher_container": {},
"rancher_service": {},
"rancher_stack": {},
"region": {},
"service": {},
"short_image": {},
"swarm_namespace": {},
"swarm_service": {},
"task_name": {},
"task_family": {},
"task_version": {},
"task_arn": {},
"version": {},
}
)

// TagsFromAttributes converts a selected list of attributes
Expand Down Expand Up @@ -132,6 +207,11 @@ func TagsFromAttributes(attrs pcommon.Map) []string {
if datadogKey, found := kubernetesMapping[key]; found && value.Str() != "" {
tags = append(tags, fmt.Sprintf("%s:%s", datadogKey, value.Str()))
}

// Kubernetes DD tags
if _, found := kubernetesDDTags[key]; found {
tags = append(tags, fmt.Sprintf("%s:%s", key, value.Str()))
}
return true
})

Expand Down
2 changes: 2 additions & 0 deletions pkg/otlp/attributes/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestTagsFromAttributes(t *testing.T) {
conventions.AttributeDeploymentEnvironment: "prod",
conventions.AttributeContainerName: "custom",
"datadog.container.tag.custom.team": "otel",
"kube_cronjob": "cron",
}
attrs := pcommon.NewMap()
attrs.FromRaw(attributeMap)
Expand All @@ -53,6 +54,7 @@ func TestTagsFromAttributes(t *testing.T) {
fmt.Sprintf("%s:%s", "env", "prod"),
fmt.Sprintf("%s:%s", "container_name", "custom"),
fmt.Sprintf("%s:%s", "custom.team", "otel"),
fmt.Sprintf("%s:%s", "kube_cronjob", "cron"),
}, TagsFromAttributes(attrs))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/otlp/logs/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func TestTranslator(t *testing.T) {
}(),
},
want: datadogV2.HTTPLogItem{
Ddtags: datadog.PtrString("otel_source:test"),
Ddtags: datadog.PtrString("service:otlp_col,otel_source:test"),
Message: *datadog.PtrString(""),
AdditionalProperties: map[string]string{
"app": "test",
Expand Down
Loading