Skip to content
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

Support regex-less relabling #3117

Open
discordianfish opened this Issue Aug 25, 2017 · 7 comments

Comments

Projects
None yet
4 participants
@discordianfish
Copy link
Member

discordianfish commented Aug 25, 2017

Hi,

not feeling too strongly about it but definitely a nice to have which arguably would be less complex to manage as a a user than the regex we have right now. It think I never had an actual need for an regex.

We should support action: replace without a regex, which would simply make all labels available in the replacement. This could be look like this:

- action: replace
  target_label: new_label
  replacement: "foo/${__meta_foo}/${__address__}/bla/${__meta_bar}"

Alternatively we could keep source_labels and just map them 1:1 to position args in replacement:

- action: replace
  source_labels: [ __meta_foo, __address__, __meta_bar ]
  target_label: new_label
  replacement: "foo/${1}/${2}/bla/${3}"

Might need to be a new action though since the current behavior is different.
Feel free to close this if it seems out of scope but I believe it makes one of the most mind bending parts of the prometheus config much easier to understand.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Aug 25, 2017

The question I would ask is what does this allow that relabelling already doesn't?

I've seen very few cases where such syntactic sugar would help, and having more than one way to do things is rarely a win for users. Particularly for something like relabelling.

@grobie

This comment has been minimized.

Copy link
Member

grobie commented Aug 25, 2017

Heh, funny, we just ran into a limitation of relabel rules (as mentioned in #2545) which could be solved by interpolation of labels in other fields. This would make it possible to configure k8s discovery only with relabel rules.

- action: keep
  source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_ports] # comma separated list of ports for example
  regex: "(^|,){{ __meta_kubernetes_pod_container_port_number }}($|,)"
- action: replace
  source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
  target_label: __address__
  regex: '(.+?)(?::\d+)?;(\d+)'
  replacement: $1:$2

The second rule could then also be rewritten as follows, close to @discordianfish suggestion:

- action: replace
  target_label: __addess__
  replacement: {{ __meta_kubernetes_pod_ip }}:{{ __meta_kubernetes_pod_container_port_number }}
@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Aug 25, 2017

That's a bit of a different feature again, and you've yet to demonstrate that what you want to do isn't already possible with relabel rules.

I note that the Go regex library does not support what's being requested here.

@discordianfish

This comment has been minimized.

Copy link
Member Author

discordianfish commented Aug 25, 2017

My intention wasn't to support something that isn't possible yet. My goal would be to make Prometheus more accessible by making relabing more readable ultimately reducing support efforts and drive adoption.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Aug 25, 2017

How often does this pattern come up? As I've said I believe replace actions that'd benefit from this are quite rare (e.g. there's none in the k8 example, and that's on the complex side as relabelling goes; nor does it help with the blackbox/snmp pattern).

To add what is basically another templating language to Prometheus, I think we'd want something like this to be very common to balance against the complexity&confusion that an additional language and syntax would cause.

@wjoel

This comment has been minimized.

Copy link

wjoel commented Apr 12, 2018

Being able to do this, and similar things, has been requested over and over again.

- action: keep
  source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_ports] # comma separated list of ports for example
  regex: "(^|,){{ __meta_kubernetes_pod_container_port_number }}($|,)"

Doing this is not possible with just Go regex. The pattern comes up very often.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Apr 12, 2018

@wjoel That is unrelated to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.