Skip to content

Commit

Permalink
[Libbeat] Fix docker autodiscovery to follow ECS
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin authored and jsoriano committed Feb 22, 2019
1 parent e17130f commit 61a6532
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
37 changes: 19 additions & 18 deletions libbeat/autodiscover/providers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand All @@ -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,
},
}

Expand Down
12 changes: 6 additions & 6 deletions libbeat/autodiscover/providers/docker/docker_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions libbeat/autodiscover/providers/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 61a6532

Please sign in to comment.