Use metrics export.*.enabled properties to control auto-configuration

Closes gh-11978
pull/12011/head
Andy Wilkinson 7 years ago
parent 85aeb5c00d
commit 384a4ed6a9

@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -44,6 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(AtlasMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.atlas", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(AtlasProperties.class)
public class AtlasMetricsExportAutoConfiguration {

@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -43,6 +44,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(DatadogMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.datadog", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(DatadogProperties.class)
public class DatadogMetricsExportAutoConfiguration {

@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -44,6 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(GangliaMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.ganglia", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(GangliaProperties.class)
public class GangliaMetricsExportAutoConfiguration {
@ -53,7 +55,7 @@ public class GangliaMetricsExportAutoConfiguration {
return new GangliaPropertiesConfigAdapter(gangliaProperties);
}
@Bean
@Bean(destroyMethod = "stop")
@ConditionalOnMissingBean
public GangliaMeterRegistry gangliaMeterRegistry(GangliaConfig gangliaConfig,
HierarchicalNameMapper nameMapper, Clock clock) {

@ -33,7 +33,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class GangliaProperties {
/**
* Enable publishing to Ganglia.
* Whether exporting of metrics to this backend is enabled.
*/
private Boolean enabled;

@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -44,6 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(GraphiteMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.graphite", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(GraphiteProperties.class)
public class GraphiteMetricsExportAutoConfiguration {

@ -33,7 +33,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class GraphiteProperties {
/**
* Enable publishing to Graphite.
* Whether exporting of metrics to this backend is enabled.
*/
private Boolean enabled;

@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -43,6 +44,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(InfluxMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.influx", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(InfluxProperties.class)
public class InfluxMetricsExportAutoConfiguration {

@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -44,6 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(JmxMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.jmx", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(JmxProperties.class)
public class JmxMetricsExportAutoConfiguration {

@ -29,11 +29,24 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "management.metrics.export.jmx")
public class JmxProperties {
/**
* Whether exporting of metrics to this backend is enabled.
*/
private Boolean enabled;
/**
* Step size (i.e. reporting frequency) to use.
*/
private Duration step;
public Boolean getEnabled() {
return this.enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Duration getStep() {
return this.step;
}

@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -44,6 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(NewRelicMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.newrelic", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(NewRelicProperties.class)
public class NewRelicMetricsExportAutoConfiguration {

@ -32,6 +32,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -47,6 +48,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(PrometheusMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.prometheus", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(PrometheusProperties.class)
public class PrometheusMetricsExportAutoConfiguration {

@ -30,7 +30,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class PrometheusProperties {
/**
* Enable publishing to Prometheus.
* Whether exporting of metrics to this backend is enabled.
*/
private Boolean enabled;

@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -44,6 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(SignalFxMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.signalfx", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(SignalFxProperties.class)
public class SignalFxMetricsExportAutoConfiguration {

@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -44,6 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(StatsdMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.statsd", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(StatsdProperties.class)
public class StatsdMetricsExportAutoConfiguration {

@ -33,7 +33,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class StatsdProperties {
/**
* Export metrics to StatsD.
* Whether exporting of metrics to this backend is enabled.
*/
private Boolean enabled;

@ -54,6 +54,15 @@ public class AtlasMetricsExportAutoConfigurationTests {
.hasSingleBean(AtlasConfig.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.atlas.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(AtlasMeterRegistry.class)
.doesNotHaveBean(AtlasConfig.class));
}
@Test
public void allowsCustomConfigToBeUsed() {
this.runner.withUserConfiguration(CustomConfigConfiguration.class)

@ -61,6 +61,15 @@ public class DatadogMetricsExportAutoConfigurationTests {
.hasSingleBean(DatadogConfig.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.datadog.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(DatadogMeterRegistry.class)
.doesNotHaveBean(DatadogConfig.class));
}
@Test
public void allowsCustomConfigToBeUsed() {
this.runner.withUserConfiguration(CustomConfigConfiguration.class)

@ -54,6 +54,15 @@ public class GangliaMetricsExportAutoConfigurationTests {
.hasSingleBean(GangliaConfig.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.ganglia.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(GangliaMeterRegistry.class)
.doesNotHaveBean(GangliaConfig.class));
}
@Test
public void allowsCustomConfigToBeUsed() {
this.runner.withUserConfiguration(CustomConfigConfiguration.class)

@ -54,6 +54,15 @@ public class GraphiteMetricsExportAutoConfigurationTests {
.hasSingleBean(GraphiteConfig.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.graphite.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(GraphiteMeterRegistry.class)
.doesNotHaveBean(GraphiteConfig.class));
}
@Test
public void allowsCustomConfigToBeUsed() {
this.runner.withUserConfiguration(CustomConfigConfiguration.class)

@ -54,6 +54,15 @@ public class InfluxMetricsExportAutoConfigurationTests {
.hasSingleBean(InfluxConfig.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.influx.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(InfluxMeterRegistry.class)
.doesNotHaveBean(InfluxConfig.class));
}
@Test
public void allowsCustomConfigToBeUsed() {
this.runner.withUserConfiguration(CustomConfigConfiguration.class)

@ -58,6 +58,16 @@ public class JmxMetricsExportAutoConfigurationTests {
.hasSingleBean(HierarchicalNameMapper.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.jmx.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(JmxMeterRegistry.class)
.doesNotHaveBean(JmxConfig.class)
.doesNotHaveBean(HierarchicalNameMapper.class));
}
@Test
public void allowsCustomConfigToBeUsed() {
this.runner.withUserConfiguration(CustomConfigConfiguration.class)

@ -69,6 +69,17 @@ public class NewRelicMetricsExportAutoConfigurationTests {
.hasSingleBean(Clock.class).hasSingleBean(NewRelicConfig.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner
.withPropertyValues("management.metrics.export.newrelic.enabled=false",
"management.metrics.export.newrelic.api-key=abcde",
"management.metrics.export.newrelic.account-id=12345")
.run((context) -> assertThat(context)
.doesNotHaveBean(NewRelicMeterRegistry.class)
.doesNotHaveBean(NewRelicConfig.class));
}
@Test
public void allowsClockToBeCustomized() {
this.runner.withUserConfiguration(CustomClockConfiguration.class)

@ -58,6 +58,16 @@ public class PrometheusMetricsExportAutoConfigurationTests {
.hasSingleBean(PrometheusConfig.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner
.withPropertyValues("management.metrics.export.prometheus.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(PrometheusMeterRegistry.class)
.doesNotHaveBean(CollectorRegistry.class)
.doesNotHaveBean(PrometheusConfig.class));
}
@Test
public void allowsCustomConfigToBeUsed() {
this.runner.withUserConfiguration(CustomConfigConfiguration.class)

@ -56,6 +56,17 @@ public class SignalFxMetricsExportAutoConfigurationTests {
.hasSingleBean(Clock.class).hasSingleBean(SignalFxConfig.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner
.withPropertyValues(
"management.metrics.export.signalfx.access-token=abcde",
"management.metrics.export.signalfx.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(SignalFxMeterRegistry.class)
.doesNotHaveBean(SignalFxConfig.class));
}
@Test
public void allowsClockToBeCustomized() {
this.runner

@ -58,6 +58,15 @@ public class StatsdMetricsExportAutoConfigurationTests {
.hasSingleBean(HierarchicalNameMapper.class));
}
@Test
public void autoConfigurationCanBeDisabled() {
this.runner.withPropertyValues("management.metrics.export.statsd.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(StatsdMeterRegistry.class)
.doesNotHaveBean(StatsdConfig.class)
.doesNotHaveBean(HierarchicalNameMapper.class));
}
@Test
public void allowsCustomConfigToBeUsed() {
this.runner.withUserConfiguration(CustomConfigConfiguration.class)

@ -1310,6 +1310,7 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.export.atlas.config-time-to-live= # Time to live for subscriptions from the LWC service.
management.metrics.export.atlas.config-uri= # URI for the Atlas LWC endpoint to retrieve current subscriptions.
management.metrics.export.atlas.connect-timeout= # Connection timeout for requests to the backend.
management.metrics.export.atlas.enabled= # Whether exporting of metrics to this backend is enabled.
management.metrics.export.atlas.eval-uri= # URI for the Atlas LWC endpoint to evaluate the data for a subscription.
management.metrics.export.atlas.lwc-enabled= # Enable streaming to Atlas LWC.
management.metrics.export.atlas.meter-time-to-live= # Time to live for meters that do not have any activity. After this period the meter will be considered expired and will not get reported.
@ -1330,6 +1331,7 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.export.datadog.uri= # URI to ship metrics to. If you need to publish metrics to an internal proxy en-route to Datadog, you can define the location of the proxy with this.
management.metrics.export.ganglia.addressing-mode= # UDP addressing mode, either unicast or multicast.
management.metrics.export.ganglia.duration-units= # Base time unit used to report durations.
management.metrics.export.ganglia.enabled= # Whether exporting of metrics to this backend is enabled.
management.metrics.export.ganglia.host= # Host of the Ganglia server to receive exported metrics.
management.metrics.export.ganglia.port= # Port of the Ganglia server to receive exported metrics.
management.metrics.export.ganglia.protocol-version= # Ganglia protocol version. Must be either 3.1 or 3.0.
@ -1337,6 +1339,7 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.export.ganglia.step= # Step size (i.e. reporting frequency) to use.
management.metrics.export.ganglia.time-to-live= # Time to live for metrics on Ganglia.
management.metrics.export.graphite.duration-units= # Base time unit used to report durations.
management.metrics.export.graphite.enabled= # Whether exporting of metrics to this backend is enabled.
management.metrics.export.graphite.host= # Host of the Graphite server to receive exported metrics.
management.metrics.export.graphite.port= # Port of the Graphite server to receive exported metrics.
management.metrics.export.graphite.protocol= # Protocol to use while shipping data to Graphite.
@ -1349,6 +1352,7 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.export.influx.connect-timeout= # Connection timeout for requests to the backend.
management.metrics.export.influx.consistency= # Write consistency for each point.
management.metrics.export.influx.db= # Tag that will be mapped to "host" when shipping metrics to Influx. Can be omitted if host should be omitted on publishing.
management.metrics.export.influx.enabled= # Whether exporting of metrics to this backend is enabled.
management.metrics.export.influx.num-threads= # Number of threads to use with the metrics publishing scheduler.
management.metrics.export.influx.password= # Login password of the Influx server.
management.metrics.export.influx.read-timeout= # Read timeout for requests to the backend.
@ -1356,6 +1360,7 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.export.influx.step=1m # Step size (i.e. reporting frequency) to use.
management.metrics.export.influx.uri= # URI of the Influx server.
management.metrics.export.influx.user-name= # Login user of the Influx server.
management.metrics.export.jmx.enabled= # Whether exporting of metrics to this backend is enabled.
management.metrics.export.jmx.step= # Step size (i.e. reporting frequency) to use.
management.metrics.export.newrelic.account-id= # New Relic account ID.
management.metrics.export.newrelic.api-key= # New Relic API key.
@ -1367,7 +1372,7 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.export.newrelic.step=1m # Step size (i.e. reporting frequency) to use.
management.metrics.export.newrelic.uri= # Optional custom URI for the New Relic Insights API.
management.metrics.export.prometheus.descriptions= # Enable publishing descriptions as part of the scrape payload to Prometheus. Turn this off to minimize the amount of data sent on each scrape.
management.metrics.export.prometheus.enabled=true # Whether exporting of metrics to Prometheus is enabled.
management.metrics.export.prometheus.enabled=true # Whether exporting of metrics to this backend is enabled.
management.metrics.export.prometheus.step= # Step size (i.e. reporting frequency) to use.
management.metrics.export.signalfx.access-token= # SignalFX access token.
management.metrics.export.signalfx.batch-size= # Number of measurements per request to use for this backend. If more measurements are found, then multiple requests will be made.
@ -1379,6 +1384,7 @@ content into your application. Rather, pick only the properties that you need.
management.metrics.export.signalfx.uri= # Optional custom URI for the SignalFX API.
management.metrics.export.simple.mode=cumulative # Counting mode.
management.metrics.export.simple.step=10s # Step size (i.e. reporting frequency) to use.
management.metrics.export.statsd.enabled= # Whether exporting of metrics to this backend is enabled.
management.metrics.export.statsd.flavor=datadog # StatsD line protocol to use.
management.metrics.export.statsd.host=localhost # Host of the StatsD server to receive exported metrics.
management.metrics.export.statsd.max-packet-length=1400 # Total length of a single payload should be kept within your network's MTU.

Loading…
Cancel
Save