Skip to content

Commit

Permalink
Migrate add_docker_metadata to ECS (elastic#9412)
Browse files Browse the repository at this point in the history
Migrate the docker fields to ECS container fields.

* docker.container.id -> container.id
* docker.container.image -> container.image.name
* docker.container.name -> container.name
* docker.container.labels -> container.labels
  • Loading branch information
ruflin authored Dec 27, 2018
1 parent d0b54f2 commit f43683f
Show file tree
Hide file tree
Showing 22 changed files with 159 additions and 139 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Rename beat.timezone to event.timezone. {pull}9458[9458]
- Use _doc as document type. {pull}9056[9056]{pull}9573[9573]
- Update to Golang 1.11.3. {pull}9560[9560]
- Migrate add_docker_metadata fields to ECS.

*Auditbeat*

Expand Down
15 changes: 6 additions & 9 deletions auditbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2670,30 +2670,27 @@ Docker stats collected from Docker.
*`docker.container.id`*::
+
--
type: keyword
Unique container id.
type: alias
alias to: container.id
--
*`docker.container.image`*::
+
--
type: keyword
Name of the image the container was built on.
type: alias
alias to: container.image.name
--
*`docker.container.name`*::
+
--
type: keyword
Container name.
type: alias
alias to: container.name
--
Expand Down
2 changes: 1 addition & 1 deletion auditbeat/include/fields.go

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions dev-tools/ecs-migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@
alias6: true
alias: true

# Docker processor
- from: docker.container.id
to: container.id
alias: true
alias6: true

- from: docker.container.image
to: container.image.name
alias6: true
alias: true

- from: docker.container.name
to: container.name
alias6: true
alias: true

- from: docker.container.labels # TODO: How to map these?
to: container.labels
alias6: false
alias: true


# Filebeat modules

## Suricata module
Expand Down
15 changes: 6 additions & 9 deletions filebeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -696,30 +696,27 @@ Docker stats collected from Docker.
*`docker.container.id`*::
+
--
type: keyword
Unique container id.
type: alias
alias to: container.id
--
*`docker.container.image`*::
+
--
type: keyword
Name of the image the container was built on.
type: alias
alias to: container.image.name
--
*`docker.container.name`*::
+
--
type: keyword
Container name.
type: alias
alias to: container.name
--
Expand Down
2 changes: 1 addition & 1 deletion filebeat/include/fields.go

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions heartbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -261,30 +261,27 @@ Docker stats collected from Docker.
*`docker.container.id`*::
+
--
type: keyword
Unique container id.
type: alias
alias to: container.id
--
*`docker.container.image`*::
+
--
type: keyword
Name of the image the container was built on.
type: alias
alias to: container.image.name
--
*`docker.container.name`*::
+
--
type: keyword
Container name.
type: alias
alias to: container.name
--
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/include/fields.go

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions journalbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -542,30 +542,27 @@ Docker stats collected from Docker.
*`docker.container.id`*::
+
--
type: keyword
Unique container id.
type: alias
alias to: container.id
--
*`docker.container.image`*::
+
--
type: keyword
Name of the image the container was built on.
type: alias
alias to: container.image.name
--
*`docker.container.name`*::
+
--
type: keyword
Container name.
type: alias
alias to: container.name
--
Expand Down
2 changes: 1 addition & 1 deletion journalbeat/include/fields.go

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions libbeat/processors/add_docker_metadata/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
type: group
fields:
- name: container.id
type: keyword
description: >
Unique container id.
type: alias
path: container.id
migration: true

- name: container.image
type: keyword
description: >
Name of the image the container was built on.
type: alias
path: container.image.name
migration: true

- name: container.name
type: keyword
description: >
Container name.
- name: container.labels
type: alias
path: container.name
migration: true

- name: container.labels # TODO: How to map these?
type: object
object_type: keyword
description: >
Expand Down
12 changes: 4 additions & 8 deletions libbeat/processors/add_docker_metadata/add_docker_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

const (
processorName = "add_docker_metadata"
dockerContainerIDKey = "docker.container.id"
dockerContainerIDKey = "container.id"
cgroupCacheExpiration = 5 * time.Minute
)

Expand Down Expand Up @@ -89,7 +89,7 @@ func buildDockerMetadataProcessor(cfg *common.Config, watcherConstructor docker.
"field": "source",
"separator": string(os.PathSeparator),
"index": config.SourceIndex,
"target": "docker.container.id",
"target": dockerContainerIDKey,
})
sourceProcessor, err = actions.NewExtractField(procConf)
if err != nil {
Expand Down Expand Up @@ -168,10 +168,6 @@ func (d *addDockerMetadata) Run(event *beat.Event) (*beat.Event, error) {
container := d.watcher.Container(cid)
if container != nil {
meta := common.MapStr{}
metaIface, ok := event.Fields["docker"]
if ok {
meta = metaIface.(common.MapStr)
}

if len(container.Labels) > 0 {
labels := common.MapStr{}
Expand All @@ -187,9 +183,9 @@ func (d *addDockerMetadata) Run(event *beat.Event) (*beat.Event, error) {
}

meta.Put("container.id", container.ID)
meta.Put("container.image", container.Image)
meta.Put("container.image.name", container.Image)
meta.Put("container.name", container.Name)
event.Fields["docker"] = meta.Clone()
event.Fields.DeepUpdate(meta.Clone())
} else {
d.log.Debugf("Container not found: cid=%s", cid)
}
Expand Down
82 changes: 41 additions & 41 deletions libbeat/processors/add_docker_metadata/add_docker_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,21 @@ func TestMatchContainer(t *testing.T) {
assert.NoError(t, err, "processing an event")

assert.EqualValues(t, common.MapStr{
"docker": common.MapStr{
"container": common.MapStr{
"id": "container_id",
"image": "image",
"labels": common.MapStr{
"a": common.MapStr{
"x": "1",
},
"b": common.MapStr{
"value": "2",
"foo": "3",
},
"container": common.MapStr{
"id": "container_id",
"image": common.MapStr{
"name": "image",
},
"labels": common.MapStr{
"a": common.MapStr{
"x": "1",
},
"b": common.MapStr{
"value": "2",
"foo": "3",
},
"name": "name",
},
"name": "name",
},
"foo": "container_id",
}, result.Fields)
Expand Down Expand Up @@ -178,17 +178,17 @@ func TestMatchContainerWithDedot(t *testing.T) {
assert.NoError(t, err, "processing an event")

assert.EqualValues(t, common.MapStr{
"docker": common.MapStr{
"container": common.MapStr{
"id": "container_id",
"image": "image",
"labels": common.MapStr{
"a_x": "1",
"b": "2",
"b_foo": "3",
},
"name": "name",
"container": common.MapStr{
"id": "container_id",
"image": common.MapStr{
"name": "image",
},
"labels": common.MapStr{
"a_x": "1",
"b": "2",
"b_foo": "3",
},
"name": "name",
},
"foo": "container_id",
}, result.Fields)
Expand Down Expand Up @@ -228,16 +228,16 @@ func TestMatchSource(t *testing.T) {
assert.NoError(t, err, "processing an event")

assert.EqualValues(t, common.MapStr{
"docker": common.MapStr{
"container": common.MapStr{
"id": "FABADA",
"image": "image",
"labels": common.MapStr{
"a": "1",
"b": "2",
},
"name": "name",
"container": common.MapStr{
"id": "FABADA",
"image": common.MapStr{
"name": "image",
},
"labels": common.MapStr{
"a": "1",
"b": "2",
},
"name": "name",
},
"source": inputSource,
}, result.Fields)
Expand Down Expand Up @@ -291,16 +291,16 @@ func TestMatchPIDs(t *testing.T) {
assert.NoError(t, err, "initializing add_docker_metadata processor")

dockerMetadata := common.MapStr{
"docker": common.MapStr{
"container": common.MapStr{
"id": "FABADA",
"image": "image",
"labels": common.MapStr{
"a": "1",
"b": "2",
},
"name": "name",
"container": common.MapStr{
"id": "FABADA",
"image": common.MapStr{
"name": "image",
},
"labels": common.MapStr{
"a": "1",
"b": "2",
},
"name": "name",
},
}

Expand Down
Loading

0 comments on commit f43683f

Please sign in to comment.