From 61a6532bf545c94811b56646e2fbe310e2acfd41 Mon Sep 17 00:00:00 2001 From: beats-jenkins Date: Thu, 14 Feb 2019 16:41:59 +0100 Subject: [PATCH] [Libbeat] Fix docker autodiscovery to follow ECS See https://github.com/elastic/beats/issues/10757 --- .../autodiscover/providers/docker/docker.go | 37 ++++++++++--------- .../docker/docker_integration_test.go | 12 +++--- .../providers/docker/docker_test.go | 1 + 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/libbeat/autodiscover/providers/docker/docker.go b/libbeat/autodiscover/providers/docker/docker.go index 6275897cb9f7..9cc512b9a6f0 100644 --- a/libbeat/autodiscover/providers/docker/docker.go +++ b/libbeat/autodiscover/providers/docker/docker.go @@ -136,23 +136,24 @@ func (d *Provider) emitContainer(event bus.Event, flag string) { } meta := common.MapStr{ - "container": common.MapStr{ - "id": container.ID, - "name": container.Name, - "image": container.Image, - "labels": labelMap, + "id": container.ID, + "name": container.Name, + "image": common.MapStr{ + "name": container.Image, }, + // TODO: Do we need some dedotting here? + "labels": labelMap, } // Without this check there would be overlapping configurations with and without ports. if len(container.Ports) == 0 { event := bus.Event{ - "provider": d.uuid, - "id": container.ID, - flag: true, - "host": host, - "docker": meta, + "provider": d.uuid, + "id": container.ID, + flag: true, + "host": host, + "container": meta, "meta": common.MapStr{ - "docker": meta, + "container": meta, }, } @@ -162,14 +163,14 @@ func (d *Provider) emitContainer(event bus.Event, flag string) { // Emit container container and port information for _, port := range container.Ports { event := bus.Event{ - "provider": d.uuid, - "id": container.ID, - flag: true, - "host": host, - "port": port.PrivatePort, - "docker": meta, + "provider": d.uuid, + "id": container.ID, + flag: true, + "host": host, + "port": port.PrivatePort, + "container": meta, "meta": common.MapStr{ - "docker": meta, + "container": meta, }, } diff --git a/libbeat/autodiscover/providers/docker/docker_integration_test.go b/libbeat/autodiscover/providers/docker/docker_integration_test.go index acb1f8ff46a4..695a0e2fda9c 100644 --- a/libbeat/autodiscover/providers/docker/docker_integration_test.go +++ b/libbeat/autodiscover/providers/docker/docker_integration_test.go @@ -82,7 +82,7 @@ func checkEvent(t *testing.T, listener bus.Listener, start bool) { select { case e := <-listener.Events(): // Ignore any other container - if getValue(e, "docker.container.image") != "busybox" { + if getValue(e, "container.image") != "busybox" { continue } if start { @@ -92,17 +92,17 @@ func checkEvent(t *testing.T, listener bus.Listener, start bool) { assert.Equal(t, getValue(e, "stop"), true) assert.Nil(t, getValue(e, "start")) } - assert.Equal(t, getValue(e, "docker.container.image"), "busybox") - assert.Equal(t, getValue(e, "docker.container.labels"), common.MapStr{ + assert.Equal(t, getValue(e, "container.image.name"), "busybox") + assert.Equal(t, getValue(e, "container.labels"), common.MapStr{ "label": common.MapStr{ "value": "foo", "child": "bar", }, }) - assert.NotNil(t, getValue(e, "docker.container.id")) - assert.NotNil(t, getValue(e, "docker.container.name")) + assert.NotNil(t, getValue(e, "container.id")) + assert.NotNil(t, getValue(e, "container.name")) assert.NotNil(t, getValue(e, "host")) - assert.Equal(t, getValue(e, "docker"), getValue(e, "meta.docker")) + assert.Equal(t, getValue(e, "container"), getValue(e, "meta.container")) return case <-time.After(10 * time.Second): diff --git a/libbeat/autodiscover/providers/docker/docker_test.go b/libbeat/autodiscover/providers/docker/docker_test.go index 7c01e6e2ec37..97a74b7e76ea 100644 --- a/libbeat/autodiscover/providers/docker/docker_test.go +++ b/libbeat/autodiscover/providers/docker/docker_test.go @@ -38,6 +38,7 @@ func TestGenerateHints(t *testing.T) { }, // Docker meta must be present in the hints { + // TODO: why must docker be present in the hints? Did my changes now break something? event: bus.Event{ "docker": common.MapStr{ "container": common.MapStr{