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
https: