help about relabeling configs, not equal

80 views
Skip to first unread message

David B G.

unread,
Jun 23, 2023, 10:14:52 PM6/23/23
to Prometheus Users
Hello Prometheus community, Could you please help me about a I doubt I have in the realabeling usage, I am trying to do an not equal rule to change the path of one value for example I have the following information object labels:

__name__: "istio_requests_total"
request_path: "/bad1"


and I what I am trying is to replace if the request_path is distinct to good1 or good2 to change to /dummy path.

Here is my relabeling rule:

- source_labels: [__name__,request_path]
  regex: istio_requests_total;^.(/good1|/good2)
  action: replace
  replacement: /dummy
  target_label: request_path


This rule doesn’t seems to work and I don’t know if it is a way to say for example if not equal too good1 or good2 change the path /dummy.

Thank you all for your help.


Brian Candler

unread,
Jun 24, 2023, 3:34:54 AM6/24/23
to Prometheus Users
Remove the start-of-line marker (^) and match any single character (.) from the middle of your regex. As-is, it can't possibly match. Try instead:

regex: istio_requests_total;(/bad1|/bad2)

Prometheus implicitly anchors the entire regex, so in effect your regex matches the same as

^(istio_requests_total;(/bad1|/bad2))$

This also means it will only match exactly /bad1 and /bad2, not paths starting with /bad1 or /bad2. If you want the latter, then you must explicitly match additional characters after it:

regex: istio_requests_total;(/bad1|/bad2).*

If instead you want to match all paths *except* /good1 and /good2 then you need two steps: one to set a temporary "keep" label for these, and then relabel only those which don't have it.  This has been asked and answered recently:

David B G.

unread,
Jun 24, 2023, 11:59:58 AM6/24/23
to Prometheus Users
Hello Brian, Thank you for you answer I really appreciate it

I followed your steps specifically in:

If instead you want to match all paths *except* /good1 and /good2 then you need two steps: one to set a temporary "keep" label for these, and then relabel only those which don't have it. 

 I have achieved a temporal keep but I dont know how can I relabel only the ones  that dont have /good1 or /good2 because there are a lot of path and always changing, I was trying something like this


- source_labels: [__name__,request_path]
  regex: istio_requests_total;(/good1|/good2)
  replacement: true
  target_label: __tmp_keep
- source_labels: [__name__,__tmp_keep]
  regex: istio_requests_total
  replacement: /dummy
  target_label: request_path

But I dont know how to work with the tmp_keep to say for example replace when the path is different of /good1 or /good2


Tahnk you very much

Brian Candler

unread,
Jun 24, 2023, 1:29:02 PM6/24/23
to Prometheus Users
Semicolons are inserted between the source_labels. so you need:

regex: istio_requests_total;

I think it's clearer if you quote it:

regex: "istio_requests_total;"

David B G.

unread,
Jun 24, 2023, 2:29:54 PM6/24/23
to Prometheus Users
Thank you very much Brian, it works like a charm. 

I really appreciate you help.
Reply all
Reply to author
Forward
0 new messages