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

[Backport 2.6] Fix substitute string processor to handle exceptions gracefully #3853

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
import org.opensearch.dataprepper.model.processor.AbstractProcessor;
import org.opensearch.dataprepper.model.record.Record;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.List;

import static org.opensearch.dataprepper.logging.DataPrepperMarkers.EVENT;

public abstract class AbstractStringProcessor<T> extends AbstractProcessor<Record<Event>, Record<Event>> {
private final List<T> entries;
static final Logger LOG = LoggerFactory.getLogger(AbstractStringProcessor.class);

@DataPrepperPluginConstructor
public AbstractStringProcessor(final PluginMetrics pluginMetrics, final StringProcessorConfig<T> config) {
Expand All @@ -35,18 +41,20 @@ public Collection<Record<Event>> doExecute(final Collection<Record<Event>> recor

private void performStringAction(final Event recordEvent)
{
for(T entry : entries) {


final String key = getKey(entry);
try {
for(T entry : entries) {
final String key = getKey(entry);

if(recordEvent.containsKey(key)) {
final Object value = recordEvent.get(key, Object.class);
if(recordEvent.containsKey(key)) {
final Object value = recordEvent.get(key, Object.class);

if(value instanceof String) {
performKeyAction(recordEvent, entry, (String) value);
if(value instanceof String) {
performKeyAction(recordEvent, entry, (String) value);
}
}
}
} catch (Exception e) {
LOG.error(EVENT, "Exception while performing String action", e);
}
}

Expand Down
Loading