diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index a2b9f8cd4cd..b07ba8a499b 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -14,6 +14,8 @@ https://github.com/elastic/beats/compare/v6.2.2...6.2[Check the HEAD diff] *Affecting all Beats* +- Fix conditions checking on autodiscover Docker labels. {pull}6412[6412] + *Auditbeat* *Filebeat* diff --git a/libbeat/autodiscover/providers/docker/docker.go b/libbeat/autodiscover/providers/docker/docker.go index e06718f7c47..a79110e190e 100644 --- a/libbeat/autodiscover/providers/docker/docker.go +++ b/libbeat/autodiscover/providers/docker/docker.go @@ -92,12 +92,17 @@ func (d *Provider) emitContainer(event bus.Event, flag string) { host = container.IPAddresses[0] } + labelMap := common.MapStr{} + for k, v := range container.Labels { + labelMap[k] = v + } + meta := common.MapStr{ "container": common.MapStr{ "id": container.ID, "name": container.Name, "image": container.Image, - "labels": container.Labels, + "labels": labelMap, }, } diff --git a/libbeat/autodiscover/providers/docker/docker_integration_test.go b/libbeat/autodiscover/providers/docker/docker_integration_test.go index 3cb892c0534..e23384edb20 100644 --- a/libbeat/autodiscover/providers/docker/docker_integration_test.go +++ b/libbeat/autodiscover/providers/docker/docker_integration_test.go @@ -34,7 +34,9 @@ func TestDockerStart(t *testing.T) { defer listener.Stop() // Start - ID, err := d.ContainerStart("busybox", "echo", "Hi!") + cmd := []string{"echo", "Hi!"} + labels := map[string]string{"label": "value"} + ID, err := d.ContainerStart("busybox", cmd, labels) if err != nil { t.Fatal(err) } @@ -69,7 +71,7 @@ func checkEvent(t *testing.T, listener bus.Listener, start bool) { assert.Nil(t, getValue(e, "start")) } assert.Equal(t, getValue(e, "docker.container.image"), "busybox") - assert.Equal(t, getValue(e, "docker.container.labels"), map[string]string{}) + assert.Equal(t, getValue(e, "docker.container.labels"), common.MapStr{"label": "value"}) assert.NotNil(t, getValue(e, "docker.container.id")) assert.NotNil(t, getValue(e, "docker.container.name")) assert.NotNil(t, getValue(e, "host")) diff --git a/libbeat/tests/docker/docker.go b/libbeat/tests/docker/docker.go index 26481fb2154..433d8dfd4f7 100644 --- a/libbeat/tests/docker/docker.go +++ b/libbeat/tests/docker/docker.go @@ -20,15 +20,16 @@ func NewClient() (Client, error) { } // ContainerStart pulls and starts the given container -func (c Client) ContainerStart(image string, cmd ...string) (string, error) { +func (c Client) ContainerStart(image string, cmd []string, labels map[string]string) (string, error) { ctx := context.Background() if _, err := c.cli.ImagePull(ctx, image, types.ImagePullOptions{}); err != nil { return "", err } resp, err := c.cli.ContainerCreate(ctx, &container.Config{ - Image: image, - Cmd: cmd, + Image: image, + Cmd: cmd, + Labels: labels, }, nil, nil, "") if err != nil { return "", err