-
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 2 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,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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,10 +83,17 @@ public Aggregator createInternal(Aggregator parent, boolean collectsFromSingleBu | |
// Add _agg to params map for backwards compatibility (redundant with context variables on the scripts created below). | ||
// When this is removed, aggState (as passed to ScriptedMetricAggregator) can be changed to Map<String, Object>, since | ||
// it won't be possible to completely replace it with another type as is possible when it's an entry in params. | ||
if (aggParams.containsKey("_agg") == false) { | ||
aggParams.put("_agg", new HashMap<String, Object>()); | ||
Object aggState = new HashMap<String, Object>(); | ||
if (ScriptedMetricAggContexts.deprecatedAggParamEnabled()) { | ||
if (!aggParams.containsKey("_agg")) { | ||
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. nit: we tend to prefer |
||
// Add _agg if it wasn't added manually | ||
aggParams.put("_agg", aggState); | ||
} else { | ||
// If it was added manually, also use it for the agg context variable to reduce the likelihood of | ||
// weird behavior due to multiple different variables. | ||
aggState = aggParams.get("_agg"); | ||
} | ||
} | ||
Object aggState = aggParams.get("_agg"); | ||
|
||
final ScriptedMetricAggContexts.InitScript initScript = this.initScript.newInstance( | ||
mergeParams(aggParams, initScriptParams), aggState); | ||
|
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 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 comment
The 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 comment
The 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.