Skip to content

Commit

Permalink
Move uid back to pod.uid
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Pérez-Aradros Herce committed Jul 10, 2018
1 parent 18d509f commit b6d8f76
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
12 changes: 6 additions & 6 deletions libbeat/common/kubernetes/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type MetaGeneratorConfig struct {
IncludeAnnotations []string `config:"include_annotations"`

// Undocumented settings, to be deprecated in favor of `drop_fields` processor:
IncludeUID bool `config:"include_uid"`
IncludePodUID bool `config:"include_pod_uid"`
IncludeCreatorMetadata bool `config:"include_creator_metadata"`
}

Expand Down Expand Up @@ -88,11 +88,6 @@ func (g *metaGenerator) ResourceMetadata(obj Resource) common.MapStr {
meta["namespace"] = objMeta.GetNamespace()
}

// Add UID metadata if enabled
if g.IncludeUID {
meta["uid"] = objMeta.GetUid()
}

// Add controller metadata if present
if g.IncludeCreatorMetadata {
for _, ref := range objMeta.OwnerReferences {
Expand Down Expand Up @@ -123,6 +118,11 @@ func (g *metaGenerator) ResourceMetadata(obj Resource) common.MapStr {
func (g *metaGenerator) PodMetadata(pod *Pod) common.MapStr {
podMeta := g.ResourceMetadata(pod)

// Add UID metadata if enabled
if g.IncludePodUID {
safemapstr.Put(podMeta, "pod.uid", pod.GetMetadata().GetUid())
}

safemapstr.Put(podMeta, "pod.name", pod.GetMetadata().GetName())
safemapstr.Put(podMeta, "node.name", pod.Spec.GetNodeName())

Expand Down
8 changes: 5 additions & 3 deletions libbeat/common/kubernetes/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestPodMetadataDeDot(t *testing.T) {
withUID, _ := common.NewConfigFrom(map[string]interface{}{"include_uid": true})
withUID, _ := common.NewConfigFrom(map[string]interface{}{"include_pod_uid": true})

UID := "005f3b90-4b9d-12f8-acf0-31020a840133"
Deployment := "Deployment"
Expand Down Expand Up @@ -71,8 +71,10 @@ func TestPodMetadataDeDot(t *testing.T) {
},
},
meta: common.MapStr{
"pod": common.MapStr{"name": ""},
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
"pod": common.MapStr{
"name": "",
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
},
"node": common.MapStr{"name": "test"},
"labels": common.MapStr{"a": common.MapStr{"value": "bar", "key": "foo"}},
},
Expand Down
4 changes: 2 additions & 2 deletions libbeat/processors/add_kubernetes_metadata/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
description: >
Kubernetes pod name
- name: uid
- name: pod.uid
type: keyword
description: >
Kubernetes uid
Kubernetes Pod UID
- name: namespace
type: keyword
Expand Down
9 changes: 7 additions & 2 deletions metricbeat/module/kubernetes/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ func NewResourceMetadataEnricher(
// update
func(m map[string]common.MapStr, r kubernetes.Resource) {
id := join(r.GetMetadata().GetNamespace(), r.GetMetadata().GetName())
m[id] = metaGen.ResourceMetadata(r)
switch r := r.(type) {
case *kubernetes.Pod:
m[id] = metaGen.PodMetadata(r)
default:
m[id] = metaGen.ResourceMetadata(r)
}
},
// delete
func(m map[string]common.MapStr, r kubernetes.Resource) {
Expand Down Expand Up @@ -145,7 +150,7 @@ func NewContainerMetadataEnricher(
// update
func(m map[string]common.MapStr, r kubernetes.Resource) {
pod := r.(*kubernetes.Pod)
meta := metaGen.ResourceMetadata(r)
meta := metaGen.PodMetadata(pod)
for _, container := range append(pod.GetSpec().GetContainers(), pod.GetSpec().GetInitContainers()...) {
id := join(r.GetMetadata().GetNamespace(), r.GetMetadata().GetName(), container.GetName())
m[id] = meta
Expand Down

0 comments on commit b6d8f76

Please sign in to comment.