@@ -361,7 +361,7 @@ public void testAllReplicasUnassigned() {
361
361
List .of ()
362
362
);
363
363
var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
364
- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
364
+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
365
365
ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
366
366
status ,
367
367
clusterState ,
@@ -386,7 +386,7 @@ public void testAllReplicasUnassigned() {
386
386
List .of ()
387
387
);
388
388
var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
389
- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
389
+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
390
390
ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
391
391
status ,
392
392
clusterState ,
@@ -411,7 +411,7 @@ public void testAllReplicasUnassigned() {
411
411
List .of ()
412
412
);
413
413
var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
414
- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
414
+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
415
415
ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
416
416
status ,
417
417
clusterState ,
@@ -438,7 +438,7 @@ public void testAllReplicasUnassigned() {
438
438
);
439
439
440
440
var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
441
- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
441
+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
442
442
ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
443
443
status ,
444
444
clusterState ,
@@ -477,7 +477,7 @@ public void testAllReplicasUnassigned() {
477
477
List .of ()
478
478
);
479
479
var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
480
- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
480
+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
481
481
ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
482
482
status ,
483
483
clusterState ,
@@ -508,7 +508,7 @@ public void testAllReplicasUnassigned() {
508
508
ProjectId projectId = randomProjectIdOrDefault ();
509
509
var clusterState = createClusterStateWith (projectId , List .of (routingTable ), List .of ());
510
510
var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
511
- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
511
+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
512
512
ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
513
513
status ,
514
514
clusterState ,
@@ -534,7 +534,7 @@ public void testAllReplicasUnassigned() {
534
534
List .of ()
535
535
);
536
536
var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
537
- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
537
+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
538
538
ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
539
539
status ,
540
540
clusterState ,
@@ -1791,32 +1791,31 @@ public void testLimitNumberOfAffectedResources() {
1791
1791
1792
1792
{
1793
1793
// assert the full result to check that details, impacts, and symptoms use the correct count of affected indices (5)
1794
- assertThat (
1795
- service .calculate (true , 2 , HealthInfo .EMPTY_HEALTH_INFO ),
1796
- equalTo (
1797
- createExpectedResult (
1798
- RED ,
1799
- "This cluster has 5 unavailable primary shards." ,
1800
- Map .of ("unassigned_primaries" , 5 ),
1801
- List .of (
1802
- new HealthIndicatorImpact (
1803
- NAME ,
1804
- ShardsAvailabilityHealthIndicatorService .PRIMARY_UNASSIGNED_IMPACT_ID ,
1805
- 1 ,
1806
- "Cannot add data to 5 indices [red-index1, red-index2, red-index3, red-index4, red-index5]. Searches might "
1807
- + "return incomplete results." ,
1808
- List .of (ImpactArea .INGEST , ImpactArea .SEARCH )
1809
- )
1810
- ),
1811
- List .of (
1812
- new Diagnosis (
1813
- ACTION_CHECK_ALLOCATION_EXPLAIN_API ,
1814
- List .of (new Diagnosis .Resource (INDEX , List .of ("red-index1" , "red-index2" )))
1815
- )
1816
- )
1794
+ // since we limit the number of allocation explanations while looping over the shards, we can't guarantee
1795
+ // which indices end up in the affected resources list, but we can at least check that the size is correct
1796
+ var calculatedResult = service .calculate (true , 2 , HealthInfo .EMPTY_HEALTH_INFO );
1797
+ assertEquals (RED , calculatedResult .status ());
1798
+ assertEquals ("This cluster has 5 unavailable primary shards." , calculatedResult .symptom ());
1799
+ assertEquals (new SimpleHealthIndicatorDetails (addDefaults (Map .of ("unassigned_primaries" , 5 ))), calculatedResult .details ());
1800
+ assertEquals (
1801
+ List .of (
1802
+ new HealthIndicatorImpact (
1803
+ NAME ,
1804
+ ShardsAvailabilityHealthIndicatorService .PRIMARY_UNASSIGNED_IMPACT_ID ,
1805
+ 1 ,
1806
+ "Cannot add data to 5 indices [red-index1, red-index2, red-index3, red-index4, red-index5]. Searches might "
1807
+ + "return incomplete results." ,
1808
+ List .of (ImpactArea .INGEST , ImpactArea .SEARCH )
1817
1809
)
1818
- )
1810
+ ),
1811
+ calculatedResult .impacts ()
1819
1812
);
1813
+ assertEquals ("Expected 1 diagnosis but got " + calculatedResult .diagnosisList (), 1 , calculatedResult .diagnosisList ().size ());
1814
+ var diagnosis = calculatedResult .diagnosisList ().get (0 );
1815
+ assertEquals (ACTION_CHECK_ALLOCATION_EXPLAIN_API , diagnosis .definition ());
1816
+ assertEquals ("Expected 1 affected resource but got " + diagnosis .affectedResources (), 1 , diagnosis .affectedResources ().size ());
1817
+ var affectedResource = diagnosis .affectedResources ().get (0 );
1818
+ assertEquals ("Expected 2 indices but got " + affectedResource .getValues (), 2 , affectedResource .getValues ().size ());
1820
1819
}
1821
1820
1822
1821
{
@@ -1838,11 +1837,8 @@ public void testLimitNumberOfAffectedResources() {
1838
1837
}
1839
1838
1840
1839
{
1841
- // 0 affected resources
1842
- assertThat (
1843
- service .calculate (true , 0 , HealthInfo .EMPTY_HEALTH_INFO ).diagnosisList (),
1844
- equalTo (List .of (new Diagnosis (ACTION_CHECK_ALLOCATION_EXPLAIN_API , List .of (new Diagnosis .Resource (INDEX , List .of ())))))
1845
- );
1840
+ // 0 affected resources means we don't do any shard allocation explanation and thus do not report any diagnosis
1841
+ assertThat (service .calculate (true , 0 , HealthInfo .EMPTY_HEALTH_INFO ).diagnosisList (), equalTo (List .of ()));
1846
1842
}
1847
1843
}
1848
1844
0 commit comments