Skip to content

Commit d808b85

Browse files
committed
Fix naming, record shard duration as histogram
1 parent b4c926f commit d808b85

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.repositories;
1111

1212
import org.elasticsearch.cluster.metadata.RepositoryMetadata;
13+
import org.elasticsearch.telemetry.metric.DoubleHistogram;
1314
import org.elasticsearch.telemetry.metric.LongCounter;
1415
import org.elasticsearch.telemetry.metric.LongGauge;
1516
import org.elasticsearch.telemetry.metric.LongWithAttributes;
@@ -21,9 +22,10 @@
2122
import java.util.function.Supplier;
2223

2324
public record SnapshotMetrics(
24-
LongCounter snapshotsStartedCounter,
25-
LongCounter snapshotsCompletedCounter,
26-
LongGauge snapshotsInProgressGauge,
25+
LongCounter snapshotsShardsStartedCounter,
26+
LongCounter snapshotsShardsCompletedCounter,
27+
LongGauge snapshotShardsInProgressGauge,
28+
DoubleHistogram snapshotShardsDurationHistogram,
2729
LongCounter snapshotBlobsUploadedCounter,
2830
LongCounter snapshotBytesUploadedCounter,
2931
LongCounter snapshotUploadDurationCounter,
@@ -34,9 +36,10 @@ public record SnapshotMetrics(
3436

3537
public static final SnapshotMetrics NOOP = new SnapshotMetrics(MeterRegistry.NOOP, List::of);
3638

37-
public static final String SNAPSHOTS_STARTED = "es.repositories.snapshots.started.total";
38-
public static final String SNAPSHOTS_COMPLETED = "es.repositories.snapshots.completed.total";
39-
public static final String SNAPSHOTS_IN_PROGRESS = "es.repositories.snapshots.current";
39+
public static final String SNAPSHOT_SHARDS_STARTED = "es.repositories.snapshots.shards.started.total";
40+
public static final String SNAPSHOT_SHARDS_COMPLETED = "es.repositories.snapshots.shards.completed.total";
41+
public static final String SNAPSHOT_SHARDS_IN_PROGRESS = "es.repositories.snapshots.shards.current";
42+
public static final String SNAPSHOT_SHARDS_DURATION = "es.repositories.snapshots.shards.duration.histogram";
4043
public static final String SNAPSHOT_BLOBS_UPLOADED = "es.repositories.snapshots.blobs.uploaded.total";
4144
public static final String SNAPSHOT_BYTES_UPLOADED = "es.repositories.snapshots.upload.bytes.total";
4245
public static final String SNAPSHOT_UPLOAD_DURATION = "es.repositories.snapshots.upload.upload_time.total";
@@ -46,14 +49,15 @@ public record SnapshotMetrics(
4649

4750
public SnapshotMetrics(MeterRegistry meterRegistry, Supplier<Collection<LongWithAttributes>> shardSnapshotsInProgressObserver) {
4851
this(
49-
meterRegistry.registerLongCounter(SNAPSHOTS_STARTED, "shard snapshots started", "unit"),
50-
meterRegistry.registerLongCounter(SNAPSHOTS_COMPLETED, "shard snapshots completed", "unit"),
52+
meterRegistry.registerLongCounter(SNAPSHOT_SHARDS_STARTED, "shard snapshots started", "unit"),
53+
meterRegistry.registerLongCounter(SNAPSHOT_SHARDS_COMPLETED, "shard snapshots completed", "unit"),
5154
meterRegistry.registerLongsGauge(
52-
SNAPSHOTS_IN_PROGRESS,
55+
SNAPSHOT_SHARDS_IN_PROGRESS,
5356
"shard snapshots in progress",
5457
"unit",
5558
shardSnapshotsInProgressObserver
5659
),
60+
meterRegistry.registerDoubleHistogram(SNAPSHOT_SHARDS_DURATION, "shard snapshots duration", "s"),
5761
meterRegistry.registerLongCounter(SNAPSHOT_BLOBS_UPLOADED, "snapshot blobs uploaded", "unit"),
5862
meterRegistry.registerLongCounter(SNAPSHOT_BYTES_UPLOADED, "snapshot bytes uploaded", "bytes"),
5963
meterRegistry.registerLongCounter(SNAPSHOT_UPLOAD_DURATION, "snapshot upload duration", "ns"),

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,8 +3214,13 @@ public void snapshotShard(SnapshotShardContext context) {
32143214
}
32153215

32163216
private void doSnapshotShard(SnapshotShardContext context) {
3217+
final long startTimeInMillis = threadPool.absoluteTimeInMillis();
32173218
blobStoreSnapshotMetrics.shardSnapshotStarted();
3218-
context.addListener(ActionListener.running(blobStoreSnapshotMetrics::shardSnapshotCompleted));
3219+
context.addListener(
3220+
ActionListener.running(
3221+
() -> blobStoreSnapshotMetrics.shardSnapshotCompleted(threadPool.absoluteTimeInMillis() - startTimeInMillis)
3222+
)
3223+
);
32193224
if (isReadOnly()) {
32203225
context.onFailure(new RepositoryException(metadata.name(), "cannot snapshot shard on a readonly repository"));
32213226
return;
@@ -3225,7 +3230,6 @@ private void doSnapshotShard(SnapshotShardContext context) {
32253230
final SnapshotId snapshotId = context.snapshotId();
32263231
final IndexShardSnapshotStatus snapshotStatus = context.status();
32273232
snapshotStatus.updateStatusDescription("snapshot task runner: setting up shard snapshot");
3228-
final long startTime = threadPool.absoluteTimeInMillis();
32293233
try {
32303234
final ShardGeneration generation = snapshotStatus.generation();
32313235
final BlobContainer shardContainer = shardContainer(context.indexId(), shardId);
@@ -3347,7 +3351,7 @@ private void doSnapshotShard(SnapshotShardContext context) {
33473351

33483352
snapshotStatus.updateStatusDescription("snapshot task runner: starting shard snapshot");
33493353
snapshotStatus.moveToStarted(
3350-
startTime,
3354+
startTimeInMillis,
33513355
indexIncrementalFileCount,
33523356
indexTotalNumberOfFiles,
33533357
indexIncrementalSize,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ public void incrementNumberOfBlobsUploaded() {
6666
}
6767

6868
public void shardSnapshotStarted() {
69-
snapshotMetrics.snapshotsStartedCounter().increment();
69+
snapshotMetrics.snapshotsShardsStartedCounter().increment();
7070
numberOfShardSnapshotsStarted.inc();
7171
shardSnapshotsInProgress.inc();
7272
}
7373

74-
public void shardSnapshotCompleted() {
75-
snapshotMetrics.snapshotsCompletedCounter().increment();
74+
public void shardSnapshotCompleted(long durationInMillis) {
75+
snapshotMetrics.snapshotsShardsCompletedCounter().increment();
76+
snapshotMetrics.snapshotShardsDurationHistogram().record(durationInMillis / 1_000f);
7677
numberOfShardSnapshotsCompleted.inc();
7778
shardSnapshotsInProgress.dec();
7879
}

0 commit comments

Comments
 (0)