-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
Scripted metric aggregations: add deprecation warning and system property to control legacy params #31597
Scripted metric aggregations: add deprecation warning and system property to control legacy params #31597
Changes from 4 commits
b9111d0
c7a6ad1
bc86682
e49f8f7
7fd0484
8185ac3
9f0b28b
bf13bf4
9681738
da54990
20ac8d8
3ea60ee
aa2e066
6009712
30ff793
22f74ed
087c005
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ The object used to share aggregation state between the scripts in a Scripted Met | |
Aggregation is now a variable called `state` available in the script context, rather than | ||
being provided via the `params` object as `params._agg`. | ||
|
||
The old `params._agg` variable is still available as well. | ||
The old `params._agg` variable is still available as well. This can be disabled by setting | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this will be backported to 6.x, with the intention of removing in 7.0, I don't think this migration note makes sense. The migration note would be that params._agg is gone, and would be in the followup which removes support in master only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks. I overthought this and was going to remove it in my followup, but you're right; there's no need for this note here now that the target version is more solid. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll revert the doc change such that this file is left as-is until the next PR. |
||
the `es.aggregations.enableDeprecatedScriptedMetricAggParam` system property to `false`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
import org.apache.lucene.index.LeafReaderContext; | ||
import org.apache.lucene.search.Scorer; | ||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.common.logging.DeprecationLogger; | ||
import org.elasticsearch.common.logging.Loggers; | ||
import org.elasticsearch.index.fielddata.ScriptDocValues; | ||
import org.elasticsearch.search.lookup.LeafSearchLookup; | ||
import org.elasticsearch.search.lookup.SearchLookup; | ||
|
@@ -31,6 +33,25 @@ | |
import java.util.Map; | ||
|
||
public class ScriptedMetricAggContexts { | ||
private static final DeprecationLogger DEPRECATION_LOGGER = | ||
new DeprecationLogger(Loggers.getLogger(ScriptedMetricAggContexts.class)); | ||
|
||
// Public for access from tests | ||
public static final String AGG_PARAM_DEPRECATION_WARNING = | ||
"params._agg/_aggs for scripted metric aggregations are deprecated, use state/states (not in params) instead. " + | ||
"Set system property es.aggregations.enableDeprecatedScriptedMetricAggParam = false to disable this deprecated behavior."; | ||
|
||
public static boolean deprecatedAggParamEnabled() { | ||
boolean enabled = Boolean.parseBoolean( | ||
System.getProperty("es.aggregations.enableDeprecatedScriptedMetricAggParam", "true")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be named with underscores. I think the name doesn't need the "deprecated" in it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So |
||
|
||
if (enabled) { | ||
DEPRECATION_LOGGER.deprecatedAndMaybeLog("enableDeprecatedScriptedMetricAggParams", AGG_PARAM_DEPRECATION_WARNING); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately I've lead you in an incorrect direction. After discussing with others, we want these to only be triggered when the deprecated behavior is used. See #31441 for and example doing this in ScriptDocValues for an idea of what must be done within the aggs code (although I think it will be simpler here, since you can do this check and deprecation outside of script invocation, and thus no need for a doPriv block). |
||
} | ||
|
||
return enabled; | ||
} | ||
|
||
private abstract static class ParamsAndStateBase { | ||
private final Map<String, Object> params; | ||
private final Object state; | ||
|
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.
sorry for not seeing this earlier: I think we should make the test cluster set the system property so the deprecated behaviour is not used?
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.
Yes it should be set to the new behavior in all tests, and a specific test added for the bwc behavior. See https://github.com/elastic/elasticsearch/pull/30975/files#diff-407c748a710cb1e33230c1fd06da7f16R694 for how it was done recently for another bwc change (although adding the sysprop in BuildPlugin should really have a comment indicating the purpose and when it can be removed).
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.
Excellent -- thanks for the feedback. I already have a commit in another branch updating the various tests to use the new context variables (PR to follow this one) so I can bring over those changes and add another dedicated test class for the old behavior similar to
ScriptDocValuesMissingV6BehaviourTests
from that example.I should be able to get back to this some evening this week. In the meantime to make sure we're on the same page, please let me know if this is different from what you had in mind:
enableDeprecatedScriptedMetricAggParam
to false centrally in BuildPlugin.groovy. With a comment that this gets remove presumably in 7.0.Some of the test changes are substantial (ScriptedMetricIT specifically) so heads up this review will get bigger.