Reputation: 249
I have a metrics of the followinf form:
kube_deployment_labels{deployment="application1-deployment",endpoint="http",instance="10.273.78.36:8180",job="kube-state-metrics",label_app="applcation-request-adapter",label_environment="dev",label_version="dev",namespace="default",pod="kore-prom-kube-state-metrics-654d86c799-2kqzs",service="kore-prom-kube-state-metrics"}
I need to perform label replace on namespace to dev_namespace and label_version to dev_version. How to write the nested label_replace statement? I am able to apply the same for them seperately as:
label_replace(kube_deployment_labels{label_app=~".*",label_environment=~"dev",label_version=~"dev"}, "dev_namespace", "$1", "namespace", "(.*)")
and
label_replace(kube_deployment_labels{label_app=~".*",label_environment=~"dev",label_version=~"dev"}, "dev_version", "$1", "label_version", "(.*)")
How to combine them together to rename or replace multiple labels at the same time in prometheus?
Upvotes: 5
Views: 5995
Reputation: 249
After some work around, I got the solution for this. I thought I will post it here so that others can have a look:
label_replace(label_replace(kube_deployment_labels{label_app=~".*",label_environment=~"dev",label_version=~"dev"}, "dev_namespace", "$1", "namespace", "(.*)"), "dev_version", "$1", "label_version", "(.*)")
Upvotes: 7