Skip to content

Commit a5e5dfb

Browse files
Fixing BWC tests
Signed-off-by: Martin Gaievski <[email protected]>
1 parent 3a9ff77 commit a5e5dfb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

server/src/main/java/org/opensearch/search/pipeline/Pipeline.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,21 @@ <Result extends SearchPhaseResult> void runSearchPhaseResultsTransformer(
289289
PipelineProcessingContext requestContext
290290
) throws SearchPipelineProcessingException {
291291
long pipelineStart = relativeTimeSupplier.getAsLong();
292-
beforeTransformPhaseResults();
292+
boolean hasMatchingProcessors = false;
293+
294+
// Check if there are any matching processors before tracking metrics
295+
for (SearchPhaseResultsProcessor searchPhaseResultsProcessor : searchPhaseResultsProcessors) {
296+
if (currentPhase.equals(searchPhaseResultsProcessor.getBeforePhase().getName())
297+
&& nextPhase.equals(searchPhaseResultsProcessor.getAfterPhase().getName())) {
298+
hasMatchingProcessors = true;
299+
break;
300+
}
301+
}
302+
303+
if (hasMatchingProcessors) {
304+
beforeTransformPhaseResults();
305+
}
306+
293307
try {
294308
for (SearchPhaseResultsProcessor searchPhaseResultsProcessor : searchPhaseResultsProcessors) {
295309
beforePhaseResultsProcessor(searchPhaseResultsProcessor);
@@ -325,8 +339,10 @@ <Result extends SearchPhaseResult> void runSearchPhaseResultsTransformer(
325339
} catch (Exception e) {
326340
throw new SearchPipelineProcessingException(e);
327341
} finally {
328-
long took = TimeUnit.NANOSECONDS.toMillis(relativeTimeSupplier.getAsLong() - pipelineStart);
329-
afterTransformPhaseResults(took);
342+
if (hasMatchingProcessors) {
343+
long took = TimeUnit.NANOSECONDS.toMillis(relativeTimeSupplier.getAsLong() - pipelineStart);
344+
afterTransformPhaseResults(took);
345+
}
330346
}
331347
}
332348

server/src/main/java/org/opensearch/search/pipeline/PipelineWithMetrics.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ protected void beforeTransformPhaseResults() {
250250
super.beforeTransformPhaseResults();
251251
totalPhaseResultsMetrics.before();
252252
// Phase results processing is also tracked as part of individual pipeline request processing
253+
// only when there are matching processors that will actually execute
253254
pipelineRequestMetrics.before();
254255
}
255256

@@ -258,6 +259,7 @@ protected void afterTransformPhaseResults(long timeInNanos) {
258259
super.afterTransformPhaseResults(timeInNanos);
259260
totalPhaseResultsMetrics.after(timeInNanos);
260261
// Phase results processing is also tracked as part of individual pipeline request processing
262+
// only when there are matching processors that will actually execute
261263
pipelineRequestMetrics.after(timeInNanos);
262264
}
263265

@@ -266,6 +268,7 @@ protected void onTransformPhaseResultsFailure() {
266268
super.onTransformPhaseResultsFailure();
267269
totalPhaseResultsMetrics.failed();
268270
// Phase results processing failures are also tracked as part of individual pipeline request processing
271+
// only when there are matching processors that will actually execute
269272
pipelineRequestMetrics.failed();
270273
}
271274

0 commit comments

Comments
 (0)