diff --git a/docs/changelog/135635.yaml b/docs/changelog/135635.yaml new file mode 100644 index 0000000000000..11493c0028b8a --- /dev/null +++ b/docs/changelog/135635.yaml @@ -0,0 +1,5 @@ +pr: 135635 +summary: Add executor name attribute to cache miss metrics +area: Search +type: enhancement +issues: [] diff --git a/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/BlobCacheMetrics.java b/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/BlobCacheMetrics.java index a814366c03651..b0aaea78d21b8 100644 --- a/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/BlobCacheMetrics.java +++ b/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/BlobCacheMetrics.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.index.store.LuceneFilesExtensions; import org.elasticsearch.telemetry.TelemetryProvider; import org.elasticsearch.telemetry.metric.DoubleHistogram; @@ -29,7 +30,9 @@ public class BlobCacheMetrics { public static final String CACHE_POPULATION_REASON_ATTRIBUTE_KEY = "reason"; 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 ES_EXECUTOR_ATTRIBUTE_KEY = "executor"; public static final String NON_LUCENE_EXTENSION_TO_RECORD = "other"; + public static final String NON_ES_EXECUTOR_TO_RECORD = "other"; public static final String BLOB_CACHE_COUNT_OF_EVICTED_REGIONS_TOTAL = "es.blob_cache.count_of_evicted_regions.total"; public static final String SEARCH_ORIGIN_REMOTE_STORAGE_DOWNLOAD_TOOK_TIME = "es.blob_cache.search_origin.download_took_time.total"; @@ -198,13 +201,16 @@ public void recordCachePopulationMetrics( ) { LuceneFilesExtensions luceneFilesExtensions = LuceneFilesExtensions.fromFile(fileName); String luceneFileExt = luceneFilesExtensions != null ? luceneFilesExtensions.getExtension() : NON_LUCENE_EXTENSION_TO_RECORD; + String executorName = EsExecutors.executorName(Thread.currentThread()); Map metricAttributes = Map.of( CACHE_POPULATION_REASON_ATTRIBUTE_KEY, cachePopulationReason.name(), CACHE_POPULATION_SOURCE_ATTRIBUTE_KEY, cachePopulationSource.name(), LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY, - luceneFileExt + luceneFileExt, + ES_EXECUTOR_ATTRIBUTE_KEY, + executorName != null ? executorName : NON_ES_EXECUTOR_TO_RECORD ); assert bytesCopied > 0 : "We shouldn't be recording zero-sized copies"; cachePopulationBytes.incrementBy(bytesCopied, metricAttributes); diff --git a/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/shared/SharedBlobCacheService.java b/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/shared/SharedBlobCacheService.java index 43ef410d28f52..6143d20d6875e 100644 --- a/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/shared/SharedBlobCacheService.java +++ b/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/shared/SharedBlobCacheService.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.RelativeByteSizeValue; import org.elasticsearch.common.util.concurrent.AbstractRunnable; +import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.ThrottledTaskRunner; import org.elasticsearch.core.AbstractRefCounted; import org.elasticsearch.core.Assertions; @@ -69,7 +70,9 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import static org.elasticsearch.blobcache.BlobCacheMetrics.ES_EXECUTOR_ATTRIBUTE_KEY; import static org.elasticsearch.blobcache.BlobCacheMetrics.LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY; +import static org.elasticsearch.blobcache.BlobCacheMetrics.NON_ES_EXECUTOR_TO_RECORD; import static org.elasticsearch.blobcache.BlobCacheMetrics.NON_LUCENE_EXTENSION_TO_RECORD; /** @@ -1284,6 +1287,7 @@ public void fillCacheRange( ActionListener completionListener ) throws IOException { String blobFileExtension = getFileExtension(resourceDescription); + String executorName = EsExecutors.executorName(Thread.currentThread()); writer.fillCacheRange( channel, channelPos, @@ -1295,7 +1299,15 @@ public void fillCacheRange( var elapsedTime = TimeUnit.NANOSECONDS.toMillis(relativeTimeInNanosSupplier.getAsLong() - startTime); blobCacheMetrics.getCacheMissLoadTimes().record(elapsedTime); blobCacheMetrics.getCacheMissCounter() - .incrementBy(1L, Map.of(LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY, blobFileExtension)); + .incrementBy( + 1L, + Map.of( + LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY, + blobFileExtension, + ES_EXECUTOR_ATTRIBUTE_KEY, + executorName != null ? executorName : NON_ES_EXECUTOR_TO_RECORD + ) + ); return null; }) ); diff --git a/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/BlobCacheMetricsTests.java b/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/BlobCacheMetricsTests.java index 87af6e101cd09..4ade158907452 100644 --- a/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/BlobCacheMetricsTests.java +++ b/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/BlobCacheMetricsTests.java @@ -19,6 +19,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; +import static org.elasticsearch.blobcache.BlobCacheMetrics.NON_ES_EXECUTOR_TO_RECORD; import static org.hamcrest.Matchers.is; public class BlobCacheMetricsTests extends ESTestCase { @@ -46,27 +47,28 @@ public void testRecordCachePopulationMetricsRecordsThroughput() { cachePopulationReason, cachePopulationSource ); + String threadName = NON_ES_EXECUTOR_TO_RECORD; // throughput histogram Measurement throughputMeasurement = recordingMeterRegistry.getRecorder() .getMeasurements(InstrumentType.DOUBLE_HISTOGRAM, "es.blob_cache.population.throughput.histogram") .get(0); assertEquals(throughputMeasurement.getDouble(), (double) mebiBytesSent / secondsTaken, 0.0); - assertExpectedAttributesPresent(throughputMeasurement, cachePopulationReason, cachePopulationSource, fileExtension); + assertExpectedAttributesPresent(throughputMeasurement, cachePopulationReason, cachePopulationSource, fileExtension, threadName); // bytes counter Measurement totalBytesMeasurement = recordingMeterRegistry.getRecorder() .getMeasurements(InstrumentType.LONG_COUNTER, "es.blob_cache.population.bytes.total") .get(0); assertEquals(totalBytesMeasurement.getLong(), ByteSizeValue.ofMb(mebiBytesSent).getBytes()); - assertExpectedAttributesPresent(totalBytesMeasurement, cachePopulationReason, cachePopulationSource, fileExtension); + assertExpectedAttributesPresent(totalBytesMeasurement, cachePopulationReason, cachePopulationSource, fileExtension, threadName); // time counter Measurement totalTimeMeasurement = recordingMeterRegistry.getRecorder() .getMeasurements(InstrumentType.LONG_COUNTER, "es.blob_cache.population.time.total") .get(0); assertEquals(totalTimeMeasurement.getLong(), TimeUnit.SECONDS.toMillis(secondsTaken)); - assertExpectedAttributesPresent(totalTimeMeasurement, cachePopulationReason, cachePopulationSource, fileExtension); + assertExpectedAttributesPresent(totalTimeMeasurement, cachePopulationReason, cachePopulationSource, fileExtension, threadName); // let us check for 0, avoid div by 0. checkReadsAndMisses(0, 0, 1); @@ -107,10 +109,12 @@ private static void assertExpectedAttributesPresent( Measurement measurement, BlobCacheMetrics.CachePopulationReason cachePopulationReason, CachePopulationSource cachePopulationSource, - String fileExtension + String fileExtension, + String threadName ) { assertThat(measurement.attributes().get(BlobCacheMetrics.CACHE_POPULATION_REASON_ATTRIBUTE_KEY), is(cachePopulationReason.name())); assertThat(measurement.attributes().get(BlobCacheMetrics.CACHE_POPULATION_SOURCE_ATTRIBUTE_KEY), is(cachePopulationSource.name())); assertThat(measurement.attributes().get(BlobCacheMetrics.LUCENE_FILE_EXTENSION_ATTRIBUTE_KEY), is(fileExtension)); + assertThat(measurement.attributes().get(BlobCacheMetrics.ES_EXECUTOR_ATTRIBUTE_KEY), is(threadName)); } }