Skip to content

Spring Boot health check fails with a user-provided RestHighLevelClient as the health indicator continues to use the auto-configured RestClient #17464

@sudoapt-getclean

Description

@sudoapt-getclean

In my @SpringBootApplication class I define this restclient

    @Bean(destroyMethod = "close")
    public RestHighLevelClient client() {
        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
            .connectedTo(elasticsearchHost)
            .usingSsl()
            .build();

        return RestClients.create(clientConfiguration).rest();
    }

This all works fine. however when the /actuator/health endpoint of the application is called. It fails and I get a stacktrace from elastic that shows connection refused.
Some debugging showed me that this is because I have two RestClient beans. The second bean is created by the code in RestClientAutoconfiguration below. This is done before my RestClient is created.
This other Restclient is created with the default localhost:9200 configuration and is used for the health check (but not for the actual searching)

/**
 * {@link EnableAutoConfiguration Auto-configuration} for Elasticsearch REST clients.
 *
 * @author Brian Clozel
 * @since 2.1.0
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(RestClient.class)
@EnableConfigurationProperties(RestClientProperties.class)
public class RestClientAutoConfiguration {

	@Bean
	@ConditionalOnMissingBean
	public RestClient restClient(RestClientBuilder builder) {
		return builder.build();
	}

I happen to be running spring boot 2.2.0.M4 (Because of the support for using the highlevel restclient yay)
Keep up the good work and let me know If you need more information

--- Appendix ---
the original stacktrace is

2019-07-09 13:54:19.981 DEBUG 1 --- [io-8080-exec-10] o.s.web.servlet.DispatcherServlet        : GET "/actuator/health", parameters={}
2019-07-09 13:54:20.000  WARN 1 --- [io-8080-exec-10] s.b.a.e.ElasticsearchRestHealthIndicator : Elasticsearch health check failed

java.net.ConnectException: Connection refused
	at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:959) ~[elasticsearch-rest-client-6.7.2.jar!/:6.7.2]
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:233) ~[elasticsearch-rest-client-6.7.2.jar!/:6.7.2]

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions