Reputation: 4732
I would like to drop a label but only from a specific series. From the doc I can see that the action needed is labeldrop.
My starting point is something like
- action: replace
source_labels: [__name__, url_rule]
regex: 'test_.+;(.+)'
target_label: path
- action: labeldrop
regex: 'url_rule'
How can I ensure that the second action will only drop the url_rule label from metrics starting by test_ (like in the first action)?
Upvotes: 4
Views: 3672
Reputation: 17784
Prometheus doesn't provide the ability for conditional label removal via action: labeldrop
. This action is applied unconditionally to every label of every metric. But you can use the following workaround for removal of url_rule
label from metrics with names starting from test_
:
- source_labels: [__name__, url_rule]
regex: "test_.+;.+"
replacement: ""
target_label: url_rule
It just sets an empty value to url_rule
label for metrics with names starting from test_
prefix. Then Prometheus drops labels with empty values after the relabeling.
P.S. The relabeling rule can be simplified with if
condition when using VictoriaMetrics - Prometheus-like monitoring solution I work on:
- if: "{__name__=~'test_.+'}"
action: labeldrop
regex: url_rule
See these docs for details.
Upvotes: 13