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

Regexes are silently anchored #1519

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

Comments

Projects
None yet
4 participants
@pete0emerson
Copy link

pete0emerson commented Apr 1, 2016

I'm seeing this in version 0.17.0.

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

In relabel_configs:

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

I would expect this to succeed. However, it fails, and my suspicion is that the regular expressions are anchored silently, because this succeeds:

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

If my assumption is correct, my suggestion would be that anchoring be not silently added, so if I truly wanted to anchor it, I'd use the regex anchor ^ to anchor it to the beginning of the string.

@juliusv

This comment has been minimized.

Copy link
Member

juliusv commented Apr 1, 2016

This behavior has been changed intentionally in 0.17.0 to the one you are seeing because wanting anchored regexes was seen as the more frequently desired use case.

See also: #1518 and the linked changelog entry.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Apr 1, 2016

This was a change we made on purpose, as not everyone is fully aware of how regexes work and we'd seen a lot of patterns in use that could unintentionally overmatch (consul tags being a common one).

@pete0emerson

This comment has been minimized.

Copy link
Author

pete0emerson commented Apr 1, 2016

That makes sense. I'd suggest that it's worth documenting well in the relabel_configs section to make that clear to the people who are more proficient at regular expressions. If you'd like me to submit a patch, I would be glad to create one.

@grobie

This comment has been minimized.

Copy link
Member

grobie commented Apr 1, 2016

@juliusv

This comment has been minimized.

Copy link
Member

juliusv commented Apr 1, 2016

It'd make sense to briefly mention it in the code block comment above the regex field too.

@grobie

This comment has been minimized.

Copy link
Member

grobie commented Apr 2, 2016

@grobie grobie closed this 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.