mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-08 10:19:13 +00:00
Disable Elasticsearch client's sniffer by default
This commit switches the auto-configuration of Elasticsearch to not contribute a client's sniffer by default. This matches the best practices as describe in https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how Closes gh-48155
This commit is contained in:
+2
-3
@@ -341,7 +341,7 @@ To take full control over the client's configuration, define a javadoc:co.elasti
|
||||
|
||||
|
||||
|
||||
Additionally, a javadoc:co.elastic.clients.transport.rest5_client.low_level.sniffer.Sniffer[] is auto-configured to automatically discover nodes from a running Elasticsearch cluster and set them on the javadoc:co.elastic.clients.transport.rest5_client.low_level.Rest5Client[] bean.
|
||||
Additionally, a javadoc:co.elastic.clients.transport.rest5_client.low_level.sniffer.Sniffer[] can be auto-configured to automatically discover nodes from a running Elasticsearch cluster and set them on the javadoc:co.elastic.clients.transport.rest5_client.low_level.Rest5Client[] bean.
|
||||
You can further tune how javadoc:co.elastic.clients.transport.rest5_client.low_level.sniffer.Sniffer[] is configured, as shown in the following example:
|
||||
|
||||
[configprops,yaml]
|
||||
@@ -350,12 +350,11 @@ spring:
|
||||
elasticsearch:
|
||||
restclient:
|
||||
sniffer:
|
||||
enabled: true
|
||||
interval: "10m"
|
||||
delay-after-failure: "30s"
|
||||
----
|
||||
|
||||
To disable auto-configuration of the Sniffer, set configprop:spring.elasticsearch.restclient.sniffer.enabled[] to `false`.
|
||||
|
||||
|
||||
|
||||
[[data.nosql.elasticsearch.connecting-using-rest.javaapiclient]]
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ public class ElasticsearchProperties {
|
||||
/**
|
||||
* Whether the sniffer is enabled.
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* Interval between consecutive ordinary sniff executions.
|
||||
|
||||
+1
-1
@@ -139,7 +139,7 @@ class ElasticsearchRestClientConfigurations {
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(Sniffer.class)
|
||||
@ConditionalOnSingleCandidate(Rest5Client.class)
|
||||
@ConditionalOnProperty(name = "spring.elasticsearch.restclient.sniffer.enabled", matchIfMissing = true)
|
||||
@ConditionalOnProperty(name = "spring.elasticsearch.restclient.sniffer.enabled")
|
||||
static class RestClientSnifferConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
+17
-15
@@ -257,8 +257,13 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureShouldCreateSnifferUsingRest5Client() {
|
||||
this.contextRunner.run((context) -> {
|
||||
void configureShouldNotCreateSnifferUsingRest5ClientByDefault() {
|
||||
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(Sniffer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWithSnifferEnabled() {
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.restclient.sniffer.enabled=true").run((context) -> {
|
||||
assertThat(context).hasSingleBean(Sniffer.class);
|
||||
assertThat(context.getBean(Sniffer.class)).hasFieldOrPropertyWithValue("restClient",
|
||||
context.getBean(Rest5Client.class));
|
||||
@@ -272,7 +277,8 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@Test
|
||||
void configureWithCustomSnifferSettings() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.elasticsearch.restclient.sniffer.interval=180s",
|
||||
.withPropertyValues("spring.elasticsearch.restclient.sniffer.enabled=true",
|
||||
"spring.elasticsearch.restclient.sniffer.interval=180s",
|
||||
"spring.elasticsearch.restclient.sniffer.delay-after-failure=30s")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Sniffer.class);
|
||||
@@ -287,18 +293,14 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@Test
|
||||
void configureWhenCustomSnifferShouldBackOff() {
|
||||
Sniffer customSniffer = mock(Sniffer.class);
|
||||
this.contextRunner.withBean(Sniffer.class, () -> customSniffer).run((context) -> {
|
||||
assertThat(context).hasSingleBean(Sniffer.class);
|
||||
Sniffer sniffer = context.getBean(Sniffer.class);
|
||||
assertThat(sniffer).isSameAs(customSniffer);
|
||||
then(customSniffer).shouldHaveNoInteractions();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWithSnifferDisabled() {
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.restclient.sniffer.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(Sniffer.class));
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.restclient.sniffer.enabled=true")
|
||||
.withBean(Sniffer.class, () -> customSniffer)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Sniffer.class);
|
||||
Sniffer sniffer = context.getBean(Sniffer.class);
|
||||
assertThat(sniffer).isSameAs(customSniffer);
|
||||
then(customSniffer).shouldHaveNoInteractions();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user