Skip to content

Commit

Permalink
MAINT: include componentType into pluginError
Browse files Browse the repository at this point in the history
Signed-off-by: George Chen <qchea@amazon.com>
  • Loading branch information
chenqi0805 committed Aug 20, 2024
1 parent c9d3d89 commit 7759f29
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
* @since 1.2
*/
public class PipelinesDataFlowModel {
public static final String EXTENSION_PLUGIN_TYPE = "extension";

@JsonInclude(JsonInclude.Include.NON_NULL)
private DataPrepperVersion version;

@JsonAlias("pipeline_configurations")
@JsonProperty("extension")
@JsonProperty(EXTENSION_PLUGIN_TYPE)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonSetter(nulls = Nulls.SKIP)
private PipelineExtensions pipelineExtensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.opensearch.dataprepper.breaker.CircuitBreakerManager;
import org.opensearch.dataprepper.model.annotations.SingleThread;
import org.opensearch.dataprepper.model.buffer.Buffer;
import org.opensearch.dataprepper.model.configuration.PipelineModel;
import org.opensearch.dataprepper.model.configuration.PipelinesDataFlowModel;
import org.opensearch.dataprepper.model.configuration.PluginSetting;
import org.opensearch.dataprepper.model.peerforwarder.RequiresPeerForwarding;
Expand Down Expand Up @@ -124,6 +125,7 @@ private void buildPipelineFromConfiguration(
return pluginFactory.loadPlugin(Source.class, sourceSetting);
} catch (Exception e) {
final PluginError pluginError = PluginError.builder()
.componentType(PipelineModel.SOURCE_PLUGIN_TYPE)
.pipelineName(pipelineName)
.pluginName(sourceSetting.getName())
.exception(e)
Expand All @@ -140,6 +142,7 @@ private void buildPipelineFromConfiguration(
pipelineDefinedBuffer = pluginFactory.loadPlugin(Buffer.class, bufferPluginSetting, source.getDecoder());
} catch (Exception e) {
final PluginError pluginError = PluginError.builder()
.componentType(PipelineModel.BUFFER_PLUGIN_TYPE)
.pipelineName(pipelineName)
.pluginName(bufferPluginSetting.getName())
.build();
Expand Down Expand Up @@ -217,6 +220,7 @@ private List<IdentifiedComponent<Processor>> newProcessor(final PluginSetting pl
.collect(Collectors.toList());
} catch (Exception e) {
final PluginError pluginError = PluginError.builder()
.componentType(PipelineModel.PROCESSOR_PLUGIN_TYPE)
.pipelineName(pluginSetting.getPipelineName())
.pluginName(pluginSetting.getName())
.exception(e)
Expand Down Expand Up @@ -266,6 +270,7 @@ private DataFlowComponent<Sink> buildRoutedSinkOrConnector(final SinkContextPlug
return new DataFlowComponent<>(sink, pluginSetting.getSinkContext().getRoutes());
} catch (Exception e) {
final PluginError pluginError = PluginError.builder()
.componentType(PipelineModel.SINK_PLUGIN_TYPE)
.pipelineName(pluginSetting.getPipelineName())
.pluginName(pluginSetting.getName())
.exception(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PluginError {
static final String PIPELINE_DELIMITER = ":";
static final String CAUSED_BY_DELIMITER = " caused by: ";
private final String pipelineName;
private final String componentType;
@NonNull
private final String pluginName;
@NonNull
Expand All @@ -21,6 +22,10 @@ public String getErrorMessage() {
message.append(pipelineName);
message.append(PIPELINE_DELIMITER);
}
if (componentType != null) {
message.append(componentType);
message.append(PIPELINE_DELIMITER);
}
message.append(pluginName);
message.append(PIPELINE_DELIMITER);
message.append(getFlattenedExceptionMessage(CAUSED_BY_DELIMITER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class PluginErrorTest {
private static final String TEST_PIPELINE_NAME = "test-pipeline";
private static final String TEST_COMPONENT_TYPE = "test-plugin-type";
private static final String TEST_PLUGIN_NAME = "test-plugin";
private static final String TEST_ERROR_MESSAGE = "test error message";
private static final String TEST_CAUSE_ERROR_MESSAGE = "test cause error message";
Expand All @@ -19,11 +20,12 @@ void testGetErrorMessageWithPipelineName() {
when(exception.getMessage()).thenReturn(TEST_ERROR_MESSAGE);
final PluginError pluginError = PluginError.builder()
.pipelineName(TEST_PIPELINE_NAME)
.componentType(TEST_COMPONENT_TYPE)
.pluginName(TEST_PLUGIN_NAME)
.exception(exception)
.build();
assertThat(pluginError.getErrorMessage(), equalTo(
"test-pipeline:test-plugin: caused by: test error message"));
"test-pipeline:test-plugin-type:test-plugin: caused by: test error message"));
}

@Test
Expand All @@ -32,10 +34,11 @@ void testGetErrorMessageWithoutPipelineName() {
when(exception.getMessage()).thenReturn(TEST_ERROR_MESSAGE);
final PluginError pluginError = PluginError.builder()
.pluginName(TEST_PLUGIN_NAME)
.componentType(TEST_COMPONENT_TYPE)
.exception(exception)
.build();
assertThat(pluginError.getErrorMessage(), equalTo(
"test-plugin: caused by: test error message"));
"test-plugin-type:test-plugin: caused by: test error message"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package org.opensearch.dataprepper.plugin;

import org.opensearch.dataprepper.model.annotations.DataPrepperExtensionPlugin;
import org.opensearch.dataprepper.model.configuration.PipelineModel;
import org.opensearch.dataprepper.model.configuration.PipelinesDataFlowModel;
import org.opensearch.dataprepper.model.plugin.ExtensionPlugin;
import org.opensearch.dataprepper.model.plugin.InvalidPluginConfigurationException;
import org.opensearch.dataprepper.model.plugin.InvalidPluginDefinitionException;
Expand Down Expand Up @@ -49,6 +51,7 @@ public List<? extends ExtensionPlugin> loadExtensions() {
extensionClass, pluginArgumentsContext, pluginName);
} catch (Exception e) {
final PluginError pluginError = PluginError.builder()
.componentType(PipelinesDataFlowModel.EXTENSION_PLUGIN_TYPE)
.pluginName(pluginName)
.exception(e)
.build();
Expand Down

0 comments on commit 7759f29

Please sign in to comment.