From b23abfa781413cd764d5083f1fa593766b8a82d7 Mon Sep 17 00:00:00 2001 From: Stuart Tettemer Date: Tue, 2 Mar 2021 16:08:54 -0600 Subject: [PATCH 1/2] 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 --- .../elasticsearch/script/mustache/MustacheScriptEngine.java | 2 +- .../src/main/java/org/elasticsearch/ingest/ValueSource.java | 2 +- .../main/java/org/elasticsearch/script/ScriptModule.java | 1 + .../main/java/org/elasticsearch/script/TemplateScript.java | 6 ++++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java index 202e16c2415a9..659d385ec2b47 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java @@ -75,7 +75,7 @@ public T compile( @Override public Set> getSupportedContexts() { - return Set.of(TemplateScript.CONTEXT); + return Set.of(TemplateScript.CONTEXT, TemplateScript.INGEST_CONTEXT); } private CustomMustacheFactory createMustacheFactory(Map options) { diff --git a/server/src/main/java/org/elasticsearch/ingest/ValueSource.java b/server/src/main/java/org/elasticsearch/ingest/ValueSource.java index be02fde2431ca..2272c3d4136a9 100644 --- a/server/src/main/java/org/elasticsearch/ingest/ValueSource.java +++ b/server/src/main/java/org/elasticsearch/ingest/ValueSource.java @@ -69,7 +69,7 @@ static ValueSource wrap(Object value, ScriptService scriptService, Map CONTEXT = new ScriptContext<>("template", Factory.class); + + // Remove compilation rate limit for ingest + public static final ScriptContext INGEST_CONTEXT = new ScriptContext<>("ingest_template", Factory.class, + 200, TimeValue.timeValueMillis(0), ScriptCache.UNLIMITED_COMPILATION_RATE.asTuple()); } From ad956d0277e0ccd64ad38472d3e887338eb7e993 Mon Sep 17 00:00:00 2001 From: Stuart Tettemer Date: Wed, 3 Mar 2021 14:01:36 -0600 Subject: [PATCH 2/2] Scripting: expand INGEST_CONTEXT comment --- .../main/java/org/elasticsearch/script/TemplateScript.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/script/TemplateScript.java b/server/src/main/java/org/elasticsearch/script/TemplateScript.java index 756d8cf8238d2..6738df2536689 100644 --- a/server/src/main/java/org/elasticsearch/script/TemplateScript.java +++ b/server/src/main/java/org/elasticsearch/script/TemplateScript.java @@ -38,7 +38,9 @@ public interface Factory { public static final ScriptContext CONTEXT = new ScriptContext<>("template", Factory.class); - // Remove compilation rate limit for ingest + // 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 INGEST_CONTEXT = new ScriptContext<>("ingest_template", Factory.class, 200, TimeValue.timeValueMillis(0), ScriptCache.UNLIMITED_COMPILATION_RATE.asTuple()); }