diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterHealthIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterHealthIT.java index 33f101cce2382..fcd58291cf8cb 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterHealthIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterHealthIT.java @@ -46,6 +46,7 @@ import org.opensearch.common.action.ActionFuture; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.index.IndexNotFoundException; import org.opensearch.test.InternalTestCluster; import org.opensearch.test.OpenSearchIntegTestCase; @@ -83,19 +84,17 @@ public void testSimpleLocalHealth() { public void testHealth() { logger.info("--> running cluster health on an index that does not exists"); + expectThrows(IndexNotFoundException.class, () -> { + client().admin().cluster().prepareHealth("test1").setWaitForYellowStatus().setTimeout("1s").execute().actionGet(); + }); + logger.info("--> running cluster wide health"); ClusterHealthResponse healthResponse = client().admin() .cluster() - .prepareHealth("test1") - .setWaitForYellowStatus() - .setTimeout("1s") + .prepareHealth() + .setWaitForGreenStatus() + .setTimeout("10s") .execute() .actionGet(); - assertThat(healthResponse.isTimedOut(), equalTo(true)); - assertThat(healthResponse.getStatus(), equalTo(ClusterHealthStatus.RED)); - assertThat(healthResponse.getIndices().isEmpty(), equalTo(true)); - - logger.info("--> running cluster wide health"); - healthResponse = client().admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); assertThat(healthResponse.isTimedOut(), equalTo(false)); assertThat(healthResponse.getStatus(), equalTo(ClusterHealthStatus.GREEN)); assertThat(healthResponse.getIndices().isEmpty(), equalTo(true)); @@ -302,6 +301,7 @@ public void run() { } public void testWaitForEventsRetriesIfOtherConditionsNotMet() { + createIndex("index"); final ActionFuture healthResponseFuture = client().admin() .cluster() .prepareHealth("index") @@ -338,7 +338,6 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS }); try { - createIndex("index"); assertFalse(client().admin().cluster().prepareHealth("index").setWaitForGreenStatus().get().isTimedOut()); // at this point the original health response should not have returned: there was never a point where the index was green AND diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/health/TransportClusterHealthAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/health/TransportClusterHealthAction.java index 8f0202e6d1ed0..a44e54b8f623d 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -419,13 +419,9 @@ static int prepareResponse( } } if (CollectionUtils.isEmpty(request.indices()) == false) { - try { - indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), request); - waitForCounter++; - } catch (IndexNotFoundException e) { - response.setStatus(ClusterHealthStatus.RED); // no indices, make sure its RED - // missing indices, wait a bit more... - } + indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), request); + waitForCounter++; + } if (!request.waitForNodes().isEmpty()) { if (request.waitForNodes().startsWith(">=")) {