Skip to content

painless: register ProcessorsWhitelistExtension to painless engine#162

Merged
yaauie merged 4 commits intoelastic:mainfrom
yaauie:painless-whitelist-proccessors
Sep 23, 2024
Merged

painless: register ProcessorsWhitelistExtension to painless engine#162
yaauie merged 4 commits intoelastic:mainfrom
yaauie:painless-whitelist-proccessors

Conversation

@yaauie
Copy link
Copy Markdown
Member

@yaauie yaauie commented Sep 20, 2024

Enables the use of the org.elasticsearch.ingest.common.Processors in ingest pipelines, as is found in integrations like logs-aws.cloudtrail.

Fixes: #161

Thanks for contributing to Logstash! If you haven't already signed our CLA, here's a handy link: https://www.elastic.co/contributor-agreement/

@yaauie yaauie requested a review from mashhurs September 20, 2024 19:26
@yaauie yaauie added the bug Something isn't working label Sep 20, 2024
}

private static ScriptService initScriptService(final Settings settings, final ThreadPool threadPool) {
final List<Whitelist> painlessBaseWhitelist = getPainlessBaseWhiteList();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review note: by using PainlessPlugin#getScriptEngine(Settings, Set<ScriptContext>) instead of `new PainlessScriptEngine(Settings, Map<ScriptContext<?>, List>), we no longer need to manage the whole whitelists ourselves.

Comment on lines +323 to +349
painlessPlugin.loadExtensions(new ExtensiblePlugin.ExtensionLoader() {
@Override
@SuppressWarnings("unchecked")
public <T> List<T> loadExtensions(Class<T> extensionPointType) {
if (extensionPointType == PainlessExtension.class) {
return List.of((T) new ProcessorsWhitelistExtension());
} else {
return List.of();
}
}
});
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review note: a single-use ExtensiblePlugin.ExtensionLoader is common-place in Elasticsearch core and looks very similar to this.

While we know that PainlessPlugin#loadExtensions(ExtensiblePlugin.ExtensionLoader) will only ever send ExtensiblePlugin.ExtensionLoader#loadExtensions(PainlessExtension.class), we need to accept any class in order to satisfy the interface.

Enables the use of the `org.elasticsearch.ingest.common.Processors` in ingest
pipelines, as is found in integrations like `logs-aws.cloudtrail`.

Fixes: elastic#161
@yaauie yaauie force-pushed the painless-whitelist-proccessors branch from 40841c6 to b288d6a Compare September 20, 2024 22:37
Comment on lines +339 to +342
extensions.add(new ConstantKeywordPainlessExtension()); // module: constant-keyword
extensions.add(new ProcessorsWhitelistExtension()); // module: ingest-common
extensions.add(new SpatialPainlessExtension()); // module: spatial
extensions.add(new WildcardPainlessExtension()); // module: wildcard
Copy link
Copy Markdown
Member Author

@yaauie yaauie Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mashhurs you brought up on a separate channel that we should audit to see what other painless extensions need to be registered, so I went through all of the implementations of PainlessExtension in ES source to find those that worked with either the IngestScript.CONTEXT or IngestConditionalScript.CONTEXT (and would thus be useful to our ScriptEngine instance that only supports those two contexts):

PainlessExtension Script Context Source
AggregationsPainlessExtension ❌context-miss --
AnalysisPainlessExtension ❌context-miss --
ConstantKeywordPainlessExtension ✅context-match ✅constant-keyword
DocValuesWhitelistExtension ❌context-miss --
EqlPainlessExtension ❌context-miss --
MachineLearningPainlessExtension ❌context-miss --
Murmur3PainlessExtension ✅context-match ❌not included
ProcessorsWhitelistExtension ✅context-match ✅ingest-common
RuntimeFieldsPainlessExtension ❌context-miss --
SpatialPainlessExtension ✅context-match ✅spatial
SqlPainlessExtension ❌context-miss --
VersionFieldDocValuesExtension ❌context-miss --
WatcherPainlessExtension ❌context-miss --
WildcardPainlessExtension ✅context-match ✅wildcard

The murmur3 painless plugin would work, but from what I can tell it isn't included in the ES default distribution.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yaauie for the details, makes sense.

…telist-proccessors

Add an integration test for the painless script which points to Ingest Processors.
Copy link
Copy Markdown
Collaborator

@mashhurs mashhurs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Side notes:

Comment on lines +339 to +342
extensions.add(new ConstantKeywordPainlessExtension()); // module: constant-keyword
extensions.add(new ProcessorsWhitelistExtension()); // module: ingest-common
extensions.add(new SpatialPainlessExtension()); // module: spatial
extensions.add(new WildcardPainlessExtension()); // module: wildcard
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yaauie for the details, makes sense.

@elasticmachine
Copy link
Copy Markdown
Collaborator

elasticmachine commented Sep 21, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working int-shortlist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: pipelines with painless scripts referencing org.elasticsearch.ingest.common.Processors fail to compile

4 participants