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

Initial support for plugin configuration classes #478

Merged

Conversation

dlvenable
Copy link
Member

@dlvenable dlvenable commented Oct 27, 2021

Description

This PR includes code which provides a mechanism for converting from PluginSetting into a custom class as defined by the plugin in @DataPrepperPlugin. This is the first PR for some of the work proposed in #469 for straightforward use-cases.

Issues Resolved

Provides some functionality for #469.

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@dlvenable dlvenable requested a review from cmanning09 October 27, 2021 15:10
@dlvenable
Copy link
Member Author

I updated the StringPrepper class to use a demonstration of the new functionality.

Copy link
Contributor

@laneholloway laneholloway left a comment

Choose a reason for hiding this comment

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

I approve I just have one nit that is more of a style choice, so fix it if you want since I think it just reads better but I'm not going to fight for the change.

@@ -48,7 +52,9 @@ public DefaultPluginFactory() {
final String pluginName = pluginSetting.getName();
final Class<? extends T> pluginClass = getPluginClass(baseClass, pluginName);

return pluginCreator.newPluginInstance(pluginClass, pluginSetting);
final Object configuration = getConfiguration(pluginSetting, pluginClass);
Copy link
Contributor

Choose a reason for hiding this comment

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

Really looking forward to getting rid of Object as a type that holds configuration...

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe in this case we need to stick with Object. The type is determined at runtime with this change. There might be an approach to making this work with generics, but I suspect it would be overly complicated without providing any value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sad 😢 , we can leave it as is for right now, but perhaps the work that Shivani is doing with the configuration models can help this.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could move away from Object by using inheritence and providing a base class with common configuration attirbutes like the plugin metrics. But I think you were thinking of keeping these objects separate have your considered combining?

Comment on lines +20 to +23
if(pluginConfigurationType.equals(PluginSetting.class))
return pluginSetting;

return objectMapper.convertValue(pluginSetting.getSettings(), pluginConfigurationType);
Copy link
Contributor

Choose a reason for hiding this comment

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

A nit on my part, but I'd like to see this as an if / else block.

*/
public StringPrepper(final PluginSetting pluginSetting) {
this.upperCase = pluginSetting.getBooleanOrDefault(UPPER_CASE, true);
public StringPrepper(final Configuration configuration) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@laneholloway , There is where the Object referred to in another discussion ends up being used. The plugin code gets a nice type and does not need to cast. I believe that this is very valuable for plugin authors and wanted to point it out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, thanks for showing how a plugin may use the new configuration model

Copy link
Contributor

@cmanning09 cmanning09 left a comment

Choose a reason for hiding this comment

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

My only other comment would be documenting this approach so other's can leverage the new model. I thought @laneholloway had put together a guide for developing plugins but I can't seem to find it. Perhaps he is still working on it.

@@ -48,7 +52,9 @@ public DefaultPluginFactory() {
final String pluginName = pluginSetting.getName();
final Class<? extends T> pluginClass = getPluginClass(baseClass, pluginName);

return pluginCreator.newPluginInstance(pluginClass, pluginSetting);
final Object configuration = getConfiguration(pluginSetting, pluginClass);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could move away from Object by using inheritence and providing a base class with common configuration attirbutes like the plugin metrics. But I think you were thinking of keeping these objects separate have your considered combining?

*/
public StringPrepper(final PluginSetting pluginSetting) {
this.upperCase = pluginSetting.getBooleanOrDefault(UPPER_CASE, true);
public StringPrepper(final Configuration configuration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, thanks for showing how a plugin may use the new configuration model

@dlvenable
Copy link
Member Author

@cmanning09 ,

Regarding documentation, Data Prepper doesn't currently have a plugin development guide. At least part of the problem is that it doesn't yet support plugins from external sources. I'll look into adding more documentation after making all the other upcoming changes.

For the Object, I do intend to keep the other objects separated. I'd very much like for the plugin configuration to be just the configuration. Thus, a base class or interface would be blank, so I don't see the value of it. Also, this Object is used solely within the plugin framework code. Plugins get objects which are meaningful to developers.

@dlvenable dlvenable merged commit 8e53185 into opensearch-project:main Oct 28, 2021
@dlvenable dlvenable deleted the plugin-configuration-classes branch November 29, 2021 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants