Home > Software engineering >  How to copy a value from one field to other if a field exists by using ingestnode pipeline
How to copy a value from one field to other if a field exists by using ingestnode pipeline

Time:11-21

I want to create a new field called kubernetes.pod.name if fields called prometheus.labels.pod exists in the logs. I found out that from the set processor I could copy the value which is present in prometheus.labels.pod to a new field kubernetes.pod.name but I need to do this conditionally as the pod name keeps on changing.

How do i set a condition such that if field prometheus.labels.pod exists then only I need to add a new field called kubernetes.pod.name (both has the same value)

ctx.prometheus?.labels?.namespace== "name_of_namespace"

could be do similarly can we do

ctx.prometheus?.labels?.pod== "*"

to check if this field exists or not?

CodePudding user response:

If the text is a string and if its required to set a condition that if it exists then best way is to use the below condition in set processor.

ctx.prometheus?.labels?.namespace!=null

This is how I implemented the above scenario by using ingest node pipeline.

"set": {
  "field": "kubernetes.pod.name",
  "copy_from": "prometheus.labels.pod",
  "if": "ctx.prometheus?.labels?.pod!=null",
  "ignore_failure": true
}
  • Related