Restore behavior of management.metrics.export.simple.enabled

See gh-12106
This commit is contained in:
Jon Schneider
2018-02-18 09:51:13 -06:00
committed by Stephane Nicoll
parent 19ce68d2d8
commit da759f29d0
4 changed files with 13 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -46,6 +47,7 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnBean(Clock.class)
@EnableConfigurationProperties(SimpleProperties.class)
@ConditionalOnMissingBean(MeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.simple", name = "enabled", havingValue = "true", matchIfMissing = true)
public class SimpleMetricsExportAutoConfiguration {
@Bean

View File

@@ -34,7 +34,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class SimpleProperties {
/**
* Enable publishing to the backend.
* Enable in-memory metrics that aren't published anywhere (allows you to see
* what metrics are collected in the metrics actuator endpoint).
*/
private boolean enabled;

View File

@@ -41,11 +41,6 @@ public class SimplePropertiesConfigAdapter
return null;
}
@Override
public boolean enabled() {
return get(SimpleProperties::getEnabled, SimpleConfig.super::enabled);
}
@Override
public Duration step() {
return get(SimpleProperties::getStep, SimpleConfig.super::step);

View File

@@ -51,6 +51,15 @@ public class SimpleMetricsExportAutoConfigurationTests {
.hasSingleBean(Clock.class).hasSingleBean(SimpleConfig.class));
}
@Test
public void backsOffWhenSpecificallyDisabled() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.simple.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(SimpleMeterRegistry.class)
.doesNotHaveBean(SimpleConfig.class));
}
@Test
public void allowsConfigToBeCustomized() {
this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class)