Skip to content

Commit ac2a2a3

Browse files
committed
Don't track stats when project ID is null
1 parent 50eb8ad commit ac2a2a3

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

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

1212
import org.elasticsearch.cluster.metadata.ProjectId;
1313
import org.elasticsearch.cluster.metadata.RepositoryMetadata;
14-
import org.elasticsearch.core.Nullable;
1514
import org.elasticsearch.telemetry.metric.DoubleHistogram;
1615
import org.elasticsearch.telemetry.metric.LongCounter;
1716
import org.elasticsearch.telemetry.metric.LongWithAttributes;
@@ -85,11 +84,8 @@ public void createSnapshotsInProgressMetric(Supplier<Collection<LongWithAttribut
8584
meterRegistry.registerLongsGauge(SNAPSHOTS_IN_PROGRESS, "snapshots in progress", "unit", snapshotsInProgressObserver);
8685
}
8786

88-
public static Map<String, Object> createAttributesMap(@Nullable ProjectId projectId, RepositoryMetadata meta) {
89-
if (projectId == null) {
90-
return Map.of("repo_type", meta.type(), "repo_name", meta.name());
91-
} else {
92-
return Map.of("project_id", projectId.id(), "repo_type", meta.type(), "repo_name", meta.name());
93-
}
87+
public static Map<String, Object> createAttributesMap(ProjectId projectId, RepositoryMetadata meta) {
88+
assert projectId != null : "Project ID should always be set";
89+
return Map.of("project_id", projectId.id(), "repo_type", meta.type(), "repo_name", meta.name());
9490
}
9591
}

server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreSnapshotMetrics.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ public class BlobStoreSnapshotMetrics {
3636
private final Map<String, Object> metricAttributes;
3737

3838
public BlobStoreSnapshotMetrics(@Nullable ProjectId projectId, RepositoryMetadata repositoryMetadata, SnapshotMetrics snapshotMetrics) {
39-
this.snapshotMetrics = snapshotMetrics;
40-
metricAttributes = SnapshotMetrics.createAttributesMap(projectId, repositoryMetadata);
39+
if (projectId != null) {
40+
this.snapshotMetrics = snapshotMetrics;
41+
metricAttributes = SnapshotMetrics.createAttributesMap(projectId, repositoryMetadata);
42+
} else {
43+
// Project ID should only be null for the stateless main blobstore, which is not used for snapshots
44+
this.snapshotMetrics = SnapshotMetrics.NOOP;
45+
this.metricAttributes = Map.of();
46+
}
4147
}
4248

4349
public void incrementSnapshotRateLimitingTimeInNanos(long throttleTimeNanos) {

0 commit comments

Comments
 (0)