Skip to content

Commit d87a1a2

Browse files
authored
Restore repo_name label to repository metrics (#117114)
1 parent eff0c42 commit d87a1a2

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

modules/repository-azure/src/internalClusterTest/java/org/elasticsearch/repositories/azure/AzureBlobStoreRepositoryMetricsTests.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void testThrottleResponsesAreCountedInMetrics() throws IOException {
112112
blobContainer.blobExists(purpose, blobName);
113113

114114
// Correct metrics are recorded
115-
metricsAsserter(dataNodeName, purpose, AzureBlobStore.Operation.GET_BLOB_PROPERTIES).expectMetrics()
115+
metricsAsserter(dataNodeName, purpose, AzureBlobStore.Operation.GET_BLOB_PROPERTIES, repository).expectMetrics()
116116
.withRequests(numThrottles + 1)
117117
.withThrottles(numThrottles)
118118
.withExceptions(numThrottles)
@@ -137,7 +137,7 @@ public void testRangeNotSatisfiedAreCountedInMetrics() throws IOException {
137137
assertThrows(RequestedRangeNotSatisfiedException.class, () -> blobContainer.readBlob(purpose, blobName));
138138

139139
// Correct metrics are recorded
140-
metricsAsserter(dataNodeName, purpose, AzureBlobStore.Operation.GET_BLOB).expectMetrics()
140+
metricsAsserter(dataNodeName, purpose, AzureBlobStore.Operation.GET_BLOB, repository).expectMetrics()
141141
.withRequests(1)
142142
.withThrottles(0)
143143
.withExceptions(1)
@@ -170,7 +170,7 @@ public void testErrorResponsesAreCountedInMetrics() throws IOException {
170170
blobContainer.blobExists(purpose, blobName);
171171

172172
// Correct metrics are recorded
173-
metricsAsserter(dataNodeName, purpose, AzureBlobStore.Operation.GET_BLOB_PROPERTIES).expectMetrics()
173+
metricsAsserter(dataNodeName, purpose, AzureBlobStore.Operation.GET_BLOB_PROPERTIES, repository).expectMetrics()
174174
.withRequests(numErrors + 1)
175175
.withThrottles(throttles.get())
176176
.withExceptions(numErrors)
@@ -191,7 +191,7 @@ public void testRequestFailuresAreCountedInMetrics() {
191191
assertThrows(IOException.class, () -> blobContainer.listBlobs(purpose));
192192

193193
// Correct metrics are recorded
194-
metricsAsserter(dataNodeName, purpose, AzureBlobStore.Operation.LIST_BLOBS).expectMetrics()
194+
metricsAsserter(dataNodeName, purpose, AzureBlobStore.Operation.LIST_BLOBS, repository).expectMetrics()
195195
.withRequests(4)
196196
.withThrottles(0)
197197
.withExceptions(4)
@@ -322,14 +322,20 @@ private void clearMetrics(String discoveryNode) {
322322
.forEach(TestTelemetryPlugin::resetMeter);
323323
}
324324

325-
private MetricsAsserter metricsAsserter(String dataNodeName, OperationPurpose operationPurpose, AzureBlobStore.Operation operation) {
326-
return new MetricsAsserter(dataNodeName, operationPurpose, operation);
325+
private MetricsAsserter metricsAsserter(
326+
String dataNodeName,
327+
OperationPurpose operationPurpose,
328+
AzureBlobStore.Operation operation,
329+
String repository
330+
) {
331+
return new MetricsAsserter(dataNodeName, operationPurpose, operation, repository);
327332
}
328333

329334
private class MetricsAsserter {
330335
private final String dataNodeName;
331336
private final OperationPurpose purpose;
332337
private final AzureBlobStore.Operation operation;
338+
private final String repository;
333339

334340
enum Result {
335341
Success,
@@ -355,10 +361,11 @@ List<Measurement> getMeasurements(TestTelemetryPlugin testTelemetryPlugin, Strin
355361
abstract List<Measurement> getMeasurements(TestTelemetryPlugin testTelemetryPlugin, String name);
356362
}
357363

358-
private MetricsAsserter(String dataNodeName, OperationPurpose purpose, AzureBlobStore.Operation operation) {
364+
private MetricsAsserter(String dataNodeName, OperationPurpose purpose, AzureBlobStore.Operation operation, String repository) {
359365
this.dataNodeName = dataNodeName;
360366
this.purpose = purpose;
361367
this.operation = operation;
368+
this.repository = repository;
362369
}
363370

364371
private class Expectations {
@@ -451,6 +458,7 @@ private void assertMatchingMetricRecorded(MetricType metricType, String metricNa
451458
.filter(
452459
m -> m.attributes().get("operation").equals(operation.getKey())
453460
&& m.attributes().get("purpose").equals(purpose.getKey())
461+
&& m.attributes().get("repo_name").equals(repository)
454462
&& m.attributes().get("repo_type").equals("azure")
455463
)
456464
.findFirst()
@@ -462,6 +470,8 @@ private void assertMatchingMetricRecorded(MetricType metricType, String metricNa
462470
+ operation.getKey()
463471
+ " and purpose="
464472
+ purpose.getKey()
473+
+ " and repo_name="
474+
+ repository
465475
+ " in "
466476
+ measurements
467477
)

modules/repository-azure/src/internalClusterTest/java/org/elasticsearch/repositories/azure/AzureBlobStoreRepositoryTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,10 @@ public void testMetrics() throws Exception {
402402
)
403403
);
404404
metrics.forEach(metric -> {
405-
assertThat(metric.attributes(), allOf(hasEntry("repo_type", AzureRepository.TYPE), hasKey("operation"), hasKey("purpose")));
405+
assertThat(
406+
metric.attributes(),
407+
allOf(hasEntry("repo_type", AzureRepository.TYPE), hasKey("repo_name"), hasKey("operation"), hasKey("purpose"))
408+
);
406409
final AzureBlobStore.Operation operation = AzureBlobStore.Operation.fromKey((String) metric.attributes().get("operation"));
407410
final AzureBlobStore.StatsKey statsKey = new AzureBlobStore.StatsKey(
408411
operation,

modules/repository-s3/src/internalClusterTest/java/org/elasticsearch/repositories/s3/S3BlobStoreRepositoryTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ public void testMetrics() throws Exception {
300300
)
301301
);
302302
metrics.forEach(metric -> {
303-
assertThat(metric.attributes(), allOf(hasEntry("repo_type", S3Repository.TYPE), hasKey("operation"), hasKey("purpose")));
303+
assertThat(
304+
metric.attributes(),
305+
allOf(hasEntry("repo_type", S3Repository.TYPE), hasKey("repo_name"), hasKey("operation"), hasKey("purpose"))
306+
);
304307
final S3BlobStore.Operation operation = S3BlobStore.Operation.parse((String) metric.attributes().get("operation"));
305308
final S3BlobStore.StatsKey statsKey = new S3BlobStore.StatsKey(
306309
operation,

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3RetryingInputStream.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ private Map<String, Object> metricAttributes(String action) {
327327
return Map.of(
328328
"repo_type",
329329
S3Repository.TYPE,
330+
"repo_name",
331+
blobStore.getRepositoryMetadata().name(),
330332
"operation",
331333
Operation.GET_OBJECT.getKey(),
332334
"purpose",

modules/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3BlobContainerRetriesTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ private List<Measurement> getRetryHistogramMeasurements() {
11061106
}
11071107

11081108
private Map<String, Object> metricAttributes(String action) {
1109-
return Map.of("repo_type", "s3", "operation", "GetObject", "purpose", "Indices", "action", action);
1109+
return Map.of("repo_type", "s3", "repo_name", "repository", "operation", "GetObject", "purpose", "Indices", "action", action);
11101110
}
11111111

11121112
/**

server/src/main/java/org/elasticsearch/repositories/RepositoriesMetrics.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,16 @@ public static Map<String, Object> createAttributesMap(
127127
OperationPurpose purpose,
128128
String operation
129129
) {
130-
return Map.of("repo_type", repositoryMetadata.type(), "operation", operation, "purpose", purpose.getKey());
130+
return Map.of(
131+
"repo_type",
132+
repositoryMetadata.type(),
133+
"repo_name",
134+
repositoryMetadata.name(),
135+
"operation",
136+
operation,
137+
"purpose",
138+
purpose.getKey()
139+
);
131140
}
132141

133142
}

0 commit comments

Comments
 (0)