opensearch-project / data-prepper

Data Prepper is a component of the OpenSearch project that accepts, filters, transforms, enriches, and routes data at scale.
https://opensearch.org/docs/latest/clients/data-prepper/index/
Apache License 2.0
259 stars 191 forks source link

Support automatic plugin loading in Data Prepper core #4838

Open dlvenable opened 1 month ago

dlvenable commented 1 month ago

Is your feature request related to a problem? Please describe.

Data Prepper plugins can depend on other Data Prepper plugins. They load these plugins manually using the PluginModel.

This results in duplicated logic such as the following:

https://github.com/opensearch-project/data-prepper/blob/91b6666512805bf502186bd683ae800b0943ba10/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/AggregateProcessor.java#L83-L87

More importantly, it is also not compatible with our new support for schema and documentation generation.

Describe the solution you'd like

Provide a feature in Data Prepper core for loading plugins on behalf of other plugins. Data Prepper can have a new @UsesDataPrepperPlugin annotation which states that the type is a Data Prepper plugin.

In plugin configurations, use the desired plugin interface type. For example, replace

https://github.com/opensearch-project/data-prepper/blob/91b6666512805bf502186bd683ae800b0943ba10/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/AggregateProcessorConfig.java#L31-L34

with:

    @JsonProperty("action")
    @NotNull
    @UsesDataPrepperPlugin
    private AggregateAction aggregateAction;

When loading plugins in Data Prepper core, detect this annotation and load the plugin.

chenqi0805 commented 2 weeks ago

@dlvenable I have a slightly different proposal which makes implementation easier without intrusive change in data-prepper-core:

We will keep the original

@JsonProperty("action")
@NotNull
@UsesDataPrepperPlugin(pluginType = AggregateAction.class)
private PluginModel aggregateAction; 

Then we will register a custom deserializer and schema generator for PluginModel.class.