Skip to content

Commit ba1448e

Browse files
authored
Fix ThreadPoolTests#testDetailedUtilizationMetric (elastic#138393) (elastic#138394)
1 parent e519fe4 commit ba1448e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

server/src/main/java/org/elasticsearch/common/util/concurrent/TaskExecutionTimeTrackingEsThreadPoolExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public enum UtilizationTrackingPurpose {
5757
ALLOCATION,
5858
}
5959

60-
private volatile UtilizationTracker apmUtilizationTracker = new UtilizationTracker();
61-
private volatile UtilizationTracker allocationUtilizationTracker = new UtilizationTracker();
60+
private final UtilizationTracker apmUtilizationTracker = new UtilizationTracker();
61+
private final UtilizationTracker allocationUtilizationTracker = new UtilizationTracker();
6262

6363
TaskExecutionTimeTrackingEsThreadPoolExecutor(
6464
String name,

server/src/test/java/org/elasticsearch/threadpool/ThreadPoolTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,12 @@ public void testDetailedUtilizationMetric() throws Exception {
533533
});
534534
safeAwait(barrier);
535535
safeGet(future);
536-
final long maxDurationNanos = System.nanoTime() - beforeStartNanos;
537-
538536
// Wait for TaskExecutionTimeTrackingEsThreadPoolExecutor#afterExecute to run
539537
assertBusy(() -> assertThat(executor.getTotalTaskExecutionTime(), greaterThan(0L)));
538+
// When you call submit, the TimedRunnable wraps the FutureTask, so safeGet can return before the duration of
539+
// the task is calculated. Waiting for totalTaskExecutionTime to be updated ensures maxDurationNanos is greater
540+
// than the actual duration.
541+
final long maxDurationNanos = System.nanoTime() - beforeStartNanos;
540542

541543
final long beforeMetricsCollectedNanos = System.nanoTime();
542544
meterRegistry.getRecorder().collect();

0 commit comments

Comments
 (0)