From 6bc731be92c5b4d455e4a71f6a34ae13cc9aa257 Mon Sep 17 00:00:00 2001 From: Patrick Koenig Date: Tue, 2 Mar 2021 11:19:08 -0800 Subject: [PATCH] Use consistent container name in docker input plugin (#8703) --- plugins/inputs/docker/docker.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index dafedacafb3f1..f795d5b029be4 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -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 } @@ -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{ @@ -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) {