forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional BlobCacheMetrics, expose BlobCacheMetrics via SharedBl…
…obCacheService (elastic#111730) Relates: ES-9067
- Loading branch information
1 parent
1ba0ef7
commit 76755be
Showing
4 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ck/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/CachePopulationSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.blobcache; | ||
|
||
/** | ||
* The places we populate the cache from | ||
*/ | ||
public enum CachePopulationSource { | ||
/** | ||
* When loading data from the blob-store | ||
*/ | ||
BlobStore, | ||
/** | ||
* When fetching data from a peer node | ||
*/ | ||
Peer, | ||
/** | ||
* We cannot determine the source (should not be used except in exceptional cases) | ||
*/ | ||
Unknown | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...ck/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/BlobCacheMetricsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.blobcache; | ||
|
||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.telemetry.InstrumentType; | ||
import org.elasticsearch.telemetry.Measurement; | ||
import org.elasticsearch.telemetry.RecordingMeterRegistry; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.junit.Before; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class BlobCacheMetricsTests extends ESTestCase { | ||
|
||
private RecordingMeterRegistry recordingMeterRegistry; | ||
private BlobCacheMetrics metrics; | ||
|
||
@Before | ||
public void createMetrics() { | ||
recordingMeterRegistry = new RecordingMeterRegistry(); | ||
metrics = new BlobCacheMetrics(recordingMeterRegistry); | ||
} | ||
|
||
public void testRecordCachePopulationMetricsRecordsThroughput() { | ||
int mebiBytesSent = randomIntBetween(1, 4); | ||
int secondsTaken = randomIntBetween(1, 5); | ||
String indexName = randomIdentifier(); | ||
int shardId = randomIntBetween(0, 10); | ||
BlobCacheMetrics.CachePopulationReason cachePopulationReason = randomFrom(BlobCacheMetrics.CachePopulationReason.values()); | ||
CachePopulationSource cachePopulationSource = randomFrom(CachePopulationSource.values()); | ||
metrics.recordCachePopulationMetrics( | ||
Math.toIntExact(ByteSizeValue.ofMb(mebiBytesSent).getBytes()), | ||
TimeUnit.SECONDS.toNanos(secondsTaken), | ||
indexName, | ||
shardId, | ||
cachePopulationReason, | ||
cachePopulationSource | ||
); | ||
|
||
// 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, shardId, indexName, cachePopulationReason, cachePopulationSource); | ||
|
||
// 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, shardId, indexName, cachePopulationReason, cachePopulationSource); | ||
|
||
// 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, shardId, indexName, cachePopulationReason, cachePopulationSource); | ||
} | ||
|
||
private static void assertExpectedAttributesPresent( | ||
Measurement measurement, | ||
int shardId, | ||
String indexName, | ||
BlobCacheMetrics.CachePopulationReason cachePopulationReason, | ||
CachePopulationSource cachePopulationSource | ||
) { | ||
assertEquals(measurement.attributes().get(BlobCacheMetrics.SHARD_ID_ATTRIBUTE_KEY), shardId); | ||
assertEquals(measurement.attributes().get(BlobCacheMetrics.INDEX_ATTRIBUTE_KEY), indexName); | ||
assertEquals(measurement.attributes().get(BlobCacheMetrics.CACHE_POPULATION_REASON_ATTRIBUTE_KEY), cachePopulationReason.name()); | ||
assertEquals(measurement.attributes().get(BlobCacheMetrics.CACHE_POPULATION_SOURCE_ATTRIBUTE_KEY), cachePopulationSource.name()); | ||
} | ||
} |