-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Opt date valued script fields out of rate limit #61238
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
Merged
nik9000
merged 2 commits into
elastic:feature/runtime_fields
from
nik9000:script_fields_rate_limit
Aug 18, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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've only done this to a single script field. If we like it I'd be happy to do it in a follow up.