Fix Elasticsearch health indicator
- added setIndices to ElasticsearchHealthIndicatorProperties to enable setting the indices property from configuration files - Elasticsearch cannot handle "null" if the health of all indices should be checked; use "_all" instead Closes gh-2812
This commit is contained in:
parent
bbaaaeb9cf
commit
24ca44dbb4
|
|
@ -31,6 +31,8 @@ import org.elasticsearch.client.Requests;
|
|||
*/
|
||||
public class ElasticsearchHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private static final String[] allIndices = { "_all" };
|
||||
|
||||
private final Client client;
|
||||
|
||||
private final ElasticsearchHealthIndicatorProperties properties;
|
||||
|
|
@ -47,8 +49,8 @@ public class ElasticsearchHealthIndicator extends AbstractHealthIndicator {
|
|||
ClusterHealthResponse response = this.client
|
||||
.admin()
|
||||
.cluster()
|
||||
.health(Requests.clusterHealthRequest(indices.isEmpty() ? null : indices
|
||||
.toArray(new String[indices.size()])))
|
||||
.health(Requests.clusterHealthRequest(indices.isEmpty() ? allIndices
|
||||
: indices.toArray(new String[indices.size()])))
|
||||
.actionGet(this.properties.getResponseTimeout());
|
||||
|
||||
switch (response.getStatus()) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
* @author Andy Wilkinson
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@ConfigurationProperties("management.health.elasticsearch")
|
||||
@ConfigurationProperties(prefix = "management.health.elasticsearch", ignoreUnknownFields = false)
|
||||
public class ElasticsearchHealthIndicatorProperties {
|
||||
|
||||
/**
|
||||
|
|
@ -45,6 +45,10 @@ public class ElasticsearchHealthIndicatorProperties {
|
|||
return this.indices;
|
||||
}
|
||||
|
||||
public void setIndices(List<String> indices) {
|
||||
this.indices = indices;
|
||||
}
|
||||
|
||||
public long getResponseTimeout() {
|
||||
return this.responseTimeout;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import static org.hamcrest.Matchers.arrayContaining;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
|
@ -82,7 +81,7 @@ public class ElasticsearchHealthIndicatorTests {
|
|||
given(this.cluster.health(requestCaptor.capture())).willReturn(responseFuture);
|
||||
Health health = this.indicator.health();
|
||||
assertThat(responseFuture.getTimeout, is(100L));
|
||||
assertThat(requestCaptor.getValue().indices(), is(nullValue()));
|
||||
assertThat(requestCaptor.getValue().indices(), is(arrayContaining("_all")));
|
||||
assertThat(health.getStatus(), is(Status.UP));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue