-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Opt date valued script fields out of rate limit (#61238)
This excuses script fields from the script compilation rate limiting. It'd be fairly sad to prevent mapping updates because of the rate limit. And we don't expect folks to add a zillion fields. On the other hand, once we allow these scripts on the `_search` request we might indeed want them to be considered in the limit. But we don't support that yet and we can deal with that when we get there.
- Loading branch information
Showing
6 changed files
with
120 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ields/src/test/java/org/elasticsearch/xpack/runtimefields/DateScriptFieldScriptTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.runtimefields; | ||
|
||
import org.elasticsearch.script.Script; | ||
import org.elasticsearch.script.ScriptService; | ||
import org.elasticsearch.script.ScriptType; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class DateScriptFieldScriptTests extends ESTestCase { | ||
public static final DateScriptFieldScript.Factory DUMMY = (params, lookup, formatter) -> ctx -> new DateScriptFieldScript( | ||
params, | ||
lookup, | ||
formatter, | ||
ctx | ||
) { | ||
@Override | ||
public void execute() { | ||
new DateScriptFieldScript.Millis(this).millis(1595431354874L); | ||
} | ||
}; | ||
|
||
public void testRateLimitingDisabled() throws IOException { | ||
try (ScriptService scriptService = TestScriptEngine.scriptService(DateScriptFieldScript.CONTEXT, DUMMY)) { | ||
for (int i = 0; i < 1000; i++) { | ||
scriptService.compile(new Script(ScriptType.INLINE, "test", "test_" + i, Map.of()), DateScriptFieldScript.CONTEXT); | ||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/TestScriptEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.runtimefields; | ||
|
||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.script.ScriptContext; | ||
import org.elasticsearch.script.ScriptEngine; | ||
import org.elasticsearch.script.ScriptService; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public abstract class TestScriptEngine implements ScriptEngine { | ||
public static <F> ScriptService scriptService(ScriptContext<F> context, F factory) { | ||
return new ScriptService(Settings.EMPTY, Map.of("test", new TestScriptEngine() { | ||
@Override | ||
protected Object buildScriptFactory(ScriptContext<?> context) { | ||
return factory; | ||
} | ||
|
||
@Override | ||
public Set<ScriptContext<?>> getSupportedContexts() { | ||
return Set.of(context); | ||
} | ||
}), Map.of(context.name, context)); | ||
} | ||
|
||
@Override | ||
public final String getType() { | ||
return "test"; | ||
} | ||
|
||
@Override | ||
public final <FactoryType> FactoryType compile( | ||
String name, | ||
String code, | ||
ScriptContext<FactoryType> context, | ||
Map<String, String> params | ||
) { | ||
@SuppressWarnings("unchecked") | ||
FactoryType castFactory = (FactoryType) buildScriptFactory(context); | ||
return castFactory; | ||
} | ||
|
||
protected abstract Object buildScriptFactory(ScriptContext<?> context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters