Skip to content

Commit

Permalink
fix schema
Browse files Browse the repository at this point in the history
Signed-off-by: chrismark <chrismarkou92@gmail.com>
  • Loading branch information
ChrsMark committed Mar 9, 2021
1 parent bdb2e53 commit e11ea81
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 398 deletions.
10 changes: 5 additions & 5 deletions libbeat/autodiscover/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ 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)

cmeta := common.MapStr{
"id": cid,
"runtime": runtimes[c.Name],
"image": common.MapStr{
"name": c.Image,
},
"name": c.Name,
}

// Information that can be used in discovering a workload
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 @@ -452,14 +452,12 @@ func TestEmitEvent(t *testing.T) {
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"id": "foobar",
"runtime": "docker",
"name": "filebeat",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -576,14 +574,12 @@ func TestEmitEvent(t *testing.T) {
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"runtime": "docker",
"id": "foobar",
"name": "filebeat",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -620,14 +616,12 @@ func TestEmitEvent(t *testing.T) {
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"id": "foobar",
"runtime": "docker",
"name": "filebeat",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -790,14 +784,12 @@ func TestEmitEvent(t *testing.T) {
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"runtime": "",
"id": "",
"name": "filebeat",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -891,10 +883,6 @@ 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",
Expand All @@ -903,8 +891,10 @@ func TestEmitEvent(t *testing.T) {
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"id": "",
"runtime": "",
"name": "filebeat",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -998,10 +988,6 @@ 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",
Expand All @@ -1010,8 +996,10 @@ func TestEmitEvent(t *testing.T) {
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"runtime": "",
"id": "",
"name": "filebeat",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -1115,14 +1103,12 @@ func TestEmitEvent(t *testing.T) {
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"id": "foobar",
"runtime": "docker",
"name": "filebeat",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -1228,14 +1214,12 @@ func TestEmitEvent(t *testing.T) {
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"id": "foobar",
"runtime": "docker",
"name": "filebeat",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -1373,14 +1357,12 @@ func TestEmitEvent(t *testing.T) {
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat",
"image": "elastic/filebeat:6.3.0",
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"id": "foobar",
"runtime": "docker",
"name": "filebeat",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -1418,14 +1400,12 @@ func TestEmitEvent(t *testing.T) {
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat-init",
"image": "elastic/filebeat:6.3.0",
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"id": "foobar-init",
"runtime": "docker",
"name": "filebeat-init",
},
},
"config": []*common.Config{},
Expand Down Expand Up @@ -1463,14 +1443,12 @@ func TestEmitEvent(t *testing.T) {
}, "node": common.MapStr{
"name": "node",
},
"container": common.MapStr{
"name": "filebeat-ephemeral",
"image": "elastic/filebeat:6.3.0",
},
},
"container": common.MapStr{
"image": common.MapStr{"name": "elastic/filebeat:6.3.0"},
"id": "foobar-ephemeral",
"runtime": "docker",
"name": "filebeat-ephemeral",
},
},
"config": []*common.Config{},
Expand Down
14 changes: 7 additions & 7 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ func (k *kubernetesAnnotator) Run(event *beat.Event) (*beat.Event, error) {
}

metaClone := metadata.Clone()
// image and name will be added to ECS fields through alias type
// id and runtime need to be added explicitly
metaClone.Delete("container.name")
metaClone.Delete("container.image")
containerImage, err := metaClone.GetValue("container.image")
if err == nil {
metaClone.Delete("container.image")
metaClone.Put("container.image.name", containerImage)
}
cmeta, err := metaClone.Clone().GetValue("container")
if err == nil {
event.Fields.DeepUpdate(common.MapStr{
Expand All @@ -269,9 +270,8 @@ func (k *kubernetesAnnotator) Run(event *beat.Event) (*beat.Event, error) {
}

kubeMeta := metadata.Clone()
// remove id and runtime from kubernetes meta (their place is under container meta)
kubeMeta.Delete("container.id")
kubeMeta.Delete("container.runtime")
// remove container meta from kubernetes.container.*
kubeMeta.Delete("container")
event.Fields.DeepUpdate(common.MapStr{
"kubernetes": kubeMeta,
})
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 @@ -17,10 +17,8 @@
"request": {
"nanocores": 200000000
}
},
"image": "ubuntu:latest",
},
"id": "docker://5f8ce416d10ab0b28ce5c7d521de2264aa03ff4d001e1194076f6a02a330139f",
"name": "ubuntu",
"status": {
"ready": true,
"restarts": 0,
Expand Down Expand Up @@ -62,11 +60,15 @@
},
"container": {
"runtime": "docker",
"id": "5f8ce416d10ab0b28ce5c7d521de2264aa03ff4d001e1194076f6a02a330139f"
"id": "5f8ce416d10ab0b28ce5c7d521de2264aa03ff4d001e1194076f6a02a330139f",
"image": {
"name": "ubuntu:latest"
},
"name": "ubuntu"
},
"event": {
"dataset": "kubernetes.container",
"module": "kubernetes",
"duration": 33750820
}
}
}
Loading

0 comments on commit e11ea81

Please sign in to comment.