Skip to content

Commit

Permalink
Add user action for repository_integrity indicator (#87920) (#87951)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidan committed Jun 23, 2022
1 parent bcb7b1d commit 783c376
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.health.HealthIndicatorService;
import org.elasticsearch.health.ImpactArea;
import org.elasticsearch.health.SimpleHealthIndicatorDetails;
import org.elasticsearch.health.UserAction;
import org.elasticsearch.repositories.RepositoryData;

import java.util.Collections;
Expand All @@ -43,6 +44,12 @@ public class RepositoryIntegrityHealthIndicatorService implements HealthIndicato
public static final String NAME = "repository_integrity";

public static final String HELP_URL = "https://ela.st/fix-repository-integrity";
public static final UserAction.Definition CORRUPTED_REPOSITORY = new UserAction.Definition(
"corrupt-repo-integrity",
"Multiple clusters are writing to the same repository. Remove the repository "
+ "from the other cluster(s), or mark it as read-only in the other cluster(s), and then re-add the repository to this cluster.",
HELP_URL
);

public static final String NO_REPOS_CONFIGURED = "No snapshot repositories configured.";
public static final String NO_CORRUPT_REPOS = "No corrupted snapshot repositories.";
Expand Down Expand Up @@ -128,7 +135,7 @@ public HealthIndicatorResult calculate(boolean explain) {
)
: HealthIndicatorDetails.EMPTY,
impacts,
Collections.emptyList()
List.of(new UserAction(CORRUPTED_REPOSITORY, corrupted))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.health.HealthIndicatorResult;
import org.elasticsearch.health.ImpactArea;
import org.elasticsearch.health.SimpleHealthIndicatorDetails;
import org.elasticsearch.health.UserAction;
import org.elasticsearch.test.ESTestCase;

import java.util.Collections;
Expand All @@ -32,6 +33,7 @@
import static org.elasticsearch.health.ServerHealthComponents.SNAPSHOT;
import static org.elasticsearch.repositories.RepositoryData.CORRUPTED_REPO_GEN;
import static org.elasticsearch.repositories.RepositoryData.EMPTY_REPO_GEN;
import static org.elasticsearch.snapshots.RepositoryIntegrityHealthIndicatorService.CORRUPTED_REPOSITORY;
import static org.elasticsearch.snapshots.RepositoryIntegrityHealthIndicatorService.NAME;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -69,6 +71,7 @@ public void testIsRedWhenAtLeastOneRepoIsCorrupted() {
var clusterState = createClusterStateWith(new RepositoriesMetadata(repos));
var service = createRepositoryCorruptionHealthIndicatorService(clusterState);

List<String> corruptedRepos = List.of("corrupted-repo");
assertThat(
service.calculate(true),
equalTo(
Expand All @@ -79,7 +82,7 @@ public void testIsRedWhenAtLeastOneRepoIsCorrupted() {
"Detected [1] corrupted snapshot repositories: [corrupted-repo].",
RepositoryIntegrityHealthIndicatorService.HELP_URL,
new SimpleHealthIndicatorDetails(
Map.of("total_repositories", repos.size(), "corrupted_repositories", 1, "corrupted", List.of("corrupted-repo"))
Map.of("total_repositories", repos.size(), "corrupted_repositories", 1, "corrupted", corruptedRepos)
),
Collections.singletonList(
new HealthIndicatorImpact(
Expand All @@ -88,7 +91,7 @@ public void testIsRedWhenAtLeastOneRepoIsCorrupted() {
List.of(ImpactArea.BACKUP)
)
),
Collections.emptyList()
List.of(new UserAction(CORRUPTED_REPOSITORY, corruptedRepos))
)
)
);
Expand Down

0 comments on commit 783c376

Please sign in to comment.