Skip to content

Commit

Permalink
Merge branch 'main' into cloudwatch-logs
Browse files Browse the repository at this point in the history
Signed-off-by: Krishna Kondaka <[email protected]>
  • Loading branch information
kkondaka authored Feb 3, 2025
2 parents 3e12f79 + 7a3cf87 commit d4056fd
Show file tree
Hide file tree
Showing 174 changed files with 4,521 additions and 1,128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public @interface AlsoRequired {
/**
* Array of Required annotations, each representing a required property with its allowed values.
* @return returns array of required values
*/
Required[] values();

Expand All @@ -25,11 +26,13 @@
@interface Required {
/**
* Name of the required property.
* @return returns name
*/
String name();

/**
* Allowed values for the required property. The default value of {} means any non-null value is allowed.
* @return returns array of allowed values
*/
String[] allowedValues() default {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public @interface ConditionalRequired {
/**
* Array of if-then-else requirements.
* @return returns array of if and else values
*/
IfThenElse[] value();

Expand All @@ -22,14 +23,17 @@
@interface IfThenElse {
/**
* Array of property schemas involved in if condition.
* @return returns of if schema properties
*/
SchemaProperty[] ifFulfilled();
/**
* Array of property schemas involved in then expectation.
* @return returns of then schema properties
*/
SchemaProperty[] thenExpect();
/**
* Array of property schemas involved in else expectation.
* @return returns of else schema properties
*/
SchemaProperty[] elseExpect() default {};
}
Expand All @@ -40,10 +44,12 @@
@interface SchemaProperty {
/**
* Name of the property.
* @return returns schema field
*/
String field();
/**
* Value of the property. Empty string means any non-null value is allowed.
* @return returns schema value
*/
String value() default "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

/**
* A description of the example value.
* @return returns description
*
* @since 2.11
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public interface Processor<InputRecord extends Record<?>, OutputRecord extends R
* @since 2.11
* Indicates if the processor holds the events or not
* Holding events indicates that the events are not ready to be released.
* @return returns if events are held by the processor or not
*/
default boolean holdsEvents() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.dataprepper.plugin;

import io.micrometer.core.instrument.Counter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -14,18 +15,19 @@
import org.opensearch.dataprepper.core.event.EventFactoryApplicationContextMarker;
import org.opensearch.dataprepper.core.validation.LoggingPluginErrorsHandler;
import org.opensearch.dataprepper.core.validation.PluginErrorCollector;
import org.opensearch.dataprepper.model.plugin.NoPluginFoundException;
import org.opensearch.dataprepper.plugins.configtest.TestComponentWithConfigInject;
import org.opensearch.dataprepper.plugins.configtest.TestDISourceWithConfig;
import org.opensearch.dataprepper.validation.PluginErrorsHandler;
import org.opensearch.dataprepper.metrics.PluginMetrics;
import org.opensearch.dataprepper.model.configuration.PipelinesDataFlowModel;
import org.opensearch.dataprepper.model.configuration.PluginSetting;
import org.opensearch.dataprepper.model.plugin.InvalidPluginConfigurationException;
import org.opensearch.dataprepper.model.plugin.NoPluginFoundException;
import org.opensearch.dataprepper.model.source.Source;
import org.opensearch.dataprepper.plugins.TestObjectPlugin;
import org.opensearch.dataprepper.plugins.configtest.TestComponentWithConfigInject;
import org.opensearch.dataprepper.plugins.configtest.TestDISourceWithConfig;
import org.opensearch.dataprepper.plugins.test.TestComponent;
import org.opensearch.dataprepper.plugins.test.TestDISource;
import org.opensearch.dataprepper.plugins.test.TestPlugin;
import org.opensearch.dataprepper.validation.PluginErrorsHandler;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Collections;
Expand Down Expand Up @@ -129,7 +131,7 @@ void loadPlugin_should_return_a_new_plugin_instance_with_DI_context_initialized(
}

@Test
void loadPlugin_should_return_a_new_plugin_instance_with_DI_context_and_config_injected() {
void loadPlugin_should_return_a_new_plugin_instance_with_DI_context_with_config_and_plugin_metrics_injected() {

final String requiredStringValue = UUID.randomUUID().toString();
final String optionalStringValue = UUID.randomUUID().toString();
Expand All @@ -152,6 +154,9 @@ void loadPlugin_should_return_a_new_plugin_instance_with_DI_context_and_config_i
assertThat(pluginConfig.getRequiredString(), equalTo(requiredStringValue));
assertThat(pluginConfig.getOptionalString(), equalTo(optionalStringValue));
assertThat(plugin.getTestComponent().getIdentifier(), equalTo("test-component-with-plugin-config-injected"));
PluginMetrics pluginMetrics = plugin.getTestComponent().getPluginMetrics();
assertInstanceOf(PluginMetrics.class, pluginMetrics);
assertInstanceOf(Counter.class, pluginMetrics.counter("testCounter"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ public Object invokeMethod(String methodName, Class<?> parameterType, Object arg
* Replaces template node in the jsonPath with the node from
* original json.
*
* @param root
* @param jsonPath
* @param newNode
* @param root json root node
* @param jsonPath json path
* @param newNode new node to be repalces with
*/
public void replaceNode(JsonNode root, String jsonPath, JsonNode newNode) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public class DefaultPluginFactory implements PluginFactory {
this.pluginBeanFactoryProvider = Objects.requireNonNull(pluginBeanFactoryProvider);
this.pluginConfigurationObservableFactory = pluginConfigurationObservableFactory;

if(pluginProviders.isEmpty()) {
if (pluginProviders.isEmpty()) {
throw new RuntimeException("Data Prepper requires at least one PluginProvider. " +
"Your Data Prepper configuration may be missing the org.opensearch.dataprepper.plugin.PluginProvider file.");
}
}

@Override
public <T> T loadPlugin(final Class<T> baseClass, final PluginSetting pluginSetting, final Object ... args) {
public <T> T loadPlugin(final Class<T> baseClass, final PluginSetting pluginSetting, final Object... args) {
final String pluginName = pluginSetting.getName();
final Class<? extends T> pluginClass = getPluginClass(baseClass, pluginName);

Expand Down Expand Up @@ -100,7 +100,7 @@ public <T> List<T> loadPlugins(

final Integer numberOfInstances = numberOfInstancesFunction.apply(pluginClass);

if(numberOfInstances == null || numberOfInstances < 0)
if (numberOfInstances == null || numberOfInstances < 0)
throw new IllegalArgumentException("The numberOfInstances must be provided as a non-negative integer.");

final ComponentPluginArgumentsContext constructionContext = getConstructionContext(pluginSetting, pluginClass, null);
Expand All @@ -121,7 +121,7 @@ private <T> ComponentPluginArgumentsContext getConstructionContext(final PluginS
.createDefaultPluginConfigObservable(pluginConfigurationConverter, pluginConfigurationType, pluginSetting);

Class[] markersToScan = pluginAnnotation.packagesToScan();
BeanFactory beanFactory = pluginBeanFactoryProvider.createPluginSpecificContext(markersToScan, configuration);
BeanFactory beanFactory = pluginBeanFactoryProvider.createPluginSpecificContext(markersToScan, configuration, pluginSetting);

return new ComponentPluginArgumentsContext.Builder()
.withPluginSetting(pluginSetting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.dataprepper.plugin;

import org.opensearch.dataprepper.metrics.PluginMetrics;
import org.opensearch.dataprepper.model.configuration.PluginSetting;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
Expand All @@ -20,8 +21,8 @@
/**
* @since 1.3
* <p>
* Used to create new instances of ApplicationContext that can be used to provide a per plugin instance isolated ApplicationContext
* scope. CoreApplicationContext is unavailable to sharedPluginApplicationContext and its children.
* Used to create new instances of ApplicationContext that can be used to provide a per plugin instance isolated ApplicationContext
* scope. CoreApplicationContext is unavailable to sharedPluginApplicationContext and its children.
* </p>
* <p>pluginIsolatedApplicationContext inherits from {@link PluginBeanFactoryProvider#sharedPluginApplicationContext}</p>
* <p>{@link PluginBeanFactoryProvider#sharedPluginApplicationContext} inherits from <i>publicContext</i></p>
Expand Down Expand Up @@ -53,20 +54,23 @@ GenericApplicationContext getCoreApplicationContext() {
}

/**
* @return BeanFactory A BeanFactory that inherits from {@link PluginBeanFactoryProvider#sharedPluginApplicationContext}
* @since 1.3
* Creates a new isolated application context that inherits from
* {@link PluginBeanFactoryProvider#sharedPluginApplicationContext} then returns new context's BeanFactory.
* {@link PluginBeanFactoryProvider#sharedPluginApplicationContext} should not be directly accessible to plugins.
* instead, a new isolated {@link ApplicationContext} should be created.
* @return BeanFactory A BeanFactory that inherits from {@link PluginBeanFactoryProvider#sharedPluginApplicationContext}
*/
public BeanFactory createPluginSpecificContext(Class[] markersToScan, Object configuration) {
public BeanFactory createPluginSpecificContext(Class[] markersToScan, Object configuration, final PluginSetting pluginSetting) {
AnnotationConfigApplicationContext isolatedPluginApplicationContext = new AnnotationConfigApplicationContext();
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) isolatedPluginApplicationContext.getBeanFactory();
if(markersToScan !=null && markersToScan.length>0) {
if(configuration !=null && !(configuration instanceof PluginSetting)) {
if (markersToScan != null && markersToScan.length > 0) {
if (configuration != null && !(configuration instanceof PluginSetting)) {
beanFactory.registerSingleton(configuration.getClass().getName(), configuration);
}
if (pluginSetting != null) {
beanFactory.registerSingleton(PluginMetrics.class.getName(), PluginMetrics.fromPluginSetting(pluginSetting));
}
// If packages to scan is provided in this plugin annotation, which indicates
// that this plugin is interested in using Dependency Injection isolated for its module
Arrays.stream(markersToScan)
Expand Down
Loading

0 comments on commit d4056fd

Please sign in to comment.