in data-prepper-plugins/grok-prepper/src/main/java/com/amazon/dataprepper/plugins/prepper/grok/GrokPrepper.java [209:243]
private void matchAndMerge(final Event event) {
final Map<String, Object> grokkedCaptures = new HashMap<>();
for (final Map.Entry<String, List<Grok>> entry : fieldToGrok.entrySet()) {
for (final Grok grok : entry.getValue()) {
final String value = event.get(entry.getKey(), String.class);
if (value != null && !value.isEmpty()) {
final Match match = grok.match(value);
match.setKeepEmptyCaptures(grokPrepperConfig.isKeepEmptyCaptures());
final Map<String, Object> captures = match.capture();
mergeCaptures(grokkedCaptures, captures);
if (shouldBreakOnMatch(grokkedCaptures)) {
break;
}
}
}
if (shouldBreakOnMatch(grokkedCaptures)) {
break;
}
}
if (grokPrepperConfig.getTargetKey() != null) {
event.put(grokPrepperConfig.getTargetKey(), grokkedCaptures);
} else {
mergeCaptures(event, grokkedCaptures);
}
if (grokkedCaptures.isEmpty()) {
grokProcessingMatchFailureCounter.increment();
} else {
grokProcessingMatchSuccessCounter.increment();
}
}