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 exclusions (negative matches) #536

Closed
siyigao121212 opened this issue Jan 30, 2024 · 5 comments
Closed

Support exclusions (negative matches) #536

siyigao121212 opened this issue Jan 30, 2024 · 5 comments
Labels
enhancement help wanted PRs for this issue are especially welcome

Comments

@siyigao121212
Copy link

I have two mapping rules, one is global mapping rule, another is regex mapping rule

- match: "a.*.*"
  name: "a_$2"
  labels:
    testname: "$1"
- match: "a\\.(.*)\\.c_([0-9]{3})"
  match_type: regex
  name: "a_c"
  labels:
    testname: "$1"
    testcount: "$2"

now I have a stats, a.b.c_100, what I want is a_c{testname:b, test_count:100}, but I got a_c_100{testname:b}, it's because the global rules executed before the regex rules, how could I give priority to the regex one. I tried with change the order, but it didn't work. Another question is could we add exclusion for the global mapping rules? Then we could exclude the particular rule from the global mapping rules. Thanks.

@matthiasr
Copy link
Contributor

This isn't immediately helpful to you, but to record the relation – prefix glob matches #481 would also solve this particular situation, by removing the need to use regex matches at all.

I'm not sure about allowing to swap the evaluation order – it's this way, because glob matches are significantly faster; but if the performance of regex matching is sufficient for you, you can use regexes for both rules.

As for exclusions, I can see that this would be useful. I'll change the title of this issue to make it about that (since we already have one for prefix matches, and I don't want to make the priority configurable). If anyone wants it enough to contribute that, please do 😄

@matthiasr matthiasr changed the title How to give priority to regex mapping rules Support exclusions (negative matches) Mar 3, 2024
@matthiasr matthiasr added enhancement help wanted PRs for this issue are especially welcome labels Mar 3, 2024
@matthiasr
Copy link
Contributor

As a word of caution, the glob matching is a very hot code path and needs to stay efficient. We need to find a way to handle this as part of the state machine for glob matching somehow. Please include benchmarks 😄

@matthiasr
Copy link
Contributor

I suspect if someone needs one exclusion, they are also likely to need multiple, like

- match: a.*.*
  exclude:
  - a.*.b
  - a.*.c

@matthiasr
Copy link
Contributor

On second thought, I think prefix matches are the solution here, and would be required to make the exclusion work in your case. Additionally, now that I think about it, a more specific glob match works as an exclusion, so the example above would be handled already by

- match: a.*.*
  
- match: a.*.b
  
- match: a.*.c
  

To make your example work, you would need

- match: a.*.*
  
- match: a.*.c_*
  

which is what #481 is about.

@matthiasr matthiasr closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2024
@siyigao121212
Copy link
Author

siyigao121212 commented Mar 25, 2024

Thanks @matthiasr for the response. I tried with a.*.c_* but it says as below. My statsd version is v0.24.0.

msg="error loading config" error="invalid match: a.*.c_*"

So we need to wait for the prefix matches feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted PRs for this issue are especially welcome
Projects
None yet
Development

No branches or pull requests

2 participants