Skip to content

Conversation

dlvenable
Copy link
Member

@dlvenable dlvenable commented Oct 3, 2025

Description

This adds a new feature to the Data Prepper plugin test framework. It provides the ability for plugin authors to write tests that will load plugin instances from a YAML file. The core feature is the addition of the @PluginConfigurationFile annotation that can be applied to method parameters. It uses JUnit's support for parameter injection to load the actual plugin and provide it to the plugin author's unit test.

The biggest new code change is the addition of PluginInstanceParameterResolver which perform the actual loading.

This also provides support for plugin tests to get an injected EventFactory or EventKeyFactory to help with authoring tests.

This PR also adds plugin test framework support to the drop_events and parse_json plugins.

Additionally, I updated the GrokProcessorIT to make as many tests as possible use this new approach. These tests are now using the framework to load plugin configurations rather than mutating PluginSetting directly. However, there were some tests that I couldn't yet update. These were:

  • Negative test cases that result in failures
  • Tests that are dynamically generated

I do plan to look into this in a future PR.

Issues Resolved

Resolves #5917

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

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.

Also, added integration tests for drop_events and parse_json processors.

Signed-off-by: David Venable <[email protected]>
…or loading plugin instances. Not all features are supported, so some tests are still using the classic approach.

Signed-off-by: David Venable <[email protected]>
Comment on lines +58 to +68
final Map<String, Object> messageMap = Map.of(
"stringKey", UUID.randomUUID().toString(),
"integerKey", random.nextInt(10_000) + 10,
"objectKey", Map.of(
"nestedKey", UUID.randomUUID().toString()
),
"arrayKey", List.of(
UUID.randomUUID().toString(),
UUID.randomUUID().toString()
)
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Like we were discussing, we can avoid these lines repeating between the test methods, if we can generalize this part as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I added #5907 to track this idea. I think it would be a nice addition.

Comment on lines +58 to +68

final PluginSetting pluginSetting = generatePluginSetting(testClass, configurationFile);

final PluginFactory pluginFactory = getOrCreatePluginFactory(extensionContext);

final Class<?> pluginType = annotation.pluginType();

return pluginFactory.loadPlugin(pluginType, pluginSetting);
}

private PluginSetting generatePluginSetting(final Class<?> testClass, final String configurationFile) {
Copy link
Collaborator

@san81 san81 Oct 9, 2025

Choose a reason for hiding this comment

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

Hope we can't avoid this method returning PluginSetting as some of the processors still depend on it! Or we shouldn't add this and convert those processors before we support test framework on them?

Copy link
Member Author

Choose a reason for hiding this comment

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

The plugin framework still takes PluginSetting. So until that is removed we need it here. But, this is kept private so that it doesn't go into the plugins themselves.


final Class<?> pluginType = annotation.pluginType();

return pluginFactory.loadPlugin(pluginType, pluginSetting);
Copy link
Collaborator

Choose a reason for hiding this comment

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

May be not required for this PR but we should test this with one of the plugin that has its PluginConfig injected. We are not explicitly registering PluginConfig object as a bean here but I think it is not required since we are scanning the entire DefaultPluginFactory.class package where are already initializing PluginConfig bean.


private static PipelinesDataFlowModel readPipelinesDataFlowModel(final Class<?> testClass, final String configurationFile) {
final PipelinesDataFlowModel pipelinesDataFlowModel;
try(final InputStream resourceStream = testClass.getResourceAsStream(configurationFile)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are expecting these files to be in the same package as the Plugin class. It may not be a problem but if the number of scenarios goes high, there may be a need to organize these into folders.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now, it loads relative to the test class actually. So there is some additional flexibility. It should also support sub-directories, though I've not tested that.

Copy link
Collaborator

@san81 san81 left a comment

Choose a reason for hiding this comment

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

Really nice addition 👍

@dlvenable dlvenable merged commit 666c726 into opensearch-project:main Oct 13, 2025
51 of 55 checks passed
@dlvenable dlvenable deleted the test-framework-load-plugins branch October 13, 2025 19:18
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.

Support loading pipeline configurations

3 participants