mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-07-06 05:43:52 -04:00
Script: no compile rate limit for ingest templates (#69841)
* Script: no compile rate limit for ingest templates Remove the compilation rate limit for ingest templates. Creates a new context, `ingest_template`, with an unlimited compilation rate limit. The `template` context is used in many places so it cannot be exempted from rate limits. Fixes: #64595
This commit is contained in:
parent
e432934e82
commit
9370b1c006
4 changed files with 11 additions and 2 deletions
|
@ -75,7 +75,7 @@ public final class MustacheScriptEngine implements ScriptEngine {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ScriptContext<?>> getSupportedContexts() {
|
public Set<ScriptContext<?>> getSupportedContexts() {
|
||||||
return Set.of(TemplateScript.CONTEXT);
|
return Set.of(TemplateScript.CONTEXT, TemplateScript.INGEST_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CustomMustacheFactory createMustacheFactory(Map<String, String> options) {
|
private CustomMustacheFactory createMustacheFactory(Map<String, String> options) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ public interface ValueSource {
|
||||||
// modified if templating is not available
|
// modified if templating is not available
|
||||||
if (scriptService.isLangSupported(DEFAULT_TEMPLATE_LANG) && ((String) value).contains("{{")) {
|
if (scriptService.isLangSupported(DEFAULT_TEMPLATE_LANG) && ((String) value).contains("{{")) {
|
||||||
Script script = new Script(ScriptType.INLINE, DEFAULT_TEMPLATE_LANG, (String) value, scriptOptions, Map.of());
|
Script script = new Script(ScriptType.INLINE, DEFAULT_TEMPLATE_LANG, (String) value, scriptOptions, Map.of());
|
||||||
return new TemplatedValue(scriptService.compile(script, TemplateScript.CONTEXT));
|
return new TemplatedValue(scriptService.compile(script, TemplateScript.INGEST_CONTEXT));
|
||||||
} else {
|
} else {
|
||||||
return new ObjectValue(value);
|
return new ObjectValue(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class ScriptModule {
|
||||||
SimilarityScript.CONTEXT,
|
SimilarityScript.CONTEXT,
|
||||||
SimilarityWeightScript.CONTEXT,
|
SimilarityWeightScript.CONTEXT,
|
||||||
TemplateScript.CONTEXT,
|
TemplateScript.CONTEXT,
|
||||||
|
TemplateScript.INGEST_CONTEXT,
|
||||||
MovingFunctionScript.CONTEXT,
|
MovingFunctionScript.CONTEXT,
|
||||||
ScriptedMetricAggContexts.InitScript.CONTEXT,
|
ScriptedMetricAggContexts.InitScript.CONTEXT,
|
||||||
ScriptedMetricAggContexts.MapScript.CONTEXT,
|
ScriptedMetricAggContexts.MapScript.CONTEXT,
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
package org.elasticsearch.script;
|
package org.elasticsearch.script;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,4 +37,10 @@ public abstract class TemplateScript {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>("template", Factory.class);
|
public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>("template", Factory.class);
|
||||||
|
|
||||||
|
// Remove compilation rate limit for ingest. Ingest pipelines may use many mustache templates, triggering compilation
|
||||||
|
// rate limiting. MustacheScriptEngine explicitly checks for TemplateScript. Rather than complicating the implementation there by
|
||||||
|
// 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());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue