Browse Source

Describe delete-snapshot tasks (#93466)

Delete-snapshot tasks can sometimes be very long-running, but they're
hard to monitor because the tasks API does not include a description of
the snapshot(s) which are being deleted. This commit adds such a
description.
David Turner 2 years ago
parent
commit
7adeb48fc7

+ 13 - 0
server/src/internalClusterTest/java/org/elasticsearch/snapshots/RepositoriesIT.java

@@ -11,6 +11,7 @@ import org.elasticsearch.ExceptionsHelper;
 import org.elasticsearch.action.ActionFuture;
 import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse;
 import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
+import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotAction;
 import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
 import org.elasticsearch.action.support.master.AcknowledgedResponse;
 import org.elasticsearch.client.internal.Client;
@@ -274,6 +275,18 @@ public class RepositoriesIT extends AbstractSnapshotIntegTestCase {
         logger.info("--> waiting for block to kick in on node [{}]", blockedNode);
         waitForBlock(blockedNode, repo);
 
+        assertTrue(
+            client().admin()
+                .cluster()
+                .prepareListTasks()
+                .setActions(DeleteSnapshotAction.NAME)
+                .setDetailed(true)
+                .get()
+                .getTasks()
+                .stream()
+                .anyMatch(ti -> ("[" + repo + "][" + snapshot1 + "]").equals(ti.description()))
+        );
+
         logger.info("--> try deleting the repository, should fail because the deletion of the snapshot is in progress");
         RepositoryConflictException e1 = expectThrows(
             RepositoryConflictException.class,

+ 7 - 0
server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotRequest.java

@@ -10,10 +10,12 @@ package org.elasticsearch.action.admin.cluster.snapshots.delete;
 
 import org.elasticsearch.action.ActionRequestValidationException;
 import org.elasticsearch.action.support.master.MasterNodeRequest;
+import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 
 import java.io.IOException;
+import java.util.Arrays;
 
 import static org.elasticsearch.action.ValidateActions.addValidationError;
 
@@ -111,4 +113,9 @@ public class DeleteSnapshotRequest extends MasterNodeRequest<DeleteSnapshotReque
         this.snapshots = snapshots;
         return this;
     }
+
+    @Override
+    public String getDescription() {
+        return Strings.format("[%s]%s", repository, Arrays.toString(snapshots));
+    }
 }