From 907bf08b3b4b5091a89c9d4e1223e5fa9ef789a7 Mon Sep 17 00:00:00 2001 From: Xavier Vello Date: Tue, 19 Sep 2017 16:25:29 +0200 Subject: [PATCH] support high cardinality tag extraction with + prefix, update conf example --- pkg/collector/dist/datadog.yaml | 11 ++++++++--- pkg/tagger/collectors/docker_extract.go | 12 ++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/collector/dist/datadog.yaml b/pkg/collector/dist/datadog.yaml index 8d2d50c211332..e286acddf7566 100644 --- a/pkg/collector/dist/datadog.yaml +++ b/pkg/collector/dist/datadog.yaml @@ -139,9 +139,14 @@ metadata_collectors: # log_level: info # log_file: /var/log/datadog/agent.log -# Docker +# Docker tag extraction +# +# We can extract container label or environment variables +# as metric tags. If you prefix your tag name with +, it +# will only be added to high cardinality metrics (docker check) # # docker_labels_as_tags: -# - label_name +# label_name: tag_name +# high_cardinality_label: +tag_name # docker_env_as_tags: -# - ENVVAR_NAME +# ENVVAR_NAME: tag_name diff --git a/pkg/tagger/collectors/docker_extract.go b/pkg/tagger/collectors/docker_extract.go index deceaa8bcd39b..0e7b79b3c050e 100644 --- a/pkg/tagger/collectors/docker_extract.go +++ b/pkg/tagger/collectors/docker_extract.go @@ -41,7 +41,11 @@ func (c *DockerCollector) extractFromInspect(co types.ContainerJSON) ([]string, if len(c.labelsAsTags) > 0 { for label_name, label_value := range co.Config.Labels { if tag_name, found := c.labelsAsTags[strings.ToLower(label_name)]; found { - low = append(low, fmt.Sprintf("%s:%s", tag_name, label_value)) + if tag_name[0] == '+' { + high = append(high, fmt.Sprintf("%s:%s", tag_name[1:], label_value)) + } else { + low = append(low, fmt.Sprintf("%s:%s", tag_name, label_value)) + } } } } @@ -53,7 +57,11 @@ func (c *DockerCollector) extractFromInspect(co types.ContainerJSON) ([]string, continue } if tag_name, found := c.envAsTags[strings.ToLower(parts[0])]; found { - low = append(low, fmt.Sprintf("%s:%s", tag_name, parts[1])) + if tag_name[0] == '+' { + high = append(high, fmt.Sprintf("%s:%s", tag_name[1:], parts[1])) + } else { + low = append(low, fmt.Sprintf("%s:%s", tag_name, parts[1])) + } } } }