I have the metric below and I want to drop the label "exported_namespace="test" and I am using the prometheus relabel_config but I'm not sure if the config will work properly:
"kube_pod_status_ready{condition="false", env="test", exported_namespace="test", instance="10.69.19.17:8080", job="kube-state-metrics", namespace="test", pod="test-1-deploy", uid="1asdadasaas"}
prometheus scrape config
- source_labels = [exported_namesapce]
separator: ,
action: labeldrop
regex: (.*)
replacement: $1
Please note that you must use metric_relabel_configs
instead of relabel_configs
if you want apply relabeling on the collected metrics. See this article for details.
If you want to drop a label with a particular value from the collected metric, then use the following relabeling rule at metric_relabel_configs section of the needed scrape_config:
- source_labels: [exported_namespace]
regex: test
target_label: exported_namespace
replacement: ""
This relabeling rule substitutes the exported_namespace="test"
label with exported_namespace=""
label, which, in turn, is automatically removed by Prometheus, since it contains an empty label value. You can play with this relabeling rule at this page.
If you need just dropping the exported_namespace
label with any value, then use the following relabeling rule:
- action: labeldrop
regex: exported_namespace
Note that this rule will drop any value for exported_namespace
label. For example, both exported_namespace="test"
and exported_namespace="foo"
will be dropped.
Update: if you use vmagent, then you can use if
filter for dropping label with the particular value. For example, the following rule drops only exported_namespace="test"
label:
- if: '{exported_namespace="test"}'
regex: exported_namespace
action: labeldrop
See these docs for more information about if
filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With