|
@@ -105,7 +105,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
),
|
|
|
List.of()
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -135,7 +135,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
),
|
|
|
List.of()
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -175,7 +175,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of(index("red-index", new ShardAllocation(randomNodeId(), UNAVAILABLE), new ShardAllocation(randomNodeId(), AVAILABLE))),
|
|
|
List.of()
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -203,7 +203,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
|
|
|
public void testShouldBeRedWhenThereAreUnassignedPrimariesAndNoReplicas() {
|
|
|
var clusterState = createClusterStateWith(List.of(index("red-index", new ShardAllocation(randomNodeId(), UNAVAILABLE))), List.of());
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -234,7 +234,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of(index("red-index", new ShardAllocation(randomNodeId(), UNAVAILABLE), new ShardAllocation(randomNodeId(), UNAVAILABLE))),
|
|
|
List.of()
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
HealthIndicatorResult result = service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO);
|
|
|
assertEquals(RED, result.status());
|
|
@@ -266,7 +266,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of(),
|
|
|
List.of()
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
HealthIndicatorResult result = service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO);
|
|
|
assertEquals(RED, result.status());
|
|
@@ -314,7 +314,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of(),
|
|
|
List.of()
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
HealthIndicatorResult result = service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO);
|
|
|
// index-2 has the higher priority so it ought to be listed first, followed by index-1 then index-3 which have the same priority:
|
|
@@ -344,7 +344,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
),
|
|
|
List.of(new NodeShutdown("node-0", RESTART, 60))
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -365,7 +365,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of(index("primaries-only-index", new ShardAllocation(randomNodeId(), AVAILABLE))),
|
|
|
List.of(new NodeShutdown("node-0", RESTART, 60))
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -392,7 +392,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
),
|
|
|
List.of(new NodeShutdown("node-0", RESTART, 60))
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -427,7 +427,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of(index("restarting-index", new ShardAllocation("node-0", INITIALIZING))),
|
|
|
List.of()
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -448,7 +448,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of(index("restarting-index", new ShardAllocation("node-0", RESTARTING, System.nanoTime()))),
|
|
|
List.of(new NodeShutdown("node-0", RESTART, 60))
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -474,7 +474,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
),
|
|
|
List.of(new NodeShutdown("node-0", RESTART, 60))
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(true, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -519,7 +519,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of()
|
|
|
);
|
|
|
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
|
|
|
assertThat(
|
|
|
service.calculate(false, HealthInfo.EMPTY_HEALTH_INFO),
|
|
@@ -555,7 +555,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
new ShardAllocation(randomNodeId(), UNAVAILABLE, noShardCopy())
|
|
|
);
|
|
|
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
List<Diagnosis.Definition> definitions = service.diagnoseUnassignedShardRouting(shardRouting, ClusterState.EMPTY_STATE);
|
|
|
|
|
|
assertThat(definitions, hasSize(1));
|
|
@@ -601,7 +601,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
MoveDecision.NOT_TAKEN
|
|
|
)
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService(clusterState, decisionMap);
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState, decisionMap);
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
ShardRouting shardRouting = clusterState.routingTable().index(indexMetadata.getIndex()).shard(0).primaryShard();
|
|
@@ -624,7 +624,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
.numberOfReplicas(0)
|
|
|
.build();
|
|
|
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
List<Diagnosis.Definition> actions = service.checkIsAllocationDisabled(
|
|
@@ -652,7 +652,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
.build();
|
|
|
|
|
|
// Disallow allocations in cluster settings
|
|
|
- var service = createAllocationHealthIndicatorService(
|
|
|
+ var service = createShardsAvailabilityIndicatorService(
|
|
|
Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none").build(),
|
|
|
ClusterState.EMPTY_STATE,
|
|
|
Map.of()
|
|
@@ -689,7 +689,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
.build();
|
|
|
|
|
|
// Disallow allocations in cluster settings
|
|
|
- var service = createAllocationHealthIndicatorService(
|
|
|
+ var service = createShardsAvailabilityIndicatorService(
|
|
|
Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none").build(),
|
|
|
ClusterState.EMPTY_STATE,
|
|
|
Map.of()
|
|
@@ -726,7 +726,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
.numberOfReplicas(0)
|
|
|
.build();
|
|
|
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
List<Diagnosis.Definition> actions = service.checkDataTierRelatedIssues(
|
|
@@ -785,7 +785,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of(),
|
|
|
List.of(hotNode)
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
List<Diagnosis.Definition> actions = service.checkDataTierRelatedIssues(
|
|
@@ -846,7 +846,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
);
|
|
|
|
|
|
// Configure at most 1 shard per node
|
|
|
- var service = createAllocationHealthIndicatorService(
|
|
|
+ var service = createShardsAvailabilityIndicatorService(
|
|
|
Settings.builder().put(CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING.getKey(), 1).build(),
|
|
|
clusterState,
|
|
|
Map.of()
|
|
@@ -910,7 +910,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
List.of(),
|
|
|
List.of(dataNode)
|
|
|
);
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
List<Diagnosis.Definition> actions = service.checkDataTierRelatedIssues(
|
|
@@ -971,7 +971,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
);
|
|
|
|
|
|
// Configure at most 1 shard per node
|
|
|
- var service = createAllocationHealthIndicatorService(
|
|
|
+ var service = createShardsAvailabilityIndicatorService(
|
|
|
Settings.builder().put(CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING.getKey(), 1).build(),
|
|
|
clusterState,
|
|
|
Map.of()
|
|
@@ -1010,7 +1010,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
.numberOfReplicas(0)
|
|
|
.build();
|
|
|
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
List<Diagnosis.Definition> actions = service.checkDataTierRelatedIssues(
|
|
@@ -1046,7 +1046,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
.numberOfReplicas(0)
|
|
|
.build();
|
|
|
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
List<Diagnosis.Definition> actions = service.checkDataTierRelatedIssues(
|
|
@@ -1081,7 +1081,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
.numberOfReplicas(0)
|
|
|
.build();
|
|
|
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
List<Diagnosis.Definition> actions = service.checkDataTierRelatedIssues(
|
|
@@ -1116,7 +1116,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
.numberOfReplicas(0)
|
|
|
.build();
|
|
|
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
List<Diagnosis.Definition> actions = service.checkDataTierRelatedIssues(
|
|
@@ -1156,7 +1156,7 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
.numberOfReplicas(0)
|
|
|
.build();
|
|
|
|
|
|
- var service = createAllocationHealthIndicatorService();
|
|
|
+ var service = createShardsAvailabilityIndicatorService();
|
|
|
|
|
|
// Get the list of user actions that are generated for this unassigned index shard
|
|
|
List<Diagnosis.Definition> actions = service.checkDataTierRelatedIssues(
|
|
@@ -1183,6 +1183,76 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
assertThat(actions, contains(ACTION_INCREASE_NODE_CAPACITY));
|
|
|
}
|
|
|
|
|
|
+ public void testLimitNumberOfAffectedResources() {
|
|
|
+ var clusterState = createClusterStateWith(
|
|
|
+ List.of(
|
|
|
+ index("red-index1", new ShardAllocation(randomNodeId(), UNAVAILABLE), new ShardAllocation(randomNodeId(), AVAILABLE)),
|
|
|
+ index("red-index2", new ShardAllocation(randomNodeId(), UNAVAILABLE), new ShardAllocation(randomNodeId(), AVAILABLE)),
|
|
|
+ index("red-index3", new ShardAllocation(randomNodeId(), UNAVAILABLE), new ShardAllocation(randomNodeId(), AVAILABLE)),
|
|
|
+ index("red-index4", new ShardAllocation(randomNodeId(), UNAVAILABLE), new ShardAllocation(randomNodeId(), AVAILABLE)),
|
|
|
+ index("red-index5", new ShardAllocation(randomNodeId(), UNAVAILABLE), new ShardAllocation(randomNodeId(), AVAILABLE))
|
|
|
+ ),
|
|
|
+ List.of()
|
|
|
+ );
|
|
|
+ var service = createShardsAvailabilityIndicatorService(clusterState);
|
|
|
+
|
|
|
+ {
|
|
|
+ // assert the full result to check that details, impacts, and symptoms use the correct count of affected indices (5)
|
|
|
+ assertThat(
|
|
|
+ service.calculate(true, 2, HealthInfo.EMPTY_HEALTH_INFO),
|
|
|
+ equalTo(
|
|
|
+ createExpectedResult(
|
|
|
+ RED,
|
|
|
+ "This cluster has 5 unavailable primary shards.",
|
|
|
+ Map.of("unassigned_primaries", 5, "started_replicas", 5),
|
|
|
+ List.of(
|
|
|
+ new HealthIndicatorImpact(
|
|
|
+ NAME,
|
|
|
+ ShardsAvailabilityHealthIndicatorService.PRIMARY_UNASSIGNED_IMPACT_ID,
|
|
|
+ 1,
|
|
|
+ "Cannot add data to 5 indices [red-index1, red-index2, red-index3, red-index4, red-index5]. Searches might "
|
|
|
+ + "return incomplete results.",
|
|
|
+ List.of(ImpactArea.INGEST, ImpactArea.SEARCH)
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ List.of(
|
|
|
+ new Diagnosis(
|
|
|
+ ACTION_CHECK_ALLOCATION_EXPLAIN_API,
|
|
|
+ List.of(new Diagnosis.Resource(INDEX, List.of("red-index1", "red-index2")))
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ // larger number of affected resources
|
|
|
+ assertThat(
|
|
|
+ service.calculate(true, 2_000, HealthInfo.EMPTY_HEALTH_INFO).diagnosisList(),
|
|
|
+ equalTo(
|
|
|
+ List.of(
|
|
|
+ new Diagnosis(
|
|
|
+ ACTION_CHECK_ALLOCATION_EXPLAIN_API,
|
|
|
+ List.of(
|
|
|
+ new Diagnosis.Resource(INDEX, List.of("red-index1", "red-index2", "red-index3", "red-index4", "red-index5"))
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ // 0 affected resources
|
|
|
+ assertThat(
|
|
|
+ service.calculate(true, 0, HealthInfo.EMPTY_HEALTH_INFO).diagnosisList(),
|
|
|
+ equalTo(List.of(new Diagnosis(ACTION_CHECK_ALLOCATION_EXPLAIN_API, List.of(new Diagnosis.Resource(INDEX, List.of())))))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private HealthIndicatorResult createExpectedResult(
|
|
|
HealthStatus status,
|
|
|
String symptom,
|
|
@@ -1452,22 +1522,22 @@ public class ShardsAvailabilityHealthIndicatorServiceTests extends ESTestCase {
|
|
|
|
|
|
private record ShardRoutingKey(String index, int shard, boolean primary) {}
|
|
|
|
|
|
- private static ShardsAvailabilityHealthIndicatorService createAllocationHealthIndicatorService() {
|
|
|
- return createAllocationHealthIndicatorService(ClusterState.EMPTY_STATE, Collections.emptyMap());
|
|
|
+ private static ShardsAvailabilityHealthIndicatorService createShardsAvailabilityIndicatorService() {
|
|
|
+ return createShardsAvailabilityIndicatorService(ClusterState.EMPTY_STATE, Collections.emptyMap());
|
|
|
}
|
|
|
|
|
|
- private static ShardsAvailabilityHealthIndicatorService createAllocationHealthIndicatorService(ClusterState clusterState) {
|
|
|
- return createAllocationHealthIndicatorService(clusterState, Collections.emptyMap());
|
|
|
+ private static ShardsAvailabilityHealthIndicatorService createShardsAvailabilityIndicatorService(ClusterState clusterState) {
|
|
|
+ return createShardsAvailabilityIndicatorService(clusterState, Collections.emptyMap());
|
|
|
}
|
|
|
|
|
|
- private static ShardsAvailabilityHealthIndicatorService createAllocationHealthIndicatorService(
|
|
|
+ private static ShardsAvailabilityHealthIndicatorService createShardsAvailabilityIndicatorService(
|
|
|
ClusterState clusterState,
|
|
|
final Map<ShardRoutingKey, ShardAllocationDecision> decisions
|
|
|
) {
|
|
|
- return createAllocationHealthIndicatorService(Settings.EMPTY, clusterState, decisions);
|
|
|
+ return createShardsAvailabilityIndicatorService(Settings.EMPTY, clusterState, decisions);
|
|
|
}
|
|
|
|
|
|
- private static ShardsAvailabilityHealthIndicatorService createAllocationHealthIndicatorService(
|
|
|
+ private static ShardsAvailabilityHealthIndicatorService createShardsAvailabilityIndicatorService(
|
|
|
Settings nodeSettings,
|
|
|
ClusterState clusterState,
|
|
|
final Map<ShardRoutingKey, ShardAllocationDecision> decisions
|