-
Notifications
You must be signed in to change notification settings - Fork 214
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
Introduces the experimental plugin feature #5318
Merged
dlvenable
merged 2 commits into
opensearch-project:main
from
dlvenable:2695-experimental-plugins
Jan 15, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...-prepper-api/src/main/java/org/opensearch/dataprepper/model/annotations/Experimental.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Marks a Data Prepper plugin as experimental. | ||
* <p> | ||
* Experimental plugins do not have the same compatibility guarantees as other plugins and may be unstable. | ||
* They may have breaking changes between minor versions and may even be removed. | ||
* <p> | ||
* Data Prepper administrators must enable experimental plugins in order to use them. | ||
* Otherwise, they are not available to use with pipelines. | ||
* | ||
* @since 2.11 | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface Experimental { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...prepper-core/src/test/java/org/opensearch/dataprepper/plugins/TestExperimentalPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins; | ||
|
||
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; | ||
import org.opensearch.dataprepper.model.annotations.Experimental; | ||
import org.opensearch.dataprepper.plugin.TestPluggableInterface; | ||
|
||
@DataPrepperPlugin(name = "test_experimental_plugin", pluginType = TestPluggableInterface.class) | ||
@Experimental | ||
public class TestExperimentalPlugin { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...epper-plugin-framework/src/main/java/org/opensearch/dataprepper/plugin/DefinedPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
import java.util.Objects; | ||
|
||
class DefinedPlugin<T> { | ||
private final Class<? extends T> pluginClass; | ||
private final String pluginName; | ||
|
||
public DefinedPlugin(final Class<? extends T> pluginClass, final String pluginName) { | ||
this.pluginClass = Objects.requireNonNull(pluginClass); | ||
this.pluginName = Objects.requireNonNull(pluginName); | ||
} | ||
|
||
public Class<? extends T> getPluginClass() { | ||
return pluginClass; | ||
} | ||
|
||
public String getPluginName() { | ||
return pluginName; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...n-framework/src/main/java/org/opensearch/dataprepper/plugin/DeprecatedPluginDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Named; | ||
import java.util.function.Consumer; | ||
|
||
@Named | ||
class DeprecatedPluginDetector implements Consumer<DefinedPlugin<?>> { | ||
private static final Logger LOG = LoggerFactory.getLogger(DeprecatedPluginDetector.class); | ||
|
||
@Override | ||
public void accept(final DefinedPlugin<?> definedPlugin) { | ||
logDeprecatedPluginsNames(definedPlugin.getPluginClass(), definedPlugin.getPluginName()); | ||
} | ||
|
||
private void logDeprecatedPluginsNames(final Class<?> pluginClass, final String pluginName) { | ||
final String deprecatedName = pluginClass.getAnnotation(DataPrepperPlugin.class).deprecatedName(); | ||
final String name = pluginClass.getAnnotation(DataPrepperPlugin.class).name(); | ||
if (deprecatedName.equals(pluginName)) { | ||
LOG.warn("Plugin name '{}' is deprecated and will be removed in the next major release. Consider using the updated plugin name '{}'.", deprecatedName, name); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...-framework/src/main/java/org/opensearch/dataprepper/plugin/ExperimentalConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* Data Prepper configurations for experimental features. | ||
* | ||
* @since 2.11 | ||
*/ | ||
public class ExperimentalConfiguration { | ||
@JsonProperty("enable_all") | ||
private boolean enableAll = false; | ||
|
||
public static ExperimentalConfiguration defaultConfiguration() { | ||
return new ExperimentalConfiguration(); | ||
} | ||
|
||
/** | ||
* Gets whether all experimental features are enabled. | ||
* @return true if all experimental features are enabled, false otherwise | ||
* @since 2.11 | ||
*/ | ||
public boolean isEnableAll() { | ||
return enableAll; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...k/src/main/java/org/opensearch/dataprepper/plugin/ExperimentalConfigurationContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
/** | ||
* Interface to decouple how an experimental configuration is defined from | ||
* usage of those configurations. | ||
* | ||
* @since 2.11 | ||
*/ | ||
public interface ExperimentalConfigurationContainer { | ||
/** | ||
* Gets the experimental configuration. | ||
* @return the experimental configuration | ||
* @since 2.11 | ||
*/ | ||
ExperimentalConfiguration getExperimental(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...ramework/src/main/java/org/opensearch/dataprepper/plugin/ExperimentalPluginValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
import org.opensearch.dataprepper.model.annotations.Experimental; | ||
import org.opensearch.dataprepper.model.plugin.NoPluginFoundException; | ||
|
||
import javax.inject.Named; | ||
import java.util.function.Consumer; | ||
|
||
@Named | ||
class ExperimentalPluginValidator implements Consumer<DefinedPlugin<?>> { | ||
private final ExperimentalConfiguration experimentalConfiguration; | ||
|
||
ExperimentalPluginValidator(final ExperimentalConfigurationContainer experimentalConfigurationContainer) { | ||
this.experimentalConfiguration = experimentalConfigurationContainer.getExperimental(); | ||
} | ||
|
||
@Override | ||
public void accept(final DefinedPlugin<?> definedPlugin) { | ||
if(isPluginDisallowedAsExperimental(definedPlugin.getPluginClass())) { | ||
throw new NoPluginFoundException("Unable to create experimental plugin " + definedPlugin.getPluginName() + | ||
". You must enable experimental plugins in data-prepper-config.yaml in order to use them."); | ||
} | ||
} | ||
|
||
private boolean isPluginDisallowedAsExperimental(final Class<?> pluginClass) { | ||
return pluginClass.isAnnotationPresent(Experimental.class) && !experimentalConfiguration.isEnableAll(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newly added files could use the new copyright message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@san81 , Thank you for catching this. I have updated all the new files with this header.