Is it possible to keep targets if the values of two lables are equal ?

34 views
Skip to first unread message

Lior Goikhburg

unread,
May 27, 2022, 11:25:30 AM5/27/22
to Prometheus Users
Hi!

My use case is to keep targets (kubernetes sd) only if the values of two specific lables are equal. Can this be done ?

My Idea was to concatenate lables and do a regex lookahead comparison. The problem is that, unfortunately, lookahead is not supported by go's RE2.

Here is what I tried:
      # Only keep pods if container port matches tcp-port annotation
      - source_labels:
        - __meta_kubernetes_pod_container_port_number
        - __meta_kubernetes_pod_annotation_tcp_port
        action: keep
        regex: ([^;]+);(?=\1$)

Is there any other way around ?

Lior Goikhburg

unread,
May 28, 2022, 6:27:14 AM5/28/22
to Prometheus Users
Also, backreferences (e.g. \1) are not supported in regex.
Is it possible to set a variable and use it in regex: ?

пятница, 27 мая 2022 г. в 18:25:30 UTC+3, Lior Goikhburg:

Brian Candler

unread,
May 29, 2022, 9:10:25 AM5/29/22
to Prometheus Users
The only "variables" in rewriting rules are additional temporary labels, starting __tmp_.  I don't think there's anything you can do with those, that you can't do with a regular label.
Reply all
Reply to author
Forward
0 new messages