Skip to content

Commit 9f79f68

Browse files
authored
Add executor name attribute to cache miss metrics (#135635)
1 parent 2c20c49 commit 9f79f68

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

docs/changelog/135635.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 135635
2+
summary: Add executor name attribute to cache miss metrics
3+
area: Search
4+
type: enhancement
5+
issues: []

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12+
import org.elasticsearch.common.util.concurrent.EsExecutors;
1213
import org.elasticsearch.index.store.LuceneFilesExtensions;
1314
import org.elasticsearch.telemetry.TelemetryProvider;
1415
import org.elasticsearch.telemetry.metric.DoubleHistogram;
@@ -29,7 +30,9 @@ public class BlobCacheMetrics {
2930
public static final String CACHE_POPULATION_REASON_ATTRIBUTE_KEY = "reason";
3031
public static final String CACHE_POPULATION_SOURCE_ATTRIBUTE_KEY = "source";
3132
public static final String LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY = "file_extension";
33+
public static final String ES_EXECUTOR_ATTRIBUTE_KEY = "executor";
3234
public static final String NON_LUCENE_EXTENSION_TO_RECORD = "other";
35+
public static final String NON_ES_EXECUTOR_TO_RECORD = "other";
3336
public static final String BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL = "es.blob_cache.count_of_evicted_regions.total";
3437
public static final String SEARCH_ORIGIN_REMOTE_STORAGE_DOWNLOAD_TOOK_TIME = "es.blob_cache.search_origin.download_took_time.total";
3538

@@ -198,13 +201,16 @@ public void recordCachePopulationMetrics(
198201
) {
199202
LuceneFilesExtensions luceneFilesExtensions = LuceneFilesExtensions.fromFile(fileName);
200203
String luceneFileExt = luceneFilesExtensions != null ? luceneFilesExtensions.getExtension() : NON_LUCENE_EXTENSION_TO_RECORD;
204+
String executorName = EsExecutors.executorName(Thread.currentThread());
201205
Map<String, Object> metricAttributes = Map.of(
202206
CACHE_POPULATION_REASON_ATTRIBUTE_KEY,
203207
cachePopulationReason.name(),
204208
CACHE_POPULATION_SOURCE_ATTRIBUTE_KEY,
205209
cachePopulationSource.name(),
206210
LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY,
207-
luceneFileExt
211+
luceneFileExt,
212+
ES_EXECUTOR_ATTRIBUTE_KEY,
213+
executorName != null ? executorName : NON_ES_EXECUTOR_TO_RECORD
208214
);
209215
assert bytesCopied > 0 : "We shouldn't be recording zero-sized copies";
210216
cachePopulationBytes.incrementBy(bytesCopied, metricAttributes);

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.common.unit.ByteSizeValue;
3030
import org.elasticsearch.common.unit.RelativeByteSizeValue;
3131
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
32+
import org.elasticsearch.common.util.concurrent.EsExecutors;
3233
import org.elasticsearch.common.util.concurrent.ThrottledTaskRunner;
3334
import org.elasticsearch.core.AbstractRefCounted;
3435
import org.elasticsearch.core.Assertions;
@@ -69,7 +70,9 @@
6970
import java.util.function.Predicate;
7071
import java.util.stream.Collectors;
7172

73+
import static org.elasticsearch.blobcache.BlobCacheMetrics.ES_EXECUTOR_ATTRIBUTE_KEY;
7274
import static org.elasticsearch.blobcache.BlobCacheMetrics.LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY;
75+
import static org.elasticsearch.blobcache.BlobCacheMetrics.NON_ES_EXECUTOR_TO_RECORD;
7376
import static org.elasticsearch.blobcache.BlobCacheMetrics.NON_LUCENE_EXTENSION_TO_RECORD;
7477

7578
/**
@@ -1284,6 +1287,7 @@ public void fillCacheRange(
12841287
ActionListener<Void> completionListener
12851288
) throws IOException {
12861289
String blobFileExtension = getFileExtension(resourceDescription);
1290+
String executorName = EsExecutors.executorName(Thread.currentThread());
12871291
writer.fillCacheRange(
12881292
channel,
12891293
channelPos,
@@ -1295,7 +1299,15 @@ public void fillCacheRange(
12951299
var elapsedTime = TimeUnit.NANOSECONDS.toMillis(relativeTimeInNanosSupplier.getAsLong() - startTime);
12961300
blobCacheMetrics.getCacheMissLoadTimes().record(elapsedTime);
12971301
blobCacheMetrics.getCacheMissCounter()
1298-
.incrementBy(1L, Map.of(LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY, blobFileExtension));
1302+
.incrementBy(
1303+
1L,
1304+
Map.of(
1305+
LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY,
1306+
blobFileExtension,
1307+
ES_EXECUTOR_ATTRIBUTE_KEY,
1308+
executorName != null ? executorName : NON_ES_EXECUTOR_TO_RECORD
1309+
)
1310+
);
12991311
return null;
13001312
})
13011313
);

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.concurrent.TimeUnit;
2020
import java.util.stream.IntStream;
2121

22+
import static org.elasticsearch.blobcache.BlobCacheMetrics.NON_ES_EXECUTOR_TO_RECORD;
2223
import static org.hamcrest.Matchers.is;
2324

2425
public class BlobCacheMetricsTests extends ESTestCase {
@@ -46,27 +47,28 @@ public void testRecordCachePopulationMetricsRecordsThroughput() {
4647
cachePopulationReason,
4748
cachePopulationSource
4849
);
50+
String threadName = NON_ES_EXECUTOR_TO_RECORD;
4951

5052
// throughput histogram
5153
Measurement throughputMeasurement = recordingMeterRegistry.getRecorder()
5254
.getMeasurements(InstrumentType.DOUBLE_HISTOGRAM, "es.blob_cache.population.throughput.histogram")
5355
.get(0);
5456
assertEquals(throughputMeasurement.getDouble(), (double) mebiBytesSent / secondsTaken, 0.0);
55-
assertExpectedAttributesPresent(throughputMeasurement, cachePopulationReason, cachePopulationSource, fileExtension);
57+
assertExpectedAttributesPresent(throughputMeasurement, cachePopulationReason, cachePopulationSource, fileExtension, threadName);
5658

5759
// bytes counter
5860
Measurement totalBytesMeasurement = recordingMeterRegistry.getRecorder()
5961
.getMeasurements(InstrumentType.LONG_COUNTER, "es.blob_cache.population.bytes.total")
6062
.get(0);
6163
assertEquals(totalBytesMeasurement.getLong(), ByteSizeValue.ofMb(mebiBytesSent).getBytes());
62-
assertExpectedAttributesPresent(totalBytesMeasurement, cachePopulationReason, cachePopulationSource, fileExtension);
64+
assertExpectedAttributesPresent(totalBytesMeasurement, cachePopulationReason, cachePopulationSource, fileExtension, threadName);
6365

6466
// time counter
6567
Measurement totalTimeMeasurement = recordingMeterRegistry.getRecorder()
6668
.getMeasurements(InstrumentType.LONG_COUNTER, "es.blob_cache.population.time.total")
6769
.get(0);
6870
assertEquals(totalTimeMeasurement.getLong(), TimeUnit.SECONDS.toMillis(secondsTaken));
69-
assertExpectedAttributesPresent(totalTimeMeasurement, cachePopulationReason, cachePopulationSource, fileExtension);
71+
assertExpectedAttributesPresent(totalTimeMeasurement, cachePopulationReason, cachePopulationSource, fileExtension, threadName);
7072

7173
// let us check for 0, avoid div by 0.
7274
checkReadsAndMisses(0, 0, 1);
@@ -107,10 +109,12 @@ private static void assertExpectedAttributesPresent(
107109
Measurement measurement,
108110
BlobCacheMetrics.CachePopulationReason cachePopulationReason,
109111
CachePopulationSource cachePopulationSource,
110-
String fileExtension
112+
String fileExtension,
113+
String threadName
111114
) {
112115
assertThat(measurement.attributes().get(BlobCacheMetrics.CACHE_POPULATION_REASON_ATTRIBUTE_KEY), is(cachePopulationReason.name()));
113116
assertThat(measurement.attributes().get(BlobCacheMetrics.CACHE_POPULATION_SOURCE_ATTRIBUTE_KEY), is(cachePopulationSource.name()));
114117
assertThat(measurement.attributes().get(BlobCacheMetrics.LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY), is(fileExtension));
118+
assertThat(measurement.attributes().get(BlobCacheMetrics.ES_EXECUTOR_ATTRIBUTE_KEY), is(threadName));
115119
}
116120
}

0 commit comments

Comments
 (0)