Skip to content

Commit

Permalink
Introduce join_standard_tags setting (#6253)
Browse files Browse the repository at this point in the history
* [kubernetes_state] Introduce join_standard_tags setting.

`join_standard_tags` enables label joins for standard tags captured from the following labels:
- `tags.datadoghq.com/version`
- `tags.datadoghq.com/env`
- `tags.datadoghq.com/service`

Metrics are being enriched for the following objects: Pod, Deployment, ReplicaSet, DaemonSet, StatefulSet, Job, CronJob.

* Add more tests to validate standard tags joins

* Fix linting error

* Fix formatting issues flagged by black
  • Loading branch information
xornivore authored Apr 16, 2020
1 parent 5926f99 commit 815c59b
Show file tree
Hide file tree
Showing 4 changed files with 3,894 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def _create_kubernetes_state_prometheus_instance(self, instance):
extra_labels = ksm_instance.get('label_joins', {})
hostname_override = is_affirmative(ksm_instance.get('hostname_override', True))
join_kube_labels = is_affirmative(ksm_instance.get('join_kube_labels', False))
join_standard_tags = is_affirmative(ksm_instance.get('join_standard_tags', False))

ksm_instance.update(
{
Expand Down Expand Up @@ -370,6 +371,44 @@ def _create_kubernetes_state_prometheus_instance(self, instance):
}
)

labels_to_get = [
"label_tags_datadoghq_com_env",
"label_tags_datadoghq_com_service",
"label_tags_datadoghq_com_version",
]

if join_standard_tags:
ksm_instance['label_joins'].update(
{
"kube_pod_labels": {"labels_to_match": ["pod", "namespace"], "labels_to_get": labels_to_get},
"kube_deployment_labels": {
"labels_to_match": ["deployment", "namespace"],
"labels_to_get": labels_to_get,
},
"kube_replicaset_labels": {
"labels_to_match": ["replicaset", "namespace"],
"labels_to_get": labels_to_get,
},
"kube_daemonset_labels": {
"labels_to_match": ["daemonset", "namespace"],
"labels_to_get": labels_to_get,
},
"kube_statefulset_labels": {
"labels_to_match": ["statefulset", "namespace"],
"labels_to_get": labels_to_get,
},
"kube_job_labels": {"labels_to_match": ["job_name", "namespace"], "labels_to_get": labels_to_get},
}
)

ksm_instance.setdefault("labels_mapper", {}).update(
{
"label_tags_datadoghq_com_env": "env",
"label_tags_datadoghq_com_service": "service",
"label_tags_datadoghq_com_version": "version",
}
)

ksm_instance['label_joins'].update(extra_labels)
if hostname_override:
ksm_instance['label_to_hostname'] = 'node'
Expand Down
Loading

0 comments on commit 815c59b

Please sign in to comment.