Skip to content

Commit

Permalink
Use consistent container name in docker input plugin (influxdata#8703)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 authored Mar 2, 2021
1 parent f8a7654 commit a2725ef
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ func (d *Docker) gatherContainer(
var cname string
for _, name := range container.Names {
trimmedName := strings.TrimPrefix(name, "/")
match := d.containerFilter.Match(trimmedName)
if match {
if !strings.Contains(trimmedName, "/") {
cname = trimmedName
break
}
Expand All @@ -445,6 +444,10 @@ func (d *Docker) gatherContainer(
return nil
}

if !d.containerFilter.Match(cname) {
return nil
}

imageName, imageVersion := docker.ParseImage(container.Image)

tags := map[string]string{
Expand Down Expand Up @@ -480,11 +483,6 @@ func (d *Docker) gatherContainer(
}
daemonOSType := r.OSType

// use common (printed at `docker ps`) name for container
if v.Name != "" {
tags["container_name"] = strings.TrimPrefix(v.Name, "/")
}

// Add labels to tags
for k, label := range container.Labels {
if d.labelFilter.Match(k) {
Expand Down

0 comments on commit a2725ef

Please sign in to comment.