Skip to content

Settings api for stable plugins#91467

Merged
pgomulka merged 13 commits intoelastic:mainfrom
pgomulka:plugin_api_settings
Dec 13, 2022
Merged

Settings api for stable plugins#91467
pgomulka merged 13 commits intoelastic:mainfrom
pgomulka:plugin_api_settings

Conversation

@pgomulka
Copy link
Copy Markdown
Contributor

@pgomulka pgomulka commented Nov 9, 2022

Stable plugins do not have a dependency on server, therefore cannot access Settings, NodeSettings or IndexSettings classes. Plugins implementing new stable plugin api will use set of annotations to mark an interface that works a as a facade for settings used by their plugin.
This will allow to validate the values provided against the restrictions defined in the plugin's settings interface

This commit introduces set of annotations in libs/plugin-api that allow to annotate an interface in plugins that will be later injected into a plugin instance. These annotations can possibly be used not only by analysis plugins in the future.
The implementation of the interface generated in server is using dynamic proxy mechanism.

relates #88980

@pgomulka pgomulka self-assigned this Nov 9, 2022
@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v8.6.0 labels Nov 9, 2022
@pgomulka pgomulka changed the title Plugin api settings Settings api for stable plugins Nov 9, 2022
@pgomulka pgomulka added the :Core/Infra/Plugins Plugin API and infrastructure label Nov 9, 2022
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Nov 9, 2022
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Nov 9, 2022
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

@pgomulka pgomulka mentioned this pull request Nov 9, 2022
25 tasks
Copy link
Copy Markdown
Contributor

@grcevski grcevski left a comment

Choose a reason for hiding this comment

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

This looks good to me, I had two minor questions about the interface.

*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.CONSTRUCTOR)
public @interface Inject {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not fully up to date with all discussions, but I'm wondering if we considered maybe using another term than Inject? It might be confusing to plugin developers that are using their own dependency injection frameworks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, it can be confusing for elasticserach developers too. We already have org.elasticsearch.common.inject.Inject.
Any ideas for better name? @SettingsInject @WithSettings?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe @InjectSettings? It is doing dependency injection, but separately to any other frameworks around

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like @InjectSettings - will update

*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface IntSetting {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason we decided to provide max, but not min? Same for long setting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point, if we have max, we can have min too. In fact I am not using max or min in this PR, as it does not contain validation. Perhaps I remove max in this PR, but include max and min in another that will actually use these attributes?

Copy link
Copy Markdown
Contributor

@grcevski grcevski left a comment

Choose a reason for hiding this comment

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

LGTM!

}

} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Cannot create instance of " + clazz, e);
Copy link
Copy Markdown
Contributor Author

@pgomulka pgomulka Nov 14, 2022

Choose a reason for hiding this comment

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

should this be IllegalArgumentException?
the exception will be thrown upon the settings and plugin component creation. So when calling indices.analyze or creating a mapping
IllegalStateException will result in 500error IllegalArgumentException in 400

@kingherc kingherc added v8.7.0 and removed v8.6.0 labels Nov 16, 2022
@pgomulka pgomulka merged commit 38f3b63 into elastic:main Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Plugins Plugin API and infrastructure >enhancement Team:Core/Infra Meta label for core/infra team v8.7.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants