@@ -361,7 +361,7 @@ public void testAllReplicasUnassigned() {
361361 List .of ()
362362 );
363363 var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
364- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
364+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
365365 ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
366366 status ,
367367 clusterState ,
@@ -386,7 +386,7 @@ public void testAllReplicasUnassigned() {
386386 List .of ()
387387 );
388388 var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
389- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
389+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
390390 ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
391391 status ,
392392 clusterState ,
@@ -411,7 +411,7 @@ public void testAllReplicasUnassigned() {
411411 List .of ()
412412 );
413413 var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
414- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
414+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
415415 ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
416416 status ,
417417 clusterState ,
@@ -438,7 +438,7 @@ public void testAllReplicasUnassigned() {
438438 );
439439
440440 var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
441- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
441+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
442442 ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
443443 status ,
444444 clusterState ,
@@ -477,7 +477,7 @@ public void testAllReplicasUnassigned() {
477477 List .of ()
478478 );
479479 var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
480- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
480+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
481481 ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
482482 status ,
483483 clusterState ,
@@ -508,7 +508,7 @@ public void testAllReplicasUnassigned() {
508508 ProjectId projectId = randomProjectIdOrDefault ();
509509 var clusterState = createClusterStateWith (projectId , List .of (routingTable ), List .of ());
510510 var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
511- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
511+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
512512 ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
513513 status ,
514514 clusterState ,
@@ -534,7 +534,7 @@ public void testAllReplicasUnassigned() {
534534 List .of ()
535535 );
536536 var service = createShardsAvailabilityIndicatorService (projectId , clusterState );
537- ShardAllocationStatus status = service .createNewStatus (clusterState .metadata ());
537+ ShardAllocationStatus status = service .createNewStatus (clusterState .metadata (), randomNonNegativeInt () );
538538 ShardsAvailabilityHealthIndicatorService .updateShardAllocationStatus (
539539 status ,
540540 clusterState ,
@@ -1791,32 +1791,31 @@ public void testLimitNumberOfAffectedResources() {
17911791
17921792 {
17931793 // 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 )
18171809 )
1818- )
1810+ ),
1811+ calculatedResult .impacts ()
18191812 );
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 ());
18201819 }
18211820
18221821 {
@@ -1838,11 +1837,8 @@ public void testLimitNumberOfAffectedResources() {
18381837 }
18391838
18401839 {
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 ()));
18461842 }
18471843 }
18481844
0 commit comments