@@ -342,19 +342,22 @@ public Map<String, Long> buildQueryBreakdownMap(
342
342
(key , value ) -> (value == null ) ? sliceBreakdownTypeCount : sliceBreakdownTypeCount + value
343
343
);
344
344
345
- // query start/end time for a TimingType is min/max of start/end time across slices for that TimingType
346
- queryTimingTypeEndTime = Math .max (
347
- queryTimingTypeEndTime ,
348
- sliceBreakdown .getValue ().getOrDefault (sliceEndTimeForTimingType , Long .MIN_VALUE )
349
- );
350
- queryTimingTypeStartTime = Math .min (
351
- queryTimingTypeStartTime ,
352
- sliceBreakdown .getValue ().getOrDefault (sliceStartTimeForTimingType , Long .MAX_VALUE )
353
- );
354
- queryTimingTypeCount += sliceBreakdownTypeCount ;
345
+ // only modify the start/end time of the TimingType if the slice used the timer
346
+ if (sliceBreakdownTypeCount > 0L ) {
347
+ // query start/end time for a TimingType is min/max of start/end time across slices for that TimingType
348
+ queryTimingTypeEndTime = Math .max (
349
+ queryTimingTypeEndTime ,
350
+ sliceBreakdown .getValue ().getOrDefault (sliceEndTimeForTimingType , Long .MIN_VALUE )
351
+ );
352
+ queryTimingTypeStartTime = Math .min (
353
+ queryTimingTypeStartTime ,
354
+ sliceBreakdown .getValue ().getOrDefault (sliceStartTimeForTimingType , Long .MAX_VALUE )
355
+ );
356
+ queryTimingTypeCount += sliceBreakdownTypeCount ;
357
+ }
355
358
}
356
359
357
- if (queryTimingTypeStartTime == Long .MAX_VALUE || queryTimingTypeEndTime == Long .MIN_VALUE ) {
360
+ if (queryTimingTypeCount > 0L && ( queryTimingTypeStartTime == Long .MAX_VALUE || queryTimingTypeEndTime == Long .MIN_VALUE ) ) {
358
361
throw new OpenSearchException (
359
362
"Unexpected timing type ["
360
363
+ timingTypeKey
@@ -365,7 +368,7 @@ public Map<String, Long> buildQueryBreakdownMap(
365
368
+ "] computed across slices for profile results"
366
369
);
367
370
}
368
- queryBreakdownMap .put (timingTypeKey , queryTimingTypeEndTime - queryTimingTypeStartTime );
371
+ queryBreakdownMap .put (timingTypeKey , ( queryTimingTypeCount > 0L ) ? queryTimingTypeEndTime - queryTimingTypeStartTime : 0L );
369
372
queryBreakdownMap .put (timingTypeCountKey , queryTimingTypeCount );
370
373
queryBreakdownMap .compute (avgBreakdownTypeTime , (key , value ) -> (value == null ) ? 0L : value / sliceLevelBreakdowns .size ());
371
374
queryBreakdownMap .compute (avgBreakdownTypeCount , (key , value ) -> (value == null ) ? 0L : value / sliceLevelBreakdowns .size ());
0 commit comments