-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Prevent requests that use scripts or now() from being cached #20750
Conversation
This commit changes the strict REST parameters message to say that unconsumed parameters are unrecognized rather than unused. Additionally, the test is beefed up to include two unused parameters. Relates #20745
This commit adds a did you mean feature to the strict REST params error message. This works by comparing any unconsumed parameters to all of the consumer parameters, comparing the Levenstein distance between those parameters, and taking any consumed parameters that are close to an unconsumed parameter as candiates for the did you mean. * Fix pluralization in strict REST params message This commit fixes the pluralization in the strict REST parameters error message so that the word "parameter" is not unconditionally written as "parameters" even when there is only one unrecognized parameter. * Strength strict REST params did you mean test This commit adds an unconsumed parameter that is too far from every consumed parameter to have any candidate suggestions. Relates #20747
Before this change the processing of the ranges in the date range (and other range type) aggregations was done when the Aggregator was created. This meant that the SearchContext did not know that now had been used in a range until after the decision to cache was made. This change moves the processing of the ranges to the aggregation builders so that the search context is made aware that now has been used before it decides if the request should be cached
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.
Looks ok to me (although I'm not that familiar with the aggs parts).
@@ -327,4 +338,75 @@ private ParsedQuery toQuery(QueryBuilder queryBuilder, CheckedFunction<QueryBuil | |||
public final Index index() { | |||
return indexSettings.getIndex(); | |||
} | |||
|
|||
/** | |||
* Compiles (or retrieves from cache) and executes the provided script |
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.
This doesn't actually execute right? It is the binding that happens immediately (vs lazy below is binding to params later).
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.
yeah gotta fix this
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.
fixed
return search(lookup, compiledScript, script.getParams()); | ||
} | ||
|
||
public SearchScript search(SearchLookup lookup, CompiledScript compiledScript, Map<String, Object> params) { |
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.
Can you add some minimal javadocs?
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.
fixed
if (isCachable(firstQuery)) { | ||
assert context.isCachable() : firstQuery.toString(); | ||
} else { | ||
assert context.isCachable() == false : firstQuery.toString(); |
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.
since it's a test case, should it use the junit assertions instead of the assert keyword?
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.
fixed
Prevent requests that use scripts or now() from being cached
Prevent requests that use scripts or now() from being cached
We already have some mechanism in place that prevents requests from being cached in the request cache if they use now(). Yet we don't have any streamlined way to assert that we are not accessing it later. We found some issues in #20645 that relate to stored scripts or scripts that are not pure functions. The immediate fix is to disable caching for these scripts. Unfortunately the script access wasn't streamlined in aggregations nor in query parsing / creation. This change adds a contained API that allows up to make cachabiltily decisions in a single place and causes requests to fail if they access scripts or
now()
after we cache the request.Relates to #20645