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

Non-greedy regex in relabel_configs fails #1520

Closed
pete0emerson opened this Issue Apr 1, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@pete0emerson
Copy link

pete0emerson commented Apr 1, 2016

Suppose __meta_consul_tags value is ,environment:stage,application:webapp,.

With a config of:

    - source_labels: ['__meta_consul_tags']
      regex:         ',environment:(.*),'
      target_label:  'environment'
      replacement:   '$1'

I get: environment="stage,application:webapp".

That makes sense, because my regular expression is greedy and blowing past the first comma.

If I change it to be non-greedy:

    - source_labels: ['__meta_consul_tags']
      regex:         ',environment:(.*?),'
      target_label:  'environment'
      replacement:   '$1'

The results are unchanged: environment="stage,application:webapp".

Interestingly enough, if I change my regex to:

    - source_labels: ['__meta_consul_tags']
      regex:         ',environment:([a-z]*),'
      target_label:  'environment'
      replacement:   '$1'

The results come back empty, i.e. no new labels are created.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Apr 1, 2016

This is a consequence of the regex being anchored and you not having (.*) on either end.

@pete0emerson

This comment has been minimized.

Copy link
Author

pete0emerson commented Apr 1, 2016

Ah, anchoring on both ends, yes, got it. (ref #1519 #1518)

Worth better documentation.

@grobie

This comment has been minimized.

Copy link
Member

grobie commented Apr 2, 2016

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 24, 2019

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