-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Security: improve exact index matching performance #36017
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
Conversation
This commit improves the efficiency of exact index name matching by separating exact matches from those that include wildcards or regular expressions. Internally, exact matching is done using a HashSet instead of adding the exact matches to the automata. For the wildcard and regular expression matches, the underlying implementation has not changed.
Pinging @elastic/es-security |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Set<String> exactMatch = new HashSet<>(); | ||
List<String> nonExactMatch = new ArrayList<>(); | ||
for (String indexPattern : indices) { | ||
if (indexPattern.startsWith("/")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing Automatons
code throws an exception if a pattern starts with /
but doesn't end with /
.
So we could simplify all this checking down to a single if/else and still be compatible with existing behaviour.
if (indexPattern.startsWith("/") || indexPattern.contains("*") || indexPattern.contains("?")) {
nonExactMatch.add(indexPattern);
} else {
exactMatch.add(indexPattern);
}
I don't care strongly, but shorter and simpler seems nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ thanks for noticing that. I misread the if statement in Automatons
I think as a follow up, when we have more time, we should:
|
This commit improves the efficiency of exact index name matching by separating exact matches from those that include wildcards or regular expressions. Internally, exact matching is done using a HashSet instead of adding the exact matches to the automata. For the wildcard and regular expression matches, the underlying implementation has not changed.
This commit improves the efficiency of exact index name matching by
separating exact matches from those that include wildcards or regular
expressions. Internally, exact matching is done using a HashSet instead
of adding the exact matches to the automata. For the wildcard and
regular expression matches, the underlying implementation has not
changed.