Skip to content
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

Make RestController pluggable #98187

Merged

Conversation

tvernum
Copy link
Contributor

@tvernum tvernum commented Aug 4, 2023

This commit changes the ActionModules to allow the RestController to be provided by an internal plugin.

It renames RestInterceptorActionPlugin to RestServerActionPlugin and adds a new getRestController method to it.

There may be multiple RestServerActionPlugins installed on a node, but only 1 may provide a Rest Wrapper (getRestHandlerInterceptor) and only 1 may provide a RestController (getRestController).

This commit changes the ActionModules to allow  the RestController to
be provided by an internal plugin.

It rename  `RestInterceptorActionPlugin` to `RestServerActionPlugin`
and adds a new `getRestController` method to it.

There may be multiple RestServerActionPlugins installed on a node, but
only 1 may provide a Rest Wrapper (getRestHandlerInterceptor) and only
1 may provide a RestController (getRestController).
@tvernum tvernum added >enhancement :Core/Infra/REST API REST infrastructure and utilities labels Aug 4, 2023
@elasticsearchmachine elasticsearchmachine added v8.10.0 Team:Core/Infra Meta label for core/infra team labels Aug 4, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine
Copy link
Collaborator

Hi @tvernum, I've created a changelog YAML for you.

@tvernum
Copy link
Contributor Author

tvernum commented Aug 6, 2023

@elasticmachine update branch

Copy link
Contributor

@pgomulka pgomulka 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 it looks great, I left few comments to help me understand the direction taken

@@ -40,7 +40,15 @@ public void testQualifiedExports() {

// The package containing the RestInterceptor type, org.elasticsearch.plugins.interceptor,
// should only be exported to security.
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps a comment needs to be updated too?

}
}

public void test3rdPartyRestControllerIsNotInstalled() {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this really happen? we only export the org.elasticsearch.plugins.interceptor to serverless and security.
Someone would have to run ES server without java9 modules? (tests don't have them enabled)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's possible to have a plugin that is not a module, in which case qualified exports are not respected.

Perhaps we need to get to a place where we require that plugins are modularized, but we don't today.

Copy link
Contributor

@pgomulka pgomulka Aug 7, 2023

Choose a reason for hiding this comment

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

I think that if a plugin is not a module it would compile, but it would fail at runtime
I would expect that we would get a runtime exception along the lines
Exception in thread "main" java.lang.IllegalAccessError: superinterface check failed: class wrong.plugin.XYZ (in unnamed module @0x19469ea2) cannot access class org.elasticsearch.plugins.interceptor.RestServerActionPlugin (in module org.elasticserach.server) because module org.elasticsearch.server does not export org.elasticsearch.plugins.interceptor to unnamed module @0x19469ea2
(note the above message I 'hand crafted' basing on a simple reproduction project structure with 4 classes)

at the same time I don't mind this test, I just thought we don't need to wory about this (I don't test for other internal plugins)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL.
I thought I had tested with a non-modularized plugin, but I suspect it might have worked because I temporarily had an open export.

);
headersToCopy = headers;

var customController = getRestServerComponent(
Copy link
Contributor

Choose a reason for hiding this comment

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

the plan is to support multiple API Versions on the same cluster, right?
isn't the limit of one plugin implementing RestServerActionPlugin prevent us to do this?
When reading the doc I was imagining we would like to provide multiple RestControllers - one per one Version supported.
how will customController support multiple API versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now we're only supporting 1 API version, so that's a future problem.
However, I'd expect it to be a single rest controller in that case with some additional logic for dispatch - similar to how the existing controller handles V7 endpoints.

Copy link
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

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

LGTM

@tvernum tvernum added the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Aug 8, 2023
@elasticsearchmachine elasticsearchmachine merged commit 3093c40 into elastic:main Aug 8, 2023
12 checks passed
@tvernum tvernum deleted the pluggable-rest-controller branch August 8, 2023 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Core/Infra/REST API REST infrastructure and utilities >enhancement Team:Core/Infra Meta label for core/infra team v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants