3535import org .elasticsearch .env .TestEnvironment ;
3636import org .elasticsearch .node .NodeRoleSettings ;
3737import org .elasticsearch .telemetry .InstrumentType ;
38+ import org .elasticsearch .telemetry .Measurement ;
3839import org .elasticsearch .telemetry .RecordingMeterRegistry ;
3940import org .elasticsearch .test .ESTestCase ;
4041import org .elasticsearch .threadpool .TestThreadPool ;
@@ -332,6 +333,8 @@ public void testAsynchronousEviction() throws Exception {
332333 }
333334
334335 public void testDecay () throws IOException {
336+ RecordingMeterRegistry recordingMeterRegistry = new RecordingMeterRegistry ();
337+ BlobCacheMetrics metrics = new BlobCacheMetrics (recordingMeterRegistry );
335338 // we have 8 regions
336339 Settings settings = Settings .builder ()
337340 .put (NODE_NAME_SETTING .getKey (), "node" )
@@ -347,7 +350,7 @@ public void testDecay() throws IOException {
347350 settings ,
348351 taskQueue .getThreadPool (),
349352 taskQueue .getThreadPool ().executor (ThreadPool .Names .GENERIC ),
350- BlobCacheMetrics . NOOP
353+ metrics
351354 )
352355 ) {
353356 assertEquals (4 , cacheService .freeRegionCount ());
@@ -375,6 +378,8 @@ public void testDecay() throws IOException {
375378 assertThat (taskQueue .hasRunnableTasks (), is (true ));
376379 taskQueue .runAllRunnableTasks ();
377380 assertThat (cacheService .epoch (), equalTo (expectedEpoch .incrementAndGet ()));
381+ long epochs = recordedEpochs (recordingMeterRegistry );
382+ assertEquals (cacheService .epoch (), epochs );
378383 };
379384
380385 triggerDecay .run ();
@@ -435,11 +440,22 @@ public void testDecay() throws IOException {
435440 }
436441 }
437442
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+
438452 /**
439453 * Test when many objects need to decay, in particular useful to measure how long the decay task takes.
440454 * For 1M objects (with no assertions) it took 26ms locally.
441455 */
442456 public void testMassiveDecay () throws IOException {
457+ RecordingMeterRegistry recordingMeterRegistry = new RecordingMeterRegistry ();
458+ BlobCacheMetrics metrics = new BlobCacheMetrics (recordingMeterRegistry );
443459 int regions = 1024 ; // to measure decay time, increase to 1024*1024 and disable assertions.
444460 Settings settings = Settings .builder ()
445461 .put (NODE_NAME_SETTING .getKey (), "node" )
@@ -455,7 +471,7 @@ public void testMassiveDecay() throws IOException {
455471 settings ,
456472 taskQueue .getThreadPool (),
457473 taskQueue .getThreadPool ().executor (ThreadPool .Names .GENERIC ),
458- BlobCacheMetrics . NOOP
474+ metrics
459475 )
460476 ) {
461477 Runnable decay = () -> {
@@ -496,6 +512,9 @@ public void testMassiveDecay() throws IOException {
496512 }
497513 }
498514 assertThat (freqs .get (4 ), equalTo (regions - maxRounds + 1 ));
515+
516+ long epochs = recordedEpochs (recordingMeterRegistry );
517+ assertEquals (cacheService .epoch (), epochs );
499518 }
500519 }
501520
0 commit comments