Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public class BlobCacheMetrics {
public static final String CACHE_POPULATION_SOURCE_ATTRIBUTE_KEY = "source";
public static final String LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY = "file_extension";
public static final String NON_LUCENE_EXTENSION_TO_RECORD = "other";
public static final String BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL = "es.blob_cache.count_of_evicted_regions.total";

private final LongCounter cacheMissCounter;
private final LongCounter evictedCountNonZeroFrequency;
private final LongCounter totalEvictedCount;
private final LongHistogram cacheMissLoadTimes;
private final DoubleHistogram cachePopulationThroughput;
private final LongCounter cachePopulationBytes;
Expand Down Expand Up @@ -66,6 +68,11 @@ public BlobCacheMetrics(MeterRegistry meterRegistry) {
"The number of times a cache entry was evicted where the frequency was not zero",
"entries"
),
meterRegistry.registerLongCounter(
BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL,
"The number of times a cache entry was evicted, irrespective of the frequency",
"entries"
),
meterRegistry.registerLongHistogram(
"es.blob_cache.cache_miss_load_times.histogram",
"The time in milliseconds for populating entries in the blob store resulting from a cache miss, expressed as a histogram.",
Expand All @@ -92,13 +99,15 @@ public BlobCacheMetrics(MeterRegistry meterRegistry) {
BlobCacheMetrics(
LongCounter cacheMissCounter,
LongCounter evictedCountNonZeroFrequency,
LongCounter totalEvictedCount,
LongHistogram cacheMissLoadTimes,
DoubleHistogram cachePopulationThroughput,
LongCounter cachePopulationBytes,
LongCounter cachePopulationTime
) {
this.cacheMissCounter = cacheMissCounter;
this.evictedCountNonZeroFrequency = evictedCountNonZeroFrequency;
this.totalEvictedCount = totalEvictedCount;
this.cacheMissLoadTimes = cacheMissLoadTimes;
this.cachePopulationThroughput = cachePopulationThroughput;
this.cachePopulationBytes = cachePopulationBytes;
Expand All @@ -115,6 +124,10 @@ public LongCounter getEvictedCountNonZeroFrequency() {
return evictedCountNonZeroFrequency;
}

public LongCounter getTotalEvictedCount() {
return totalEvictedCount;
}

public LongHistogram getCacheMissLoadTimes() {
return cacheMissLoadTimes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ boolean tryEvict() {
if (refCount() <= 1 && evict()) {
logger.trace("evicted {} with channel offset {}", regionKey, physicalStartOffset());
blobCacheService.evictCount.increment();
blobCacheService.blobCacheMetrics.getTotalEvictedCount().increment();
decRef();
return true;
}
Expand All @@ -933,6 +934,7 @@ boolean tryEvictNoDecRef() {
if (refCount() <= 1 && evict()) {
logger.trace("evicted and take {} with channel offset {}", regionKey, physicalStartOffset());
blobCacheService.evictCount.increment();
blobCacheService.blobCacheMetrics.getTotalEvictedCount().increment();
return true;
}

Expand All @@ -944,6 +946,7 @@ public boolean forceEvict() {
if (evict()) {
logger.trace("force evicted {} with channel offset {}", regionKey, physicalStartOffset());
blobCacheService.evictCount.increment();
blobCacheService.blobCacheMetrics.getTotalEvictedCount().increment();
decRef();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.env.TestEnvironment;
import org.elasticsearch.node.NodeRoleSettings;
import org.elasticsearch.telemetry.InstrumentType;
import org.elasticsearch.telemetry.RecordingMeterRegistry;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.TestThreadPool;
import org.elasticsearch.threadpool.ThreadPool;
Expand All @@ -57,6 +59,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.elasticsearch.blobcache.BlobCacheMetrics.BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL;
import static org.elasticsearch.node.Node.NODE_NAME_SETTING;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
Expand Down Expand Up @@ -88,14 +91,16 @@ public void testBasicEviction() throws IOException {
.put("path.home", createTempDir())
.build();
final DeterministicTaskQueue taskQueue = new DeterministicTaskQueue();
RecordingMeterRegistry recordingMeterRegistry = new RecordingMeterRegistry();
BlobCacheMetrics metrics = new BlobCacheMetrics(recordingMeterRegistry);
try (
NodeEnvironment environment = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings));
var cacheService = new SharedBlobCacheService<>(
environment,
settings,
taskQueue.getThreadPool(),
taskQueue.getThreadPool().executor(ThreadPool.Names.GENERIC),
BlobCacheMetrics.NOOP
metrics
)
) {
final var cacheKey = generateCacheKey();
Expand All @@ -114,9 +119,17 @@ public void testBasicEviction() throws IOException {
assertTrue(tryEvict(region1));
}
assertEquals(3, cacheService.freeRegionCount());
// one eviction should be reflected in the telemetry for total count of evicted regions
assertThat(
recordingMeterRegistry.getRecorder()
.getMeasurements(InstrumentType.LONG_COUNTER, BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL)
.size(),
is(1)
);
synchronized (cacheService) {
assertFalse(tryEvict(region1));
}

assertEquals(3, cacheService.freeRegionCount());
final var bytesReadFuture = new PlainActionFuture<Integer>();
region0.populateAndRead(
Expand Down Expand Up @@ -144,6 +157,14 @@ public void testBasicEviction() throws IOException {
assertTrue(tryEvict(region2));
}
assertEquals(5, cacheService.freeRegionCount());
// another 2 evictions should bump our total evictions telemetry at 3
assertThat(
recordingMeterRegistry.getRecorder()
.getMeasurements(InstrumentType.LONG_COUNTER, BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL)
.size(),
is(3)
);

assertTrue(bytesReadFuture.isDone());
assertEquals(Integer.valueOf(1), bytesReadFuture.actionGet());
}
Expand Down