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

Conversation

mashhurs
Copy link
Collaborator

@mashhurs mashhurs commented Aug 5, 2025

Sync up with upstream ES main: apply project ID resolver applied in logstash-bridge ScriptServiceBridge.

Applying as introduced in the logstash-bridge ScriptServiceBridge: https://github.com/elastic/elasticsearch/pull/130578/files#diff-f74baacde87eae5c09e26daf35f888065d68238e2593160179fb937c11d11327R73

Soon, this plugin will start using logstash-bridge instead direct ScriptService usage. See the observations that applying null breaks the plugin, so we may need to apply a logic to provide an actual project resolver.

Copy link

mergify bot commented Aug 5, 2025

This pull request does not have a backport label. Could you fix it @mashhurs? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit.
  • If no backport is necessary, please add the backport-skip label

@mashhurs mashhurs added the backport-skip Skip automated backport with mergify label Aug 5, 2025
@@ -318,7 +318,7 @@ 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, null);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Oh, ha i just read the PR description 😅 :

Applying as introduced in the logstash-bridge ScriptServiceBridge: https://github.com/elastic/elasticsearch/pull/130578/files#diff-f74baacde87eae5c09e26daf35f888065d68238e2593160179fb937c11d11327R73

Copy link
Member

Choose a reason for hiding this comment

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

3 PDT logstash-1 | org.elasticsearch.ElasticsearchException: java.lang.NullPointerException: Cannot invoke "org.elasticsearch.cluster.project.ProjectResolver.getProjectId()" because "this.projectResolver" is null

Hmm maybe that wont work

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, but it seems our case is non-null tolerant (see below error). I will do couple of tests with logstash-bridge changes (with my ongoing PR) and introduce DefaultProjectResolver.INSTANCE in the bridge as well.


2025-08-05 14:29:13 PDT | logstash-1       \|         Caused by: java.lang.NullPointerException: Cannot invoke "org.elasticsearch.cluster.project.ProjectResolver.getProjectId()" because "this.projectResolver" is null
-- | --
  | 2025-08-05 14:29:13 PDT | logstash-1       \|                 at org.elasticsearch.script.ScriptService.compile(ScriptService.java:596) ~[elasticsearch-9.2.0-SNAPSHOT.jar:9.2.0-SNAPSHOT]
  | 2025-08-05 14:29:13 PDT | logstash-1       \|                 at org.elasticsearch.ingest.ConditionalProcessor.<init>(ConditionalProcessor.java:82) ~[elasticsearch-9.2.0-SNAPSHOT.jar:9.2.0-SNAPSHOT]
  | 2025-08-05 14:29:13 PDT | logstash-1       \|                 at org.elasticsearch.ingest.ConditionalProcessor.<init>(ConditionalProcessor.java:62) ~[elasticsearch-9.2.0-SNAPSHOT.jar:9.2.0-SNAPSHOT]
  | 2025-08-05 14:29:13 PDT | logstash-1       \|                 at org.elasticsearch.ingest.ConfigurationUtils.readProcessor(ConfigurationUtils.java:658) ~[elasticsearch-9.2.0-SNAPSHOT.jar:9.2.0-SNAPSHOT]
  | 2025-08-05 14:29:13 PDT | logstash-1       \|                 ... 104 more

Copy link
Collaborator Author

@mashhurs mashhurs Aug 6, 2025

Choose a reason for hiding this comment

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

Both null and DefaultProjectResolver.INSTANCE didn't work for this case. DefaultProjectResolver.INSTANCE requires additional classes such as Metadata class loading where plugin needs to include its jar package. Introducing a separate plugin based project resolver seems a better approach for now.
FYI: I have also tested with the logstash-bridge - mashhurs/elasticsearch@78a5fb9

donoghuc
donoghuc previously approved these changes Aug 5, 2025
Copy link
Member

@donoghuc donoghuc left a comment

Choose a reason for hiding this comment

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

LGTM

@donoghuc donoghuc dismissed their stale review August 5, 2025 21:36

Tests failing due to null pointer exception

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

@mashhurs mashhurs requested a review from donoghuc August 6, 2025 15:12
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.

Copy link
Member

@donoghuc donoghuc left a comment

Choose a reason for hiding this comment

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

I think this is worth it to get the plugin working. We can update if the pattern we choose upstream changes. :shipit:

@mashhurs mashhurs merged commit 6b369f6 into elastic:main Aug 7, 2025
4 checks passed
@mashhurs mashhurs deleted the sync-with-es-main branch August 7, 2025 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip automated backport with mergify
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants