Regular Expression and Label Action Support to match two or more source labels

60 views
Skip to first unread message

tejaswini vadlamudi

unread,
May 21, 2024, 10:43:05 AM5/21/24
to Prometheus Users
The below relabeling rule from Victoria Metrics is useful for matching accurate ports and dropping unwanted targets.        - action: keep_if_equal
          source_labels: [__meta_kubernetes_service_annotation_prometheus_io_port, __meta_kubernetes_pod_container_port_number]
Does anyone know how we can compare two labels using Prometheus Relabeling rules?

Based on my analysis, Prometheus doesn't support regex patterns on 
1. backreferences like \1 
2. lookaheads or lookbehinds

Brian Candler

unread,
May 22, 2024, 6:01:31 AM5/22/24
to Prometheus Users
Yes, there are similar relabel actions "keepequal" and "dropequal":

These were added in v2.41.0 / 2022-12-20
They behave slightly differently from VM: in Prometheus, the concatenation of source_labels is compared with target_label.

tejaswini vadlamudi

unread,
May 22, 2024, 6:52:03 AM5/22/24
to Prometheus Users
Sure Brian, I was aware of this.
This config comes with a software change, but is there any possibility or workaround in the old (< 2.41) Prometheus releases on this topic?

/Teja

Brian Candler

unread,
May 22, 2024, 7:07:37 AM5/22/24
to Prometheus Users
I would assume that the reason this feature was added was because there wasn't a feasible alternative way to do it.

I suggest you upgrade to v2.45.5 which is the current "Long Term Stable" release.  The previous LTS release (v2.37) went end-of-life in July 2023, so it seems you're very likely running something unsupported at the moment.

tejaswini vadlamudi

unread,
May 22, 2024, 2:02:45 PM5/22/24
to Prometheus Users
Thanks a lot, Brain!
Reply all
Reply to author
Forward
0 new messages