Auto-configure Micrometer's Clock in a single place

Closes gh-11977
pull/11967/merge
Andy Wilkinson 7 years ago
parent 2c40383524
commit cc3d7648c1

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics;
import io.micrometer.core.annotation.Timed;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
@ -50,6 +51,12 @@ import org.springframework.integration.support.management.IntegrationManagementC
@EnableConfigurationProperties(MetricsProperties.class)
public class MetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
public static CompositeMeterRegistryPostProcessor compositeMeterRegistryPostProcessor() {
return new CompositeMeterRegistryPostProcessor();

@ -44,12 +44,6 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(AtlasProperties.class)
public class AtlasMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
@ConditionalOnMissingBean(AtlasConfig.class)
public AtlasConfig atlasConfig(AtlasProperties atlasProperties) {

@ -45,12 +45,6 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(DatadogProperties.class)
public class DatadogMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
@ConditionalOnMissingBean
public DatadogConfig datadogConfig(DatadogProperties datadogProperties) {

@ -44,12 +44,6 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(GangliaProperties.class)
public class GangliaMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
@ConditionalOnMissingBean
public GangliaConfig gangliaConfig(GangliaProperties gangliaProperties) {

@ -44,12 +44,6 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(GraphiteProperties.class)
public class GraphiteMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
@ConditionalOnMissingBean
public GraphiteConfig graphiteConfig(GraphiteProperties graphiteProperties) {

@ -43,12 +43,6 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(InfluxProperties.class)
public class InfluxMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
@ConditionalOnMissingBean(InfluxConfig.class)
public InfluxConfig influxConfig(InfluxProperties influxProperties) {

@ -44,12 +44,6 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(JmxProperties.class)
public class JmxMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
@ConditionalOnMissingBean
public JmxConfig jmxConfig(JmxProperties jmxProperties) {

@ -46,12 +46,6 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(PrometheusProperties.class)
public class PrometheusMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
@ConditionalOnMissingBean
public PrometheusConfig prometheusConfig(PrometheusProperties prometheusProperties) {

@ -46,12 +46,6 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnMissingBean(MeterRegistry.class)
public class SimpleMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
@ConditionalOnMissingBean(MeterRegistry.class)
public SimpleMeterRegistry simpleMeterRegistry(SimpleConfig config, Clock clock) {

@ -44,12 +44,6 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties(StatsdProperties.class)
public class StatsdMetricsExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public Clock micrometerClock() {
return Clock.SYSTEM;
}
@Bean
@ConditionalOnMissingBean(StatsdConfig.class)
public StatsdConfig statsdConfig(StatsdProperties statsdProperties) {

@ -20,6 +20,7 @@ import java.util.UUID;
import javax.sql.DataSource;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.MockClock;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
@ -180,6 +181,20 @@ public class MetricsAutoConfigurationTests {
});
}
@Test
public void autoConfiguresAClock() {
this.contextRunner.with(MetricsRun.limitedTo())
.run((context) -> assertThat(context).hasSingleBean(Clock.class));
}
@Test
public void allowsCustomClockToBeConfigured() {
this.contextRunner.with(MetricsRun.limitedTo())
.withUserConfiguration(CustomClockConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(Clock.class)
.hasBean("customClock"));
}
@Configuration
static class PrimarySimpleMeterRegistryConfiguration {
@ -211,4 +226,14 @@ public class MetricsAutoConfigurationTests {
}
@Configuration
static class CustomClockConfiguration {
@Bean
public Clock customClock() {
return Clock.SYSTEM;
}
}
}

Loading…
Cancel
Save