Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use alias to report container image in k8s parts #24380

Merged
merged 7 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Update to ECS 1.7.0. {pull}22571[22571]
- Add support for SCRAM-SHA-512 and SCRAM-SHA-256 in Kafka output. {pull}12867[12867]
- Fix panic with inline SSL when the certificate or key were small than 256 bytes. {pull}23820[23820]
- Use alias to report container image in k8s metadata. {pull}24380[24380]

*Auditbeat*

Expand Down
6 changes: 4 additions & 2 deletions auditbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11970,7 +11970,7 @@ type: keyword
*`kubernetes.container.name`*::
+
--
Kubernetes container name
Kubernetes container name (different than the name from the runtime)


type: keyword
Expand All @@ -11983,7 +11983,9 @@ type: keyword
Kubernetes container image


type: keyword
type: alias

alias to: container.image.name

--

Expand Down
2 changes: 1 addition & 1 deletion auditbeat/include/fields.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions filebeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -86569,7 +86569,7 @@ type: keyword
*`kubernetes.container.name`*::
+
--
Kubernetes container name
Kubernetes container name (different than the name from the runtime)


type: keyword
Expand All @@ -86582,7 +86582,9 @@ type: keyword
Kubernetes container image


type: keyword
type: alias

alias to: container.image.name

--

Expand Down
2 changes: 1 addition & 1 deletion filebeat/include/fields.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions heartbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9552,7 +9552,7 @@ type: keyword
*`kubernetes.container.name`*::
+
--
Kubernetes container name
Kubernetes container name (different than the name from the runtime)


type: keyword
Expand All @@ -9565,7 +9565,9 @@ type: keyword
Kubernetes container image


type: keyword
type: alias

alias to: container.image.name

--

Expand Down
2 changes: 1 addition & 1 deletion heartbeat/include/fields.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions journalbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9897,7 +9897,7 @@ type: keyword
*`kubernetes.container.name`*::
+
--
Kubernetes container name
Kubernetes container name (different than the name from the runtime)


type: keyword
Expand All @@ -9910,7 +9910,9 @@ type: keyword
Kubernetes container image


type: keyword
type: alias

alias to: container.image.name

--

Expand Down
2 changes: 1 addition & 1 deletion journalbeat/include/fields.go

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions libbeat/autodiscover/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,18 +349,14 @@ func (p *pod) emitEvents(pod *kubernetes.Pod, flag string, containers []kubernet
// so it works also on `stop` if containers have been already deleted.
eventID := fmt.Sprintf("%s.%s", pod.GetObjectMeta().GetUID(), c.Name)

meta := p.metagen.Generate(
pod,
metadata.WithFields("container.name", c.Name),
metadata.WithFields("container.image", c.Image),
)
meta := p.metagen.Generate(pod, metadata.WithFields("container.name", c.Name))

cmeta := common.MapStr{
"id": cid,
"id": cid,
"runtime": runtimes[c.Name],
"image": common.MapStr{
"name": c.Image,
},
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
"runtime": runtimes[c.Name],
}

// Information that can be used in discovering a workload
Expand All @@ -387,6 +383,7 @@ func (p *pod) emitEvents(pod *kubernetes.Pod, flag string, containers []kubernet
"host": host,
"port": 0,
"kubernetes": kubemeta,
//Actual metadata that will enrich the event
"meta": common.MapStr{
"kubernetes": meta,
"container": cmeta,
Expand Down
66 changes: 22 additions & 44 deletions libbeat/autodiscover/providers/kubernetes/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,8 @@ func TestEmitEvent(t *testing.T) {
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
}, "container": common.MapStr{
"name": "filebeat",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -576,10 +574,8 @@ func TestEmitEvent(t *testing.T) {
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
}, "container": common.MapStr{
"name": "filebeat",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -621,10 +617,8 @@ func TestEmitEvent(t *testing.T) {
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
}, "container": common.MapStr{
"name": "filebeat",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -792,10 +786,8 @@ func TestEmitEvent(t *testing.T) {
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
}, "container": common.MapStr{
"name": "filebeat",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -895,15 +887,13 @@ func TestEmitEvent(t *testing.T) {
"meta": common.MapStr{
"kubernetes": common.MapStr{
"namespace": "default",
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
},
"pod": common.MapStr{
"name": "filebeat",
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
}, "container": common.MapStr{
"name": "filebeat",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -1003,15 +993,13 @@ func TestEmitEvent(t *testing.T) {
"meta": common.MapStr{
"kubernetes": common.MapStr{
"namespace": "default",
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
},
"pod": common.MapStr{
"name": "filebeat",
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
}, "container": common.MapStr{
"name": "filebeat",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -1120,10 +1108,8 @@ func TestEmitEvent(t *testing.T) {
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
}, "container": common.MapStr{
"name": "filebeat",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -1234,10 +1220,8 @@ func TestEmitEvent(t *testing.T) {
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
}, "container": common.MapStr{
"name": "filebeat",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -1380,10 +1364,8 @@ func TestEmitEvent(t *testing.T) {
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
}, "container": common.MapStr{
"name": "filebeat",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -1426,10 +1408,8 @@ func TestEmitEvent(t *testing.T) {
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat-init",
"image": "elastic/filebeat:6.3.0",
}, "container": common.MapStr{
"name": "filebeat-init",
},
},
"container": common.MapStr{
Expand Down Expand Up @@ -1472,10 +1452,8 @@ func TestEmitEvent(t *testing.T) {
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat-ephemeral",
"image": "elastic/filebeat:6.3.0",
}, "container": common.MapStr{
"name": "filebeat-ephemeral",
},
},
"container": common.MapStr{
Expand Down
5 changes: 3 additions & 2 deletions libbeat/processors/add_kubernetes_metadata/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@
- name: container.name
type: keyword
description: >
Kubernetes container name
Kubernetes container name (different than the name from the runtime)

- name: container.image
type: keyword
type: alias
path: container.image.name
description: >
Kubernetes container image
2 changes: 2 additions & 0 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,10 @@ func (k *kubernetesAnnotator) Run(event *beat.Event) (*beat.Event, error) {
}

kubeMeta := metadata.Clone()
// remove container meta from kubernetes.container.*
kubeMeta.Delete("container.id")
kubeMeta.Delete("container.runtime")
kubeMeta.Delete("container.image")
event.Fields.DeepUpdate(common.MapStr{
"kubernetes": kubeMeta,
})
Expand Down
6 changes: 4 additions & 2 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -27465,7 +27465,7 @@ type: keyword
*`kubernetes.container.name`*::
+
--
Kubernetes container name
Kubernetes container name (different than the name from the runtime)


type: keyword
Expand All @@ -27478,7 +27478,9 @@ type: keyword
Kubernetes container image


type: keyword
type: alias

alias to: container.image.name

--

Expand Down
12 changes: 7 additions & 5 deletions metricbeat/module/kubernetes/state_container/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
"app": "playground"
},
"container": {
"name": "ubuntu",
"cpu": {
"request": {
"nanocores": 200000000
}
},
"image": "ubuntu:latest",
},
"id": "docker://5f8ce416d10ab0b28ce5c7d521de2264aa03ff4d001e1194076f6a02a330139f",
"name": "ubuntu",
"status": {
"ready": true,
"restarts": 0,
Expand Down Expand Up @@ -62,11 +61,14 @@
},
"container": {
"runtime": "docker",
"id": "5f8ce416d10ab0b28ce5c7d521de2264aa03ff4d001e1194076f6a02a330139f"
"id": "5f8ce416d10ab0b28ce5c7d521de2264aa03ff4d001e1194076f6a02a330139f",
"image": {
"name": "ubuntu:latest"
},
},
"event": {
"dataset": "kubernetes.container",
"module": "kubernetes",
"duration": 33750820
}
}
}
Loading