Skip to content

Commit fe8a43d

Browse files
committed
Add check for if performance_metadata is enabled before adding metadata for grok processing time to Events
Signed-off-by: Taylor Gray <tylgry@amazon.com>
1 parent e76d831 commit fe8a43d

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

data-prepper-plugins/grok-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/grok/GrokProcessor.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,15 @@ public Collection<Record<Event>> doExecute(final Collection<Record<Event>> recor
149149

150150
final Instant endTime = Instant.now();
151151

152-
Long totalEventTimeInGrok = (Long) event.getMetadata().getAttribute(TOTAL_TIME_SPENT_IN_GROK_METADATA_KEY);
153-
if (totalEventTimeInGrok == null) {
154-
totalEventTimeInGrok = 0L;
155-
}
152+
if (grokProcessorConfig.getIncludePerformanceMetadata()) {
153+
Long totalEventTimeInGrok = (Long) event.getMetadata().getAttribute(TOTAL_TIME_SPENT_IN_GROK_METADATA_KEY);
154+
if (totalEventTimeInGrok == null) {
155+
totalEventTimeInGrok = 0L;
156+
}
156157

157-
final long timeSpentInThisGrok = endTime.toEpochMilli() - startTime.toEpochMilli();
158-
event.getMetadata().setAttribute(TOTAL_TIME_SPENT_IN_GROK_METADATA_KEY, totalEventTimeInGrok + timeSpentInThisGrok);
158+
final long timeSpentInThisGrok = endTime.toEpochMilli() - startTime.toEpochMilli();
159+
event.getMetadata().setAttribute(TOTAL_TIME_SPENT_IN_GROK_METADATA_KEY, totalEventTimeInGrok + timeSpentInThisGrok);
160+
}
159161
}
160162
return records;
161163
}

data-prepper-plugins/grok-processor/src/test/java/org/opensearch/dataprepper/plugins/processor/grok/GrokProcessorTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public void testMatchMerge() throws JsonProcessingException, ExecutionException,
190190
assertThat(grokkedRecords.get(0).getData(), notNullValue());
191191
assertThat(grokkedRecords.get(0).getData().getMetadata(), notNullValue());
192192
assertThat(grokkedRecords.get(0).getData().getMetadata().getAttribute(TOTAL_PATTERNS_ATTEMPTED_METADATA_KEY), equalTo(null));
193+
assertThat(grokkedRecords.get(0).getData().getMetadata().getAttribute(TOTAL_TIME_SPENT_IN_GROK_METADATA_KEY), equalTo(null));
193194
assertRecordsAreEqual(grokkedRecords.get(0), resultRecord);
194195

195196
verify(grokProcessingMatchCounter, times(1)).increment();

0 commit comments

Comments
 (0)