From aa7a6fc02609922582f92a478630c71a534d52c6 Mon Sep 17 00:00:00 2001 From: Jeremy Dahlgren Date: Mon, 11 Aug 2025 15:14:06 -0400 Subject: [PATCH] Fix race condition in SnapshotMetricsIT.testSnapshotAPMMetrics Moves the new code that updates the snapshot completed metrics to before the snapshot listeners are completed. This mirrors how the listener is completed after the snapshot started metric is updated. Resolves: #132672 --- muted-tests.yml | 3 --- .../java/org/elasticsearch/snapshots/SnapshotsService.java | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index e5410199d4106..e34ffd493ea58 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -527,9 +527,6 @@ tests: - class: org.elasticsearch.xpack.sql.action.SqlSearchPageTimeoutIT method: testSearchContextIsCleanedUpAfterPageTimeoutForAggregationQueries issue: https://github.com/elastic/elasticsearch/issues/132619 -- class: org.elasticsearch.repositories.SnapshotMetricsIT - method: testSnapshotAPMMetrics - issue: https://github.com/elastic/elasticsearch/issues/132672 # Examples: # diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index 87ba959b0ebf2..f28d4948f657a 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -1232,7 +1232,6 @@ protected void doRun() { () -> snapshotListeners.addListener(new ActionListener<>() { @Override public void onResponse(List> actionListeners) { - SnapshotsServiceUtils.completeListenersIgnoringException(actionListeners, snapshotInfo); final Map attributesWithState = Maps.copyMapWithAddedEntry( SnapshotMetrics.createAttributesMap(snapshot.getProjectId(), repo.getMetadata()), "state", @@ -1241,6 +1240,7 @@ public void onResponse(List> actionListeners) { snapshotMetrics.snapshotsCompletedCounter().incrementBy(1, attributesWithState); snapshotMetrics.snapshotsDurationHistogram() .record((snapshotInfo.endTime() - snapshotInfo.startTime()) / 1_000.0, attributesWithState); + SnapshotsServiceUtils.completeListenersIgnoringException(actionListeners, snapshotInfo); logger.info("snapshot [{}] completed with state [{}]", snapshot, snapshotInfo.state()); }