Skip to content

Sync up with upstream ES main: apply project ID resolver to ScriptService. #357

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
merged 3 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import co.elastic.logstash.filters.elasticintegration.resolver.ResolverCache;
import co.elastic.logstash.filters.elasticintegration.util.Exceptions;
import co.elastic.logstash.filters.elasticintegration.util.PluginContext;
import co.elastic.logstash.filters.elasticintegration.util.PluginProjectResolver;
import com.google.common.util.concurrent.Service;
import com.google.common.util.concurrent.ServiceManager;
import org.elasticsearch.client.RestClient;
Expand All @@ -33,7 +34,6 @@
import org.elasticsearch.painless.PainlessPlugin;
import org.elasticsearch.painless.PainlessScriptEngine;
import org.elasticsearch.painless.spi.PainlessExtension;
import org.elasticsearch.painless.spi.Whitelist;
import org.elasticsearch.plugins.ExtensiblePlugin;
import org.elasticsearch.plugins.IngestPlugin;
import org.elasticsearch.script.IngestConditionalScript;
Expand Down Expand Up @@ -318,7 +318,13 @@ private static ScriptService initScriptService(final Settings settings, final Th
Map<String, ScriptEngine> engines = new HashMap<>();
engines.put(PainlessScriptEngine.NAME, getPainlessScriptEngine(settings));
engines.put(MustacheScriptEngine.NAME, new MustacheScriptEngine(settings));
return new ScriptService(settings, engines, ScriptModule.CORE_CONTEXTS, threadPool::absoluteTimeInMillis);

return new ScriptService(
settings,
engines,
ScriptModule.CORE_CONTEXTS,
threadPool::absoluteTimeInMillis,
new PluginProjectResolver());
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have to write out own project resolver? Can we use the default? https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/cluster/project/DefaultProjectResolver.java

Seems like our own one is missing some methods and i'm not sure what the implications of returning null will be for a project id.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thus, current better approach looks to me applying default project ID with minimal requirements (similar to DefaultProjectResolver except default methods)

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yep. Lets see what they say on that!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI: In the logstash-bridge module, there is a wrapper for Metadata and we can introduce more if we get to know how PluginProjectResolver should behave. This is for now a minimal change to bring the plugin into a working state.

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package co.elastic.logstash.filters.elasticintegration.util;

import org.elasticsearch.cluster.metadata.ProjectId;
import org.elasticsearch.cluster.project.ProjectResolver;
import org.elasticsearch.core.CheckedRunnable;

public class PluginProjectResolver implements ProjectResolver {
@Override
public ProjectId getProjectId() {
return null;
}

@Override
public <E extends Exception> void executeOnProject(ProjectId projectId, CheckedRunnable<E> checkedRunnable) throws E {
if (projectId.equals(ProjectId.DEFAULT)) {
checkedRunnable.run();
} else {
throw new IllegalArgumentException("Cannot execute on a project other than [" + ProjectId.DEFAULT + "]");
}
}
}