35
35
import org .elasticsearch .env .TestEnvironment ;
36
36
import org .elasticsearch .node .NodeRoleSettings ;
37
37
import org .elasticsearch .telemetry .InstrumentType ;
38
+ import org .elasticsearch .telemetry .Measurement ;
38
39
import org .elasticsearch .telemetry .RecordingMeterRegistry ;
39
40
import org .elasticsearch .test .ESTestCase ;
40
41
import org .elasticsearch .threadpool .TestThreadPool ;
@@ -332,6 +333,8 @@ public void testAsynchronousEviction() throws Exception {
332
333
}
333
334
334
335
public void testDecay () throws IOException {
336
+ RecordingMeterRegistry recordingMeterRegistry = new RecordingMeterRegistry ();
337
+ BlobCacheMetrics metrics = new BlobCacheMetrics (recordingMeterRegistry );
335
338
// we have 8 regions
336
339
Settings settings = Settings .builder ()
337
340
.put (NODE_NAME_SETTING .getKey (), "node" )
@@ -347,7 +350,7 @@ public void testDecay() throws IOException {
347
350
settings ,
348
351
taskQueue .getThreadPool (),
349
352
taskQueue .getThreadPool ().executor (ThreadPool .Names .GENERIC ),
350
- BlobCacheMetrics . NOOP
353
+ metrics
351
354
)
352
355
) {
353
356
assertEquals (4 , cacheService .freeRegionCount ());
@@ -375,6 +378,8 @@ public void testDecay() throws IOException {
375
378
assertThat (taskQueue .hasRunnableTasks (), is (true ));
376
379
taskQueue .runAllRunnableTasks ();
377
380
assertThat (cacheService .epoch (), equalTo (expectedEpoch .incrementAndGet ()));
381
+ long epochs = recordedEpochs (recordingMeterRegistry );
382
+ assertEquals (cacheService .epoch (), epochs );
378
383
};
379
384
380
385
triggerDecay .run ();
@@ -435,11 +440,22 @@ public void testDecay() throws IOException {
435
440
}
436
441
}
437
442
443
+ private static long recordedEpochs (RecordingMeterRegistry recordingMeterRegistry ) {
444
+ long epochs = recordingMeterRegistry .getRecorder ()
445
+ .getMeasurements (InstrumentType .LONG_COUNTER , "es.blob_cache.epoch.total" )
446
+ .stream ()
447
+ .mapToLong (Measurement ::getLong )
448
+ .sum ();
449
+ return epochs ;
450
+ }
451
+
438
452
/**
439
453
* Test when many objects need to decay, in particular useful to measure how long the decay task takes.
440
454
* For 1M objects (with no assertions) it took 26ms locally.
441
455
*/
442
456
public void testMassiveDecay () throws IOException {
457
+ RecordingMeterRegistry recordingMeterRegistry = new RecordingMeterRegistry ();
458
+ BlobCacheMetrics metrics = new BlobCacheMetrics (recordingMeterRegistry );
443
459
int regions = 1024 ; // to measure decay time, increase to 1024*1024 and disable assertions.
444
460
Settings settings = Settings .builder ()
445
461
.put (NODE_NAME_SETTING .getKey (), "node" )
@@ -455,7 +471,7 @@ public void testMassiveDecay() throws IOException {
455
471
settings ,
456
472
taskQueue .getThreadPool (),
457
473
taskQueue .getThreadPool ().executor (ThreadPool .Names .GENERIC ),
458
- BlobCacheMetrics . NOOP
474
+ metrics
459
475
)
460
476
) {
461
477
Runnable decay = () -> {
@@ -496,6 +512,9 @@ public void testMassiveDecay() throws IOException {
496
512
}
497
513
}
498
514
assertThat (freqs .get (4 ), equalTo (regions - maxRounds + 1 ));
515
+
516
+ long epochs = recordedEpochs (recordingMeterRegistry );
517
+ assertEquals (cacheService .epoch (), epochs );
499
518
}
500
519
}
501
520
0 commit comments