如果日志中存在名為 prometheus.labels.pod 的欄位,我想創建一個名為 kubernetes.pod.name 的新欄位。我發現從 set 處理器中我可以將 prometheus.labels.pod 中存在的值復制到一個新欄位 kubernetes.pod.name 但我需要有條件地執行此操作,因為 pod 名稱不斷變化。
我如何設定一個條件,如果欄位 prometheus.labels.pod 存在,那么我只需要添加一個名為 kubernetes.pod.name 的新欄位(兩者都具有相同的值)
ctx.prometheus?.labels?.namespace== "name_of_namespace"
可以做類似的事情我們可以做嗎
ctx.prometheus?.labels?.pod== "*"
檢查此欄位是否存在?
uj5u.com熱心網友回復:
如果文本是一個字串,并且需要設定一個條件,如果它存在,那么最好的方法是在設定處理器中使用以下條件。
ctx.prometheus?.labels?.namespace!=null
這就是我通過使用攝取節點管道來實作上述場景的方式。
"set": {
"field": "kubernetes.pod.name",
"copy_from": "prometheus.labels.pod",
"if": "ctx.prometheus?.labels?.pod!=null",
"ignore_failure": true
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/363497.html
上一篇:我必須在彈性堆疊中使用多少集群?
