Skip to content

Commit

Permalink
docker_labels_as_tags and docker_env_as_tags are maps
Browse files Browse the repository at this point in the history
  • Loading branch information
xvello authored and hush-hush committed Sep 20, 2017
1 parent 7dfec8e commit 0435d8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func init() {
// Autoconfig
Datadog.SetDefault("autoconf_template_dir", "/datadog/check_configs")
// Docker
Datadog.SetDefault("docker_labels_as_tags", []string{})
Datadog.SetDefault("docker_env_as_tags", []string{})
Datadog.SetDefault("docker_labels_as_tags", map[string]string{})
Datadog.SetDefault("docker_env_as_tags", map[string]string{})
// Kubernetes
Datadog.SetDefault("kubernetes_http_kubelet_port", 10255)
Datadog.SetDefault("kubernetes_https_kubelet_port", 10250)
Expand Down
14 changes: 7 additions & 7 deletions pkg/tagger/collectors/docker_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ func (c *DockerCollector) extractFromInspect(co types.ContainerJSON) ([]string,
}
}

for _, label := range c.labelsAsTags {
if value, found := co.Config.Labels[label]; found {
low = append(low, fmt.Sprintf("%s:%s", label, value))
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))
}
}
}

Expand All @@ -50,10 +52,8 @@ func (c *DockerCollector) extractFromInspect(co types.ContainerJSON) ([]string,
if len(parts) != 2 {
continue
}
for _, envAsTagConfigEntry := range c.envAsTags {
if parts[0] == envAsTagConfigEntry {
low = append(low, fmt.Sprintf("%s:%s", parts[0], parts[1]))
}
if tag_name, found := c.envAsTags[strings.ToLower(parts[0])]; found {
low = append(low, fmt.Sprintf("%s:%s", tag_name, parts[1]))
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/tagger/collectors/docker_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type DockerCollector struct {
client *client.Client
stop chan bool
infoOut chan<- []*TagInfo
labelsAsTags []string
envAsTags []string
labelsAsTags map[string]string
envAsTags map[string]string
}

// Detect tries to connect to the docker socket and returns success
Expand All @@ -54,8 +54,10 @@ func (c *DockerCollector) Detect(out chan<- []*TagInfo) (CollectionMode, error)
c.client = client
c.stop = make(chan bool)
c.infoOut = out
c.labelsAsTags = config.Datadog.GetStringSlice("docker_labels_as_tags")
c.envAsTags = config.Datadog.GetStringSlice("docker_env_as_tags")

// viper lower-cases map keys, so extractor must lowercase before matching
c.labelsAsTags = config.Datadog.GetStringMapString("docker_labels_as_tags")
c.envAsTags = config.Datadog.GetStringMapString("docker_env_as_tags")

if docker.NeedInit() {
err := docker.InitDockerUtil(&docker.Config{})
Expand Down

0 comments on commit 0435d8a

Please sign in to comment.