-
Notifications
You must be signed in to change notification settings - Fork 207
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
Write json processor #4514
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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; | ||||
|
@@ -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"; | ||||
private final String source; | ||||
private final Counter writeJsonFailedCounter; | ||||
private String target; | ||||
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()); | ||||
|
||||
|
@@ -37,6 +40,7 @@ public WriteJsonProcessor(final WriteJsonProcessorConfig writeJsonProcessorConfi | |||
if (target == null) { | ||||
target = source; | ||||
} | ||||
writeJsonFailedCounter = pluginMetrics.counter(WRITE_JSON_FAILED_COUNTER); | ||||
} | ||||
|
||||
@Override | ||||
|
@@ -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); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the exception contain user data ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can fix this as followup to mask customer data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an example of marker Line 133 in f23972c
|
||||
writeJsonFailedCounter.increment(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||
} | ||||
} | ||||
} | ||||
|
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.
Nit: could just name this
writeJsonEventsFailed
. Counter is a bit redundant.