-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Relabeling: Using a labelname in a regex (to use the labelname's value) #11556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Since I'm reviewing #11564, I would like to understand a full use case example for this. Like, why would you put something into |
The usage of metadata:
annotations: # containername:scheme:port:path:scrapespeed
prometheus.io/scrape_1: "server:https:8585:/metrics:normal" relabel_configs:
- source_labels: [ __meta_kubernetes_pod_annotation_prometheus_io_scrape_1 ]
action: replace
target_label: __tmp_port
regex: "[^:]+:[^:]+:([^:]+):[^:]+:[^:]+"
- source_labels: [ __meta_kubernetes_pod_container_port_number ]
action: keep
regex: ${__tmp_port} So you are correct in your assumption this was about "comparing an annotation label to a port label" in this case. But I do think the functionality serves a good purpose for other use cases during service discovery. |
Looking over the solution, it seems to solve this, but it is not as powerful as allowing It would also keep the |
@juliusv the issue is with service discoveries that expose multiple times the same target. I came up with a simple solution to the problem . |
Thanks for the explanations, makes sense! @thernstig is still suggesting to do something more general than the simple equality matching implemented in #11564. However, I'm not sure how we would implement that in a clean way. We can't just put something like |
@juliusv I think if you "premassage" the regex it could work. Search the regex for I do not think it would be a breaking change as if someone already had the literal text The only thing is that users might find it weird that special regex characters are used for something that is not actual regex functionality. But with that said, I am fine with @roidelapluie approach as-is, even though I think it could be more powerful from the get-go. |
Hmm yeah, that could work, although it is a tad weird as you say. @roidelapluie Just checking to see what you think of @thernstig's proposal... but I'm fine either way :) |
This would be incompatible with go regexes as you can have named capture groups. |
@roidelapluie the capture groups are used in Again, with that said, I am fine with it as-is if that is preferred 😄 |
I think on general this would create a lot of corner cases and things difficult to do. What if a label contains a dot? It would be passed as a regex? And would not work like you would expect. |
The pre-massaging could escape special characters. I do understand such an implementation would require quite a bit of work, so probably not worth it. The main concern with my proposed solution is that users would be confused by using So your current solution works quite well as-is to solve many use cases and for me that is good enough. |
Okay I'd say let's go with my proposal @juliusv |
Yep, sounds good. |
…ng actions These actions are supported by Prometheus starting from v2.41.0 See prometheus/prometheus#11564 , prometheus/prometheus#11556 and prometheus/prometheus#3756 Side note: It's a pity that Prometheus developers decided inventing `keepequal` and `dropequal` relabeling actions instead of adding support for `keep_if_equal` and `drop_if_equal` relabeling actions supported by VictoriaMetrics since June 2020 - see 2a39ba6 .
…ng actions These actions are supported by Prometheus starting from v2.41.0 See prometheus/prometheus#11564 , prometheus/prometheus#11556 and prometheus/prometheus#3756 Side note: It's a pity that Prometheus developers decided inventing `keepequal` and `dropequal` relabeling actions instead of adding support for `keep_if_equal` and `drop_if_equal` relabeling actions supported by VictoriaMetrics since June 2020 - see 2a39ba6 .
Uh oh!
There was an error while loading. Please reload this page.
Proposal
In relabeling config, let's say I have saved a value in a label like
__tmp_port
. I then want to match some port in Kubernetes service discoveryIf the value of
__meta_kubernetes_pod_container_port_number
and__tmp_port
are both8080
, it will keep this target. It could possibly be used inreplacement
as well.I would like to be able to use any existing
__
value in the regex, even the ones found from service discovery such as__meta_kubernetes_pod_container_port_number
.It solves e.g. #3756
The text was updated successfully, but these errors were encountered: