Skip to content

Commit 03558a8

Browse files
authored
Omit project ID from snapshot metrics (#133098)
1 parent db44c9d commit 03558a8

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

server/src/internalClusterTest/java/org/elasticsearch/repositories/SnapshotMetricsIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ public void testByStateCounts_InitAndQueuedShards() throws Exception {
276276
assertMetricsHaveAttributes(
277277
InstrumentType.LONG_GAUGE,
278278
SnapshotMetrics.SNAPSHOT_SHARDS_BY_STATE,
279-
Map.of("project_id", ProjectId.DEFAULT.id(), "repo_name", repositoryName, "repo_type", "mock")
279+
Map.of("repo_name", repositoryName, "repo_type", "mock")
280280
);
281281
assertMetricsHaveAttributes(
282282
InstrumentType.LONG_GAUGE,
283283
SnapshotMetrics.SNAPSHOTS_BY_STATE,
284-
Map.of("project_id", ProjectId.DEFAULT.id(), "repo_name", repositoryName, "repo_type", "mock")
284+
Map.of("repo_name", repositoryName, "repo_type", "mock")
285285
);
286286
}
287287

@@ -345,12 +345,12 @@ public void testByStateCounts_PausedForRemovalShards() throws Exception {
345345
assertMetricsHaveAttributes(
346346
InstrumentType.LONG_GAUGE,
347347
SnapshotMetrics.SNAPSHOT_SHARDS_BY_STATE,
348-
Map.of("project_id", ProjectId.DEFAULT.id(), "repo_name", repositoryName, "repo_type", "mock")
348+
Map.of("repo_name", repositoryName, "repo_type", "mock")
349349
);
350350
assertMetricsHaveAttributes(
351351
InstrumentType.LONG_GAUGE,
352352
SnapshotMetrics.SNAPSHOTS_BY_STATE,
353-
Map.of("project_id", ProjectId.DEFAULT.id(), "repo_name", repositoryName, "repo_type", "mock")
353+
Map.of("repo_name", repositoryName, "repo_type", "mock")
354354
);
355355
}
356356

@@ -421,12 +421,12 @@ public void testByStateCounts_WaitingShards() throws Exception {
421421
assertMetricsHaveAttributes(
422422
InstrumentType.LONG_GAUGE,
423423
SnapshotMetrics.SNAPSHOT_SHARDS_BY_STATE,
424-
Map.of("project_id", ProjectId.DEFAULT.id(), "repo_name", repositoryName, "repo_type", "mock")
424+
Map.of("repo_name", repositoryName, "repo_type", "mock")
425425
);
426426
assertMetricsHaveAttributes(
427427
InstrumentType.LONG_GAUGE,
428428
SnapshotMetrics.SNAPSHOTS_BY_STATE,
429-
Map.of("project_id", ProjectId.DEFAULT.id(), "repo_name", repositoryName, "repo_type", "mock")
429+
Map.of("repo_name", repositoryName, "repo_type", "mock")
430430
);
431431
}
432432

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.cluster.metadata.ProjectId;
1313
import org.elasticsearch.cluster.metadata.RepositoryMetadata;
14+
import org.elasticsearch.core.FixForMultiProject;
1415
import org.elasticsearch.telemetry.metric.DoubleHistogram;
1516
import org.elasticsearch.telemetry.metric.LongCounter;
1617
import org.elasticsearch.telemetry.metric.LongWithAttributes;
@@ -93,8 +94,8 @@ public void createSnapshotsByStateMetric(Supplier<Collection<LongWithAttributes>
9394
meterRegistry.registerLongsGauge(SNAPSHOTS_BY_STATE, "snapshots by state", "unit", snapshotsByStatusObserver);
9495
}
9596

97+
@FixForMultiProject(description = "When multi-project arrives we should add project ID to the labels")
9698
public static Map<String, Object> createAttributesMap(ProjectId projectId, RepositoryMetadata meta) {
97-
assert projectId != null : "Project ID should always be set";
98-
return Map.of("project_id", projectId.id(), "repo_type", meta.type(), "repo_name", meta.name());
99+
return Map.of("repo_type", meta.type(), "repo_name", meta.name());
99100
}
100101
}

0 commit comments

Comments
 (0)