Skip to content

Commit

Permalink
Add possibility to disable the Elasticsearch Sniffer functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed Jun 17, 2021
1 parent 566a642 commit 0d91b24
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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,7 @@ 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,13 @@ public void setDelayAfterFailure(Duration delayAfterFailure) {
this.delayAfterFailure = delayAfterFailure;
}

public boolean isEnabled() {
return 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

0 comments on commit 0d91b24

Please sign in to comment.