Script: Opt-out system contexts from script compilation rate limit#79459
Script: Opt-out system contexts from script compilation rate limit#79459stu-elastic merged 3 commits intoelastic:7.xfrom
Conversation
Restore the scripting general cache in preparation for deprecation of the context cache, then removal of the context cache in master. Brings back the general cache settings: * `script.max_compilations_rate` * `script.cache.expire` * `script.cache.max_size` `script.cache.max_size` and `script.cache.expire` are now dynamic settings. The context cache is still default, the switch to general cache as default will happen on context cache deprecation. System script contexts can now opt-out of compilation rate limiting using a flag rather than a sentinel rate limit value. Duplicated defaults for system contexts have been coalesced. Other than that, this code is the same as what was in 7.x to make a `master`-first commit and backport strategy easy. Refs: elastic#62899 Backport: elastic#79414
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
rjernst
left a comment
There was a problem hiding this comment.
It seems like all but runtime fields have the flag backwards, it should be false to not use rate limited, right?
| /** The context used to compile {@link IngestConditionalScript} factories. */ | ||
| public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>("processor_conditional", Factory.class, | ||
| 200, TimeValue.timeValueMillis(0), ScriptCache.UNLIMITED_COMPILATION_RATE.asTuple(), true); | ||
| public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>("processor_conditional", Factory.class, true); |
There was a problem hiding this comment.
Shouldn't this be false to maintain not using compilation limits?
There was a problem hiding this comment.
That's the flag for stored, there is no flag for not using compilation limits in that constructor.
There was a problem hiding this comment.
Switched to full constructor, value is explicitly false.
| /** The context used to compile {@link IngestScript} factories. */ | ||
| public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>("ingest", Factory.class, | ||
| 200, TimeValue.timeValueMillis(0), ScriptCache.UNLIMITED_COMPILATION_RATE.asTuple(), true); | ||
| public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>("ingest", Factory.class, true); |
There was a problem hiding this comment.
Shouldn't this be false to maintain not using compilation limits?
There was a problem hiding this comment.
It's calling the following constructor and allowing stored scripts.
public ScriptContext(String name, Class<FactoryType> factoryClazz, boolean allowStoredScript) {
this(name, factoryClazz, 200, TimeValue.timeValueMillis(0), false, allowStoredScript);
}
}
public ScriptContext(String name, Class<FactoryType> factoryClazz, int cacheSizeDefault, TimeValue cacheExpireDefault,
ScriptContext(String name, Class<FactoryType> factoryClazz, int cacheSizeDefault, TimeValue cacheExpireDefault,
Tuple<Integer, TimeValue> maxCompilationRateDefault, boolean allowStoredScript) {
boolean compilationRateLimited, boolean allowStoredScript)
There was a problem hiding this comment.
Switched to full constructor, value is explicitly false.
| builder.field(Fields.COMPILATIONS, compilations); | ||
| builder.field(Fields.CACHE_EVICTIONS, cacheEvictions); | ||
| builder.field(Fields.COMPILATION_LIMIT_TRIGGERED, compilationLimitTriggered); | ||
| /* TODO(stu): master only |
| // creating a new Script class (as would be customary), this context is used to avoid the default rate limit. | ||
| public static final ScriptContext<Factory> INGEST_CONTEXT = new ScriptContext<>("ingest_template", Factory.class, | ||
| 200, TimeValue.timeValueMillis(0), ScriptCache.UNLIMITED_COMPILATION_RATE.asTuple(), true); | ||
| public static final ScriptContext<Factory> INGEST_CONTEXT = new ScriptContext<>("ingest_template", Factory.class, true); |
There was a problem hiding this comment.
Shouldn't this be false to maintain not using compilation limits?
There was a problem hiding this comment.
That's for allowing it to be stored.
There was a problem hiding this comment.
Switched to full constructor, value is explicitly false.
| stats.toXContent(builder, ToXContent.EMPTY_PARAMS); | ||
| builder.endObject(); | ||
|
|
||
| /* TODO(stu): master only |
| public static final ScriptContext<TemplateScript.Factory> SCRIPT_TEMPLATE_CONTEXT | ||
| = new ScriptContext<>("xpack_template", TemplateScript.Factory.class, | ||
| 200, TimeValue.timeValueMillis(0), ScriptCache.UNLIMITED_COMPILATION_RATE.asTuple(), true); | ||
| = new ScriptContext<>("xpack_template", TemplateScript.Factory.class, true); |
There was a problem hiding this comment.
Shouldn't this be false to maintain not using compilation limits?
There was a problem hiding this comment.
That's for allowing it to be stored.
There was a problem hiding this comment.
Switched to full constructor, value is explicitly false.
|
|
||
| public static ScriptContext<Factory> CONTEXT = new ScriptContext<>("watcher_condition", Factory.class, | ||
| 200, TimeValue.timeValueMillis(0), ScriptCache.UNLIMITED_COMPILATION_RATE.asTuple(), true); | ||
| public static ScriptContext<Factory> CONTEXT = new ScriptContext<>("watcher_condition", Factory.class, true); |
There was a problem hiding this comment.
Shouldn't this be false to maintain not using compilation limits?
There was a problem hiding this comment.
That's for allowing it to be stored.
There was a problem hiding this comment.
Switched to full constructor, value is explicitly false.
|
|
||
| public static ScriptContext<Factory> CONTEXT = new ScriptContext<>("watcher_transform", Factory.class, | ||
| 200, TimeValue.timeValueMillis(0), ScriptCache.UNLIMITED_COMPILATION_RATE.asTuple(), true); | ||
| public static ScriptContext<Factory> CONTEXT = new ScriptContext<>("watcher_transform", Factory.class, true); |
There was a problem hiding this comment.
Shouldn't this be false to maintain not using compilation limits?
There was a problem hiding this comment.
That's for allowing it to be stored.
There was a problem hiding this comment.
Switched to full constructor, value is explicitly false.
| * - default cache expiration: no expiration | ||
| * - unlimited compilation rate | ||
| */ | ||
| public ScriptContext(String name, Class<FactoryType> factoryClazz, boolean allowStoredScript) { |
There was a problem hiding this comment.
I don't think we need another constructor? Let's just update the few places you already have modified in this PR to be explicit about the settings for each context.
There was a problem hiding this comment.
I added this constructor to avoid having two boolean flags in a row, which (despite intellij) is a bit hard to read.
Will update.
Deprecate the script context cache in favor of the general cache. Users should use the following settings: `script.max_compilations_rate` to set the max compilation rate for user scripts such as filter scripts. Certain script contexts that submit scripts outside of the control of the user are exempted from this rate limit. Examples include runtime fields, ingest and watcher. `script.cache.max_size` to set the max size of the cache. `script.cache.expire` to set the expiration time for entries in the cache. Whats deprecated? `script.max_compilations_rate: use-context`. This special setting value was used to turn on the script context-specific caches. `script.context.$CONTEXT.cache_max_size`, use `script.cache.max_size` instead. `script.context.$CONTEXT.cache_expire`, use `script.cache.expire` instead. `script.context.$CONTEXT.max_compilations_rate`, use `script.max_compilations_rate` instead. The default cache size was increased from `100` to `3000`, which was approximately the max cache size when using context-specific caches. The default compilation rate limit was increased from `75/5m` to `150/5m` to account for increasing uses of scripts. System script contexts can now opt-out of compilation rate limiting using a flag rather than a sentinel rate limit value. 7.16: Script: Deprecate script context cache elastic#79508 Refs: elastic#62899 7.16: Script: Opt-out system contexts from script compilation rate limit elastic#79459 Refs: elastic#62899
Deprecate the script context cache in favor of the general cache. Users should use the following settings: `script.max_compilations_rate` to set the max compilation rate for user scripts such as filter scripts. Certain script contexts that submit scripts outside of the control of the user are exempted from this rate limit. Examples include runtime fields, ingest and watcher. `script.cache.max_size` to set the max size of the cache. `script.cache.expire` to set the expiration time for entries in the cache. Whats deprecated? `script.max_compilations_rate: use-context`. This special setting value was used to turn on the script context-specific caches. `script.context.$CONTEXT.cache_max_size`, use `script.cache.max_size` instead. `script.context.$CONTEXT.cache_expire`, use `script.cache.expire` instead. `script.context.$CONTEXT.max_compilations_rate`, use `script.max_compilations_rate` instead. The default cache size was increased from `100` to `3000`, which was approximately the max cache size when using context-specific caches. The default compilation rate limit was increased from `75/5m` to `150/5m` to account for increasing uses of scripts. System script contexts can now opt-out of compilation rate limiting using a flag rather than a sentinel rate limit value. 7.16: Script: Deprecate script context cache elastic#79508 Refs: elastic#62899 7.16: Script: Opt-out system contexts from script compilation rate limit elastic#79459 Refs: elastic#62899
Deprecate the script context cache in favor of the general cache. Users should use the following settings: `script.max_compilations_rate` to set the max compilation rate for user scripts such as filter scripts. Certain script contexts that submit scripts outside of the control of the user are exempted from this rate limit. Examples include runtime fields, ingest and watcher. `script.cache.max_size` to set the max size of the cache. `script.cache.expire` to set the expiration time for entries in the cache. Whats deprecated? `script.max_compilations_rate: use-context`. This special setting value was used to turn on the script context-specific caches. `script.context.$CONTEXT.cache_max_size`, use `script.cache.max_size` instead. `script.context.$CONTEXT.cache_expire`, use `script.cache.expire` instead. `script.context.$CONTEXT.max_compilations_rate`, use `script.max_compilations_rate` instead. The default cache size was increased from `100` to `3000`, which was approximately the max cache size when using context-specific caches. The default compilation rate limit was increased from `75/5m` to `150/5m` to account for increasing uses of scripts. System script contexts can now opt-out of compilation rate limiting using a flag rather than a sentinel rate limit value. 7.16: Script: Deprecate script context cache #79508 Refs: #62899 7.16: Script: Opt-out system contexts from script compilation rate limit #79459 Refs: #62899
System script contexts can now opt-out of compilation rate limiting using a flag rather than a sentinel rate limit value.
Duplicated defaults for system contexts have been coalesced.
Refs: #62899