Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to disable the Elasticsearch Sniffer functionality #26949

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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.context.annotation.Bean;
Expand Down Expand Up @@ -113,6 +114,8 @@ RestHighLevelClient elasticsearchRestHighLevelClient(RestClientBuilder restClien
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Sniffer.class)
@ConditionalOnSingleCandidate(RestHighLevelClient.class)
@ConditionalOnProperty(prefix = "spring.elasticsearch.rest.sniffer", name = "enabled", havingValue = "true",
matchIfMissing = true)
static class RestClientSnifferConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public static class Sniffer {
*/
private Duration delayAfterFailure = Duration.ofMinutes(1);

/**
* Whether to enable Sniffer support.
*/
private boolean enabled = true;

public Duration getInterval() {
return this.interval;
}
Expand All @@ -131,6 +136,14 @@ public void setDelayAfterFailure(Duration delayAfterFailure) {
this.delayAfterFailure = delayAfterFailure;
}

public boolean isEnabled() {
return this.enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ void configureWithoutSnifferLibraryShouldNotCreateSniffer() {
.doesNotHaveBean(Sniffer.class));
}

@Test
void configureWithDisabledSnifferShouldNotCreateSniffer() {
this.contextRunner.withPropertyValues("spring.elasticsearch.rest.sniffer.enabled=false")
.run((context) -> assertThat(context).hasSingleBean(RestHighLevelClient.class)
.doesNotHaveBean(Sniffer.class));
}

@Test
void configureShouldCreateSnifferUsingRestHighLevelClient() {
this.contextRunner.run((context) -> {
Expand Down