Skip to content
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

Write json processor #4514

Merged
merged 5 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data-prepper-plugins/write-json-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
dependencies {
implementation project(':data-prepper-api')
implementation project(':data-prepper-plugins:common')
implementation 'io.micrometer:micrometer-core'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-ion'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.micrometer.core.instrument.Counter;
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin;
import org.opensearch.dataprepper.model.annotations.DataPrepperPluginConstructor;
import org.opensearch.dataprepper.metrics.PluginMetrics;
Expand All @@ -25,7 +26,9 @@
@DataPrepperPlugin(name = "write_json", pluginType = Processor.class, pluginConfigurationType = WriteJsonProcessorConfig.class)
public class WriteJsonProcessor extends AbstractProcessor<Record<Event>, Record<Event>> {
private static final Logger LOG = LoggerFactory.getLogger(WriteJsonProcessor.class);
private static final String WRITE_JSON_FAILED_COUNTER = "writeJsonFailedCounter";
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could just name this writeJsonEventsFailed. Counter is a bit redundant.

private final String source;
private final Counter writeJsonFailedCounter;
private String target;
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());

Expand All @@ -37,6 +40,7 @@ public WriteJsonProcessor(final WriteJsonProcessorConfig writeJsonProcessorConfi
if (target == null) {
target = source;
}
writeJsonFailedCounter = pluginMetrics.counter(WRITE_JSON_FAILED_COUNTER);
}

@Override
Expand All @@ -48,7 +52,8 @@ public Collection<Record<Event>> doExecute(Collection<Record<Event>> records) {
try {
event.put(target, objectMapper.writeValueAsString(value));
} catch (Exception e) {
LOG.error("Failed to convert source to json string");
LOG.error("Failed to convert source to json string", e);
Copy link
Member

Choose a reason for hiding this comment

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

Does the exception contain user data ?

Copy link
Member

Choose a reason for hiding this comment

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

We can fix this as followup to mask customer data.

Copy link
Member

Choose a reason for hiding this comment

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

Here is an example of marker

LOG.error(DataPrepperMarkers.EVENT, "Failed to get IP address from [{}] in event: [{}]. Caused by:[{}]",

writeJsonFailedCounter.increment();
Copy link
Member

Choose a reason for hiding this comment

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

Could add a unit test to cover this case and verify metric is incremented

}
}
}
Expand Down
Loading