Skip to content

Commit

Permalink
[add_kubernetes_metadata] Remove extra debug messages (#40625)
Browse files Browse the repository at this point in the history
* Remove extra debug messages

---------

Signed-off-by: constanca <constanca.manteigas@elastic.co>
  • Loading branch information
constanca-m committed Sep 9, 2024
1 parent 83a880f commit 9008e8d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
++++

The `add_kubernetes_metadata` processor annotates each event with relevant
metadata based on which Kubernetes pod the event originated from.
metadata based on which Kubernetes pod the event originated from. This processor only adds metadata to the events that do not have it yet present.

At startup, it detects an `in_cluster` environment and caches the
Kubernetes-related metadata. Events are only annotated if a valid configuration
is detected. If it's not able to detect a valid Kubernetes configuration,
Expand Down
11 changes: 2 additions & 9 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func New(cfg *config.C) (beat.Processor, error) {
kubernetesAvailable: false,
}

// complete processor's initialisation asynchronously so as to re-try on failing k8s client initialisations in case
// complete processor's initialisation asynchronously to re-try on failing k8s client initialisations in case
// the k8s node is not yet ready.
go processor.init(config, cfg)

Expand Down Expand Up @@ -260,17 +260,14 @@ func (k *kubernetesAnnotator) init(config kubeAnnotatorConfig, cfg *config.C) {
watcher.AddEventHandler(kubernetes.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
pod := obj.(*kubernetes.Pod)
k.log.Debugf("Adding kubernetes pod: %s/%s", pod.GetNamespace(), pod.GetName())
k.addPod(pod)
},
UpdateFunc: func(obj interface{}) {
pod := obj.(*kubernetes.Pod)
k.log.Debugf("Updating kubernetes pod: %s/%s", pod.GetNamespace(), pod.GetName())
k.updatePod(pod)
},
DeleteFunc: func(obj interface{}) {
pod := obj.(*kubernetes.Pod)
k.log.Debugf("Removing pod: %s/%s", pod.GetNamespace(), pod.GetName())
k.removePod(pod)
},
})
Expand Down Expand Up @@ -316,19 +313,17 @@ func (k *kubernetesAnnotator) Run(event *beat.Event) (*beat.Event, error) {
return event, nil
}
if kubernetesMetadataExist(event) {
k.log.Debug("Skipping add_kubernetes_metadata processor as kubernetes metadata already exist")
return event, nil
}

index := k.matchers.MetadataIndex(event.Fields)
if index == "" {
k.log.Debug("No container match string, not adding kubernetes data")
return event, nil
}

k.log.Debugf("Using the following index key %s", index)
metadata := k.cache.get(index)
if metadata == nil {
k.log.Debugf("Index key %s did not match any of the cached resources", index)
return event, nil
}

Expand Down Expand Up @@ -381,7 +376,6 @@ func (k *kubernetesAnnotator) Close() error {
func (k *kubernetesAnnotator) addPod(pod *kubernetes.Pod) {
metadata := k.indexers.GetMetadata(pod)
for _, m := range metadata {
k.log.Debugf("Created index %s for pod %s/%s", m.Index, pod.GetNamespace(), pod.GetName())
k.cache.set(m.Index, m.Data)
}
}
Expand All @@ -391,7 +385,6 @@ func (k *kubernetesAnnotator) updatePod(pod *kubernetes.Pod) {

// Add it again only if it is not being deleted
if pod.GetObjectMeta().GetDeletionTimestamp() != nil {
k.log.Debugf("Removing kubernetes pod being terminated: %s/%s", pod.GetNamespace(), pod.GetName())
return
}

Expand Down

0 comments on commit 9008e8d

Please sign in to comment.