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 1 commit
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
6 changes: 2 additions & 4 deletions libbeat/autodiscover/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,6 @@ func (p *pod) emitEvents(pod *kubernetes.Pod, flag string, containers []kubernet

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

Expand Down Expand Up @@ -387,8 +384,9 @@ 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,
"kubernetes": meta, // these will be moved to ECS (container.name and container.image.name) through alias type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment looks a bit confusing to me. Not all these kubernetes.* meta fields are moved, right?

"container": cmeta,
},
}
Expand Down
6 changes: 4 additions & 2 deletions libbeat/processors/add_kubernetes_metadata/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@
Kubernetes statefulset name

- name: container.name
type: keyword
type: alias
path: container.name
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
description: >
Kubernetes container name

- name: container.image
type: keyword
type: alias
path: container.image.name
description: >
Kubernetes container image
9 changes: 4 additions & 5 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,10 @@ 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")
containerImage, err := metadata.GetValue("container.image")
if err == nil {
metaClone.Delete("container.image")
metaClone.Put("container.image.name", containerImage)
}
metaClone.Delete("container.image")
cmeta, err := metaClone.Clone().GetValue("container")
if err == nil {
event.Fields.DeepUpdate(common.MapStr{
Expand All @@ -271,6 +269,7 @@ 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")
event.Fields.DeepUpdate(common.MapStr{
Expand Down
12 changes: 2 additions & 10 deletions metricbeat/module/kubernetes/state_container/state_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ var (

Labels: map[string]p.LabelMap{
"pod": p.KeyLabel(mb.ModuleDataKey + ".pod.name"),
"container": p.KeyLabel("name"),
"container": p.KeyLabel("name"), // this will be moved to ECS container.name through alias type
"namespace": p.KeyLabel(mb.ModuleDataKey + ".namespace"),

"node": p.Label(mb.ModuleDataKey + ".node.name"),
"container_id": p.Label("id"),
"image": p.Label("image"),
"image": p.Label("image"), // this will be moved to ECS container.image.name through alias type
},
}
)
Expand Down Expand Up @@ -147,14 +147,6 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error {
containerFields.Put("id", cID[split+3:])
}
}
if containerImage, ok := event["image"]; ok {
cImage := (containerImage).(string)
containerFields.Put("image.name", cImage)
}
if containerName, ok := event["name"]; ok {
cName := (containerName).(string)
containerFields.Put("name", cName)
}
if len(containerFields) > 0 {
rootFields = common.MapStr{
"container": containerFields,
Expand Down