parent
cdbdc1cb7f
commit
a33c3eec3f
|
@ -37,7 +37,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for {@link InfluxDbHealthIndicator}.
|
||||
*
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
@ -57,8 +57,9 @@ public class InfluxDbHealthIndicatorAutoConfiguration extends
|
|||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "influxdbHealthIndicator")
|
||||
public HealthIndicator influxdbHealthIndicator() {
|
||||
@ConditionalOnMissingBean(name = "influxDbHealthIndicator")
|
||||
public HealthIndicator influxDbHealthIndicator() {
|
||||
return createHealthIndicator(this.influxDbs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -103,6 +103,12 @@
|
|||
"description": "Whether to enable elasticsearch health check.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "management.influxdb.jms.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether to enable InfluxDB health check.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "management.health.jms.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAuto
|
|||
import org.springframework.boot.actuate.health.ApplicationHealthIndicator;
|
||||
import org.springframework.boot.actuate.infux.InfluxDbHealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -33,35 +32,35 @@ import static org.mockito.Mockito.mock;
|
|||
|
||||
/**
|
||||
* Tests for {@link InfluxDbHealthIndicatorAutoConfiguration}.
|
||||
*
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
public class InfluxDbHealthIndicatorAutonConfigurationTests {
|
||||
public class InfluxDbHealthIndicatorAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(InfluxDbConfiguration.class,
|
||||
.withUserConfiguration(InfluxDbConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
InfluxDbHealthIndicatorAutoConfiguration.class,
|
||||
HealthIndicatorAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void runShouldCreateIndicator() throws Exception {
|
||||
public void runShouldCreateIndicator() {
|
||||
this.contextRunner.run((context) -> assertThat(context)
|
||||
.hasSingleBean(InfluxDbHealthIndicator.class)
|
||||
.doesNotHaveBean(ApplicationHealthIndicator.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runWhenDisabledShouldNotCreateIndicator() throws Exception {
|
||||
public void runWhenDisabledShouldNotCreateIndicator() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("management.health.influxdb.enabled:false").run(
|
||||
(context) -> assertThat(context)
|
||||
.doesNotHaveBean(InfluxDbHealthIndicator.class)
|
||||
.hasSingleBean(ApplicationHealthIndicator.class));
|
||||
(context) -> assertThat(context)
|
||||
.doesNotHaveBean(InfluxDbHealthIndicator.class)
|
||||
.hasSingleBean(ApplicationHealthIndicator.class));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@AutoConfigureBefore(InfluxDbHealthIndicatorAutoConfiguration.class)
|
||||
protected static class InfluxDbConfiguration {
|
||||
static class InfluxDbConfiguration {
|
||||
|
||||
@Bean
|
||||
public InfluxDB influxdb() {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.boot.actuate.infux;
|
||||
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.dto.Pong;
|
||||
|
||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
|
@ -39,9 +40,9 @@ public class InfluxDbHealthIndicator extends AbstractHealthIndicator {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
String version = this.influxDb.version();
|
||||
builder.up().withDetail("version", version);
|
||||
protected void doHealthCheck(Health.Builder builder) {
|
||||
Pong pong = this.influxDb.ping();
|
||||
builder.up().withDetail("version", pong.getVersion());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.InfluxDBException;
|
||||
import org.influxdb.dto.Pong;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
|
@ -39,26 +40,29 @@ import static org.mockito.Mockito.verify;
|
|||
public class InfluxDbHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void influxdbIsUp() {
|
||||
public void influxDbIsUp() {
|
||||
Pong pong = mock(Pong.class);
|
||||
given(pong.getVersion()).willReturn("0.9");
|
||||
InfluxDB influxDB = mock(InfluxDB.class);
|
||||
given(influxDB.version()).willReturn("0.9");
|
||||
given(influxDB.ping()).willReturn(pong);
|
||||
InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDB);
|
||||
Health health = healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails().get("version")).isEqualTo("0.9");
|
||||
verify(influxDB).version();
|
||||
verify(influxDB).ping();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void influxdbIsDown() {
|
||||
public void influxDbIsDown() {
|
||||
InfluxDB influxDB = mock(InfluxDB.class);
|
||||
given(influxDB.version()).willThrow(
|
||||
given(influxDB.ping()).willThrow(
|
||||
new InfluxDBException(new IOException("Connection failed")));
|
||||
InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDB);
|
||||
Health health = healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat((String) health.getDetails().get("error"))
|
||||
.contains("Connection failed");
|
||||
verify(influxDB).version();
|
||||
verify(influxDB).ping();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1224,6 +1224,7 @@ content into your application. Rather, pick only the properties that you need.
|
|||
management.health.elasticsearch.indices= # Comma-separated index names.
|
||||
management.health.elasticsearch.response-timeout=100ms # The time to wait for a response from the cluster.
|
||||
management.health.jms.enabled=true # Whether to enable JMS health check.
|
||||
management.health.influxdb.enabled=true # Whether to enable InfluxDB health check.
|
||||
management.health.ldap.enabled=true # Whether to enable LDAP health check.
|
||||
management.health.mail.enabled=true # Whether to enable Mail health check.
|
||||
management.health.mongo.enabled=true # Whether to enable MongoDB health check.
|
||||
|
|
|
@ -368,6 +368,9 @@ The following `HealthIndicators` are auto-configured by Spring Boot when appropr
|
|||
|{sc-spring-boot-actuator}/elasticsearch/ElasticsearchHealthIndicator.{sc-ext}[`ElasticsearchHealthIndicator`]
|
||||
|Checks that an Elasticsearch cluster is up.
|
||||
|
||||
|{sc-spring-boot-actuator}/influx/InfluxDbHealthIndicator.{sc-ext}[`InfluxDbHealthIndicator`]
|
||||
|Checks that an InfluxDB server is up.
|
||||
|
||||
|{sc-spring-boot-actuator}/jms/JmsHealthIndicator.{sc-ext}[`JmsHealthIndicator`]
|
||||
|Checks that a JMS broker is up.
|
||||
|
||||
|
|
Loading…
Reference in New Issue