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

enhancement(remap): add match_any function #7414

Merged
merged 4 commits into from
May 28, 2021
Merged

enhancement(remap): add match_any function #7414

merged 4 commits into from
May 28, 2021

Conversation

lukesteensen
Copy link
Member

@lukesteensen lukesteensen commented May 11, 2021

This is currently built on top of #7250 to take advantage of some of @jszwedko additions there. It's also not documented and has one unwrap that needs removed, but I'm opening it in this state to get some feedback since it's my first real work with VRL.

The goal here is to optimize the case of checking against multiple regexes. Instead of match(.foo, ...) || match(.foo, ...) || ..., you can simply pass an array of patterns that are compiled to a RegexSet and checked efficiently in one pass. This is also more ergonomic than asking users to combine patterns manually.

@lukesteensen lukesteensen marked this pull request as ready for review May 19, 2021 23:05
@lukesteensen lukesteensen requested a review from a team May 19, 2021 23:05
Parameter {
keyword: "patterns",
kind: kind::ARRAY,
required: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this not be required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! It should definitely be required. Seems like this was somehow fixed when rebasing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, I was looking at somewhere else. Will push a fix now.

Copy link
Contributor

@StephenWakely StephenWakely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, apart from I suspect the patterns parameter should be required.

It's a shame we have to convert the regexes to strings and back again, but I can't see another way around that. It is only at boot time, so not critical.

Base automatically changed from reimplement-redact to master May 27, 2021 14:06
Signed-off-by: Luke Steensen <luke.steensen@gmail.com>
Signed-off-by: Luke Steensen <luke.steensen@gmail.com>
Signed-off-by: Luke Steensen <luke.steensen@gmail.com>
Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! I might add a note to the docs that using this is faster if you have multiple regexes to check than using match multiple times.

@binarylogic
Copy link
Contributor

I wonder if we should add a follow up issues to convert successive match calls to match_any as part of compilation?

Signed-off-by: Luke Steensen <luke.steensen@gmail.com>
@lukesteensen
Copy link
Member Author

I wonder if we should add a follow up issues to convert successive match calls to match_any as part of compilation?

This was something I looked into first, but it seemed pretty non-trivial. I'll at least open an issue around adding that kind of optimization pass to the VRL compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants