mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Add config prop to enabled/disable Elasticsearch sniffer
Closes gh-47301 Co-Authored-By: Andy Wilkinson <andy.wilkinson@broadcom.com>
This commit is contained in:
committed by
Andy Wilkinson
co-authored by
Andy Wilkinson
parent
3a9ab15696
commit
dc341edfdd
@@ -350,6 +350,8 @@ spring:
|
||||
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]]
|
||||
|
||||
+13
@@ -160,6 +160,11 @@ public class ElasticsearchProperties {
|
||||
|
||||
public static class Sniffer {
|
||||
|
||||
/**
|
||||
* Whether the sniffer is enabled.
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Interval between consecutive ordinary sniff executions.
|
||||
*/
|
||||
@@ -170,6 +175,14 @@ public class ElasticsearchProperties {
|
||||
*/
|
||||
private Duration delayAfterFailure = Duration.ofMinutes(1);
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Duration getInterval() {
|
||||
return this.interval;
|
||||
}
|
||||
|
||||
+2
@@ -47,6 +47,7 @@ import org.jspecify.annotations.Nullable;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.elasticsearch.autoconfigure.ElasticsearchConnectionDetails.Node;
|
||||
@@ -138,6 +139,7 @@ class ElasticsearchRestClientConfigurations {
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(Sniffer.class)
|
||||
@ConditionalOnSingleCandidate(Rest5Client.class)
|
||||
@ConditionalOnProperty(name = "spring.elasticsearch.restclient.sniffer.enabled", matchIfMissing = true)
|
||||
static class RestClientSnifferConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
+6
@@ -295,6 +295,12 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWithSnifferDisabled() {
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.restclient.sniffer.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(Sniffer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void definesPropertiesBasedConnectionDetailsByDefault() {
|
||||
this.contextRunner
|
||||
|
||||
Reference in New Issue
Block a user