Skip to content

Commit d2854f5

Browse files
authored
Register a blob cache long counter metric for total evicted regions (elastic#131862)
Currently we only track the number of evicted _used_ regions (i.e. freq > 1). This adds another metric, `es.blob_cache.count_of_evicted_regions.total`, that tracks the total number of evicted regions, irrespective of frequency.
1 parent 4b4ee57 commit d2854f5

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/BlobCacheMetrics.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ public class BlobCacheMetrics {
2727
public static final String CACHE_POPULATION_SOURCE_ATTRIBUTE_KEY = "source";
2828
public static final String LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY = "file_extension";
2929
public static final String NON_LUCENE_EXTENSION_TO_RECORD = "other";
30+
public static final String BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL = "es.blob_cache.count_of_evicted_regions.total";
3031

3132
private final LongCounter cacheMissCounter;
3233
private final LongCounter evictedCountNonZeroFrequency;
34+
private final LongCounter totalEvictedCount;
3335
private final LongHistogram cacheMissLoadTimes;
3436
private final DoubleHistogram cachePopulationThroughput;
3537
private final LongCounter cachePopulationBytes;
@@ -66,6 +68,11 @@ public BlobCacheMetrics(MeterRegistry meterRegistry) {
6668
"The number of times a cache entry was evicted where the frequency was not zero",
6769
"entries"
6870
),
71+
meterRegistry.registerLongCounter(
72+
BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL,
73+
"The number of times a cache entry was evicted, irrespective of the frequency",
74+
"entries"
75+
),
6976
meterRegistry.registerLongHistogram(
7077
"es.blob_cache.cache_miss_load_times.histogram",
7178
"The time in milliseconds for populating entries in the blob store resulting from a cache miss, expressed as a histogram.",
@@ -92,13 +99,15 @@ public BlobCacheMetrics(MeterRegistry meterRegistry) {
9299
BlobCacheMetrics(
93100
LongCounter cacheMissCounter,
94101
LongCounter evictedCountNonZeroFrequency,
102+
LongCounter totalEvictedCount,
95103
LongHistogram cacheMissLoadTimes,
96104
DoubleHistogram cachePopulationThroughput,
97105
LongCounter cachePopulationBytes,
98106
LongCounter cachePopulationTime
99107
) {
100108
this.cacheMissCounter = cacheMissCounter;
101109
this.evictedCountNonZeroFrequency = evictedCountNonZeroFrequency;
110+
this.totalEvictedCount = totalEvictedCount;
102111
this.cacheMissLoadTimes = cacheMissLoadTimes;
103112
this.cachePopulationThroughput = cachePopulationThroughput;
104113
this.cachePopulationBytes = cachePopulationBytes;
@@ -115,6 +124,10 @@ public LongCounter getEvictedCountNonZeroFrequency() {
115124
return evictedCountNonZeroFrequency;
116125
}
117126

127+
public LongCounter getTotalEvictedCount() {
128+
return totalEvictedCount;
129+
}
130+
118131
public LongHistogram getCacheMissLoadTimes() {
119132
return cacheMissLoadTimes;
120133
}

x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/shared/SharedBlobCacheService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ boolean tryEvict() {
922922
if (refCount() <= 1 && evict()) {
923923
logger.trace("evicted {} with channel offset {}", regionKey, physicalStartOffset());
924924
blobCacheService.evictCount.increment();
925+
blobCacheService.blobCacheMetrics.getTotalEvictedCount().increment();
925926
decRef();
926927
return true;
927928
}
@@ -933,6 +934,7 @@ boolean tryEvictNoDecRef() {
933934
if (refCount() <= 1 && evict()) {
934935
logger.trace("evicted and take {} with channel offset {}", regionKey, physicalStartOffset());
935936
blobCacheService.evictCount.increment();
937+
blobCacheService.blobCacheMetrics.getTotalEvictedCount().increment();
936938
return true;
937939
}
938940

@@ -944,6 +946,7 @@ public boolean forceEvict() {
944946
if (evict()) {
945947
logger.trace("force evicted {} with channel offset {}", regionKey, physicalStartOffset());
946948
blobCacheService.evictCount.increment();
949+
blobCacheService.blobCacheMetrics.getTotalEvictedCount().increment();
947950
decRef();
948951
return true;
949952
}

x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/shared/SharedBlobCacheServiceTests.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.elasticsearch.env.NodeEnvironment;
3535
import org.elasticsearch.env.TestEnvironment;
3636
import org.elasticsearch.node.NodeRoleSettings;
37+
import org.elasticsearch.telemetry.InstrumentType;
38+
import org.elasticsearch.telemetry.RecordingMeterRegistry;
3739
import org.elasticsearch.test.ESTestCase;
3840
import org.elasticsearch.threadpool.TestThreadPool;
3941
import org.elasticsearch.threadpool.ThreadPool;
@@ -57,6 +59,7 @@
5759
import java.util.stream.Collectors;
5860
import java.util.stream.IntStream;
5961

62+
import static org.elasticsearch.blobcache.BlobCacheMetrics.BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL;
6063
import static org.elasticsearch.node.Node.NODE_NAME_SETTING;
6164
import static org.hamcrest.Matchers.equalTo;
6265
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -88,14 +91,16 @@ public void testBasicEviction() throws IOException {
8891
.put("path.home", createTempDir())
8992
.build();
9093
final DeterministicTaskQueue taskQueue = new DeterministicTaskQueue();
94+
RecordingMeterRegistry recordingMeterRegistry = new RecordingMeterRegistry();
95+
BlobCacheMetrics metrics = new BlobCacheMetrics(recordingMeterRegistry);
9196
try (
9297
NodeEnvironment environment = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings));
9398
var cacheService = new SharedBlobCacheService<>(
9499
environment,
95100
settings,
96101
taskQueue.getThreadPool(),
97102
taskQueue.getThreadPool().executor(ThreadPool.Names.GENERIC),
98-
BlobCacheMetrics.NOOP
103+
metrics
99104
)
100105
) {
101106
final var cacheKey = generateCacheKey();
@@ -114,9 +119,17 @@ public void testBasicEviction() throws IOException {
114119
assertTrue(tryEvict(region1));
115120
}
116121
assertEquals(3, cacheService.freeRegionCount());
122+
// one eviction should be reflected in the telemetry for total count of evicted regions
123+
assertThat(
124+
recordingMeterRegistry.getRecorder()
125+
.getMeasurements(InstrumentType.LONG_COUNTER, BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL)
126+
.size(),
127+
is(1)
128+
);
117129
synchronized (cacheService) {
118130
assertFalse(tryEvict(region1));
119131
}
132+
120133
assertEquals(3, cacheService.freeRegionCount());
121134
final var bytesReadFuture = new PlainActionFuture<Integer>();
122135
region0.populateAndRead(
@@ -144,6 +157,14 @@ public void testBasicEviction() throws IOException {
144157
assertTrue(tryEvict(region2));
145158
}
146159
assertEquals(5, cacheService.freeRegionCount());
160+
// another 2 evictions should bump our total evictions telemetry at 3
161+
assertThat(
162+
recordingMeterRegistry.getRecorder()
163+
.getMeasurements(InstrumentType.LONG_COUNTER, BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL)
164+
.size(),
165+
is(3)
166+
);
167+
147168
assertTrue(bytesReadFuture.isDone());
148169
assertEquals(Integer.valueOf(1), bytesReadFuture.actionGet());
149170
}

0 commit comments

Comments
 (0)