Migrate all of metrics to auto-configuration

Migrate remaining metrics `@Configuration` classes to individual
auto-configurations.

Fixes gh-11935
pull/11971/merge
Phillip Webb 7 years ago
parent 6f7f11fd96
commit 204f6f67fd

@ -1,84 +0,0 @@
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.metrics;
import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
import io.micrometer.core.instrument.binder.logging.LogbackMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Configuration for various {@link MeterBinder MeterBinders}.
*
* @author Jon Schneider
*/
@Configuration
class MeterBindersConfiguration {
@Bean
@ConditionalOnProperty(value = "management.metrics.binders.jvm.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public JvmGcMetrics jvmGcMetrics() {
return new JvmGcMetrics();
}
@Bean
@ConditionalOnProperty(value = "management.metrics.binders.jvm.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public JvmMemoryMetrics jvmMemoryMetrics() {
return new JvmMemoryMetrics();
}
@Bean
@ConditionalOnProperty(value = "management.metrics.binders.jvm.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public JvmThreadMetrics jvmThreadMetrics() {
return new JvmThreadMetrics();
}
@Bean
@ConditionalOnMissingBean(LogbackMetrics.class)
@ConditionalOnProperty(value = "management.metrics.binders.logback.enabled", matchIfMissing = true)
@ConditionalOnClass(name = "ch.qos.logback.classic.Logger")
public LogbackMetrics logbackMetrics() {
return new LogbackMetrics();
}
@Bean
@ConditionalOnProperty(value = "management.metrics.binders.uptime.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public UptimeMetrics uptimeMetrics() {
return new UptimeMetrics();
}
@Bean
@ConditionalOnProperty(value = "management.metrics.binders.processor.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public ProcessorMetrics processorMetrics() {
return new ProcessorMetrics();
}
}

@ -17,28 +17,23 @@
package org.springframework.boot.actuate.autoconfigure.metrics;
import io.micrometer.core.annotation.Timed;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
import io.micrometer.core.instrument.binder.logging.LogbackMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.reactive.server.WebFluxMetricsConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.web.client.RestTemplateMetricsConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.web.servlet.WebMvcMetricsConfiguration;
import org.springframework.boot.actuate.metrics.integration.SpringIntegrationMetrics;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
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.SearchStrategy;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.integration.config.EnableIntegrationManagement;
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
@ -53,12 +48,6 @@ import org.springframework.integration.support.management.IntegrationManagementC
@Configuration
@ConditionalOnClass(Timed.class)
@EnableConfigurationProperties(MetricsProperties.class)
@Import({ MeterBindersConfiguration.class, WebMvcMetricsConfiguration.class,
WebFluxMetricsConfiguration.class, RestTemplateMetricsConfiguration.class,
CacheMetricsConfiguration.class, DataSourcePoolMetricsConfiguration.class,
RabbitMetricsConfiguration.class })
@AutoConfigureAfter({ CacheAutoConfiguration.class, DataSourceAutoConfiguration.class,
RabbitAutoConfiguration.class, RestTemplateAutoConfiguration.class })
public class MetricsAutoConfiguration {
@Bean
@ -78,6 +67,56 @@ public class MetricsAutoConfiguration {
return new PropertiesMeterFilter(properties);
}
@Configuration
@ConditionalOnProperty(value = "management.metrics.binders.jvm.enabled", matchIfMissing = true)
static class JvmMeterBindersConfiguration {
@Bean
@ConditionalOnMissingBean
public JvmGcMetrics jvmGcMetrics() {
return new JvmGcMetrics();
}
@Bean
@ConditionalOnMissingBean
public JvmMemoryMetrics jvmMemoryMetrics() {
return new JvmMemoryMetrics();
}
@Bean
@ConditionalOnMissingBean
public JvmThreadMetrics jvmThreadMetrics() {
return new JvmThreadMetrics();
}
}
static class MeterBindersConfiguration {
@Bean
@ConditionalOnClass(name = "ch.qos.logback.classic.Logger")
@ConditionalOnMissingBean(LogbackMetrics.class)
@ConditionalOnProperty(value = "management.metrics.binders.logback.enabled", matchIfMissing = true)
public LogbackMetrics logbackMetrics() {
return new LogbackMetrics();
}
@Bean
@ConditionalOnProperty(value = "management.metrics.binders.uptime.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public UptimeMetrics uptimeMetrics() {
return new UptimeMetrics();
}
@Bean
@ConditionalOnProperty(value = "management.metrics.binders.processor.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public ProcessorMetrics processorMetrics() {
return new ProcessorMetrics();
}
}
/**
* Binds metrics from Spring Integration.
*/

@ -24,7 +24,11 @@ import io.micrometer.core.instrument.Tags;
import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.metrics.amqp.RabbitMetrics;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -33,17 +37,19 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
/**
* Configure metrics for all available {@link ConnectionFactory connection factories}.
* {@link EnableAutoConfiguration Auto-configuration} for metrics on all available
* {@link ConnectionFactory connection factories}.
*
* @author Stephane Nicoll
* @since 2.0.0
*/
@Configuration
@AutoConfigureAfter({ MetricsAutoConfiguration.class, RabbitAutoConfiguration.class })
@ConditionalOnClass({ ConnectionFactory.class, AbstractConnectionFactory.class })
@ConditionalOnBean(AbstractConnectionFactory.class)
@ConditionalOnProperty(value = "management.metrics.rabbitmq.instrument", matchIfMissing = true)
@EnableConfigurationProperties(RabbitMetricsProperties.class)
public class RabbitMetricsConfiguration {
public class RabbitMetricsAutoConfiguration {
private static final String CONNECTION_FACTORY_SUFFIX = "connectionFactory";
@ -51,7 +57,7 @@ public class RabbitMetricsConfiguration {
private final String metricName;
public RabbitMetricsConfiguration(MeterRegistry registry,
public RabbitMetricsAutoConfiguration(MeterRegistry registry,
RabbitMetricsProperties rabbitMetricsProperties) {
this.registry = registry;
this.metricName = rabbitMetricsProperties.getMetricName();

@ -16,6 +16,10 @@
package org.springframework.boot.actuate.autoconfigure.metrics.cache;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.Cache;
@ -24,16 +28,18 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Configure metrics for all available {@link Cache caches}.
* {@link EnableAutoConfiguration Auto-configuration} for metrics on all available
* {@link Cache caches}.
*
* @author Stephane Nicoll
* @since 2.0.0
*/
@Configuration
@AutoConfigureAfter({ MetricsAutoConfiguration.class, CacheAutoConfiguration.class })
@ConditionalOnBean(CacheManager.class)
@ConditionalOnProperty(value = "management.metrics.cache.instrument", matchIfMissing = true)
@Import({ CacheMeterBinderProvidersConfiguration.class,
CacheMetricsRegistrarConfiguration.class })
public class CacheMetricsConfiguration {
public class CacheMetricsAutoConfiguration {
}

@ -25,25 +25,31 @@ import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.metrics.jdbc.DataSourcePoolMetrics;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
/**
* Configure metrics for all available {@link DataSource datasources}.
* {@link EnableAutoConfiguration Auto-configuration} for metrics on all available
* {@link DataSource datasources}.
*
* @author Stephane Nicoll
* @since 2.0.0
*/
@Configuration
@AutoConfigureAfter({ MetricsAutoConfiguration.class, DataSourceAutoConfiguration.class })
@ConditionalOnBean({ DataSource.class, DataSourcePoolMetadataProvider.class })
@ConditionalOnProperty(value = "management.metrics.jdbc.instrument", matchIfMissing = true)
@EnableConfigurationProperties(JdbcMetricsProperties.class)
public class DataSourcePoolMetricsConfiguration {
public class DataSourcePoolMetricsAutoConfiguration {
private static final String DATASOURCE_SUFFIX = "dataSource";
@ -53,7 +59,7 @@ public class DataSourcePoolMetricsConfiguration {
private final String metricName;
public DataSourcePoolMetricsConfiguration(MeterRegistry registry,
public DataSourcePoolMetricsAutoConfiguration(MeterRegistry registry,
Collection<DataSourcePoolMetadataProvider> metadataProviders,
JdbcMetricsProperties jdbcMetricsProperties) {
this.registry = registry;

@ -25,27 +25,34 @@ import io.micrometer.core.instrument.config.MeterFilterReply;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties;
import org.springframework.boot.actuate.metrics.web.client.DefaultRestTemplateExchangeTagsProvider;
import org.springframework.boot.actuate.metrics.web.client.MetricsRestTemplateCustomizer;
import org.springframework.boot.actuate.metrics.web.client.RestTemplateExchangeTagsProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.client.RestTemplate;
/**
* Configuration for {@link RestTemplate}-related metrics.
* {@link EnableAutoConfiguration Auto-configuration} for {@link RestTemplate}-related
* metrics.
*
* @author Jon Schneider
* @author Phillip Webb
* @since 2.0.0
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
public class RestTemplateMetricsConfiguration {
@AutoConfigureAfter({ MetricsAutoConfiguration.class,
RestTemplateAutoConfiguration.class })
@ConditionalOnClass(RestTemplate.class)
public class RestTemplateMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean(RestTemplateExchangeTagsProvider.class)
@ -78,7 +85,7 @@ public class RestTemplateMetricsConfiguration {
private static class MaximumUriTagsReachedMeterFilter implements MeterFilter {
private final Logger logger = LoggerFactory
.getLogger(RestTemplateMetricsConfiguration.class);
.getLogger(RestTemplateMetricsAutoConfiguration.class);
private final String metricName;

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,29 +14,33 @@
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.metrics.reactive.server;
package org.springframework.boot.actuate.autoconfigure.metrics.web.reactive;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties;
import org.springframework.boot.actuate.metrics.web.reactive.server.DefaultWebFluxTagsProvider;
import org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter;
import org.springframework.boot.actuate.metrics.web.reactive.server.WebFluxTagsProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Configures instrumentation of Spring Webflux MVC annotation-based programming model
* request mappings.
* {@link EnableAutoConfiguration Auto-configuration} for instrumentation of Spring
* Webflux MVC annotation-based programming model request mappings.
*
* @author Jon Schneider
* @since 2.0.0
*/
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@Configuration
public class WebFluxMetricsConfiguration {
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
public class WebFluxMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean(WebFluxTagsProvider.class)

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,4 +17,4 @@
/**
* Auto-configuration for WebFlux actuator metrics.
*/
package org.springframework.boot.actuate.autoconfigure.metrics.reactive.server;
package org.springframework.boot.actuate.autoconfigure.metrics.web.reactive;

@ -20,11 +20,14 @@ import javax.servlet.DispatcherType;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties.Web.Server;
import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider;
import org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter;
import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
@ -36,16 +39,18 @@ import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
/**
* Configures instrumentation of Spring Web MVC servlet-based request mappings.
* {@link EnableAutoConfiguration Auto-configuration} for instrumentation of Spring Web
* MVC servlet-based request mappings.
*
* @author Jon Schneider
* @since 2.0.0
*/
@Configuration
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnClass(DispatcherServlet.class)
@EnableConfigurationProperties(MetricsProperties.class)
public class WebMvcMetricsConfiguration {
public class WebMvcMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean(WebMvcTagsProvider.class)

@ -34,6 +34,8 @@ org.springframework.boot.actuate.autoconfigure.management.HeapDumpWebEndpointAut
org.springframework.boot.actuate.autoconfigure.management.ThreadDumpEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.MetricsEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.export.atlas.AtlasMetricsExportAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.export.datadog.DatadogMetricsExportAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.export.ganglia.GangliaMetricsExportAutoConfiguration,\
@ -43,6 +45,10 @@ org.springframework.boot.actuate.autoconfigure.metrics.export.jmx.JmxMetricsExpo
org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.export.statsd.StatsdMetricsExportAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.web.client.RestTemplateMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.web.reactive.WebFluxMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.web.servlet.WebMvcMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.mongo.MongoHealthIndicatorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.neo4j.Neo4jHealthIndicatorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.redis.RedisHealthIndicatorAutoConfiguration,\
@ -56,7 +62,6 @@ org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoC
org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.web.trace.HttpTraceAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.web.trace.HttpTraceEndpointAutoConfiguration
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=\
org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration,\
org.springframework.boot.actuate.autoconfigure.endpoint.web.reactive.WebFluxEndpointManagementContextConfiguration,\

@ -27,13 +27,13 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link RabbitMetricsConfiguration}.
* Tests for {@link RabbitMetricsAutoConfiguration}.
*
* @author Stephane Nicoll
*/
public class RabbitMetricsConfigurationTests {
public class RabbitMetricsAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(RabbitAutoConfiguration.class));

@ -29,13 +29,13 @@ import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CacheMetricsConfiguration}.
* Tests for {@link CacheMetricsAutoConfiguration}.
*
* @author Stephane Nicoll
*/
public class CacheMetricsConfigurationTests {
public class CacheMetricsAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.simple()).withUserConfiguration(CachingConfiguration.class)
.withConfiguration(AutoConfigurations.of(CacheAutoConfiguration.class));

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.actuate.autoconfigure.metrics;
package org.springframework.boot.actuate.autoconfigure.metrics.test;
import java.util.Collections;
import java.util.Map;
@ -34,6 +34,13 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.web.client.RestTemplateMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.web.reactive.WebFluxMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.web.servlet.WebMvcMetricsAutoConfiguration;
import org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
@ -69,14 +76,14 @@ import static org.springframework.test.web.client.match.MockRestRequestMatchers.
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
/**
* Integration tests for {@link MetricsAutoConfiguration}.
* Integration tests for Metrics.
*
* @author Jon Schneider
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = MetricsAutoConfigurationIntegrationTests.MetricsApp.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = MetricsIntegrationTests.MetricsApp.class)
@TestPropertySource(properties = "management.metrics.use-global-registry=false")
public class MetricsAutoConfigurationIntegrationTests {
public class MetricsIntegrationTests {
@Autowired
private ApplicationContext context;
@ -134,6 +141,10 @@ public class MetricsAutoConfigurationIntegrationTests {
@Configuration
@ImportAutoConfiguration({ MetricsAutoConfiguration.class,
RabbitMetricsAutoConfiguration.class, CacheMetricsAutoConfiguration.class,
DataSourcePoolMetricsAutoConfiguration.class,
RestTemplateMetricsAutoConfiguration.class,
WebFluxMetricsAutoConfiguration.class, WebMvcMetricsAutoConfiguration.class,
JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
RestTemplateAutoConfiguration.class, WebMvcAutoConfiguration.class,
DispatcherServletAutoConfiguration.class,

@ -22,6 +22,8 @@ import java.util.Set;
import java.util.function.Function;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.atlas.AtlasMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.datadog.DatadogMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ganglia.GangliaMetricsExportAutoConfiguration;
@ -31,6 +33,10 @@ import org.springframework.boot.actuate.autoconfigure.metrics.export.jmx.JmxMetr
import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.statsd.StatsdMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.web.client.RestTemplateMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.web.reactive.WebFluxMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.web.servlet.WebMvcMetricsAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.util.Assert;
@ -44,7 +50,7 @@ import org.springframework.util.Assert;
*/
public final class MetricsRun {
private static final Set<Class<?>> IMPLEMENTATIONS;
private static final Set<Class<?>> EXPORT_AUTO_CONFIGURATIONS;
static {
Set<Class<?>> implementations = new LinkedHashSet<>();
@ -57,9 +63,16 @@ public final class MetricsRun {
implementations.add(PrometheusMetricsExportAutoConfiguration.class);
implementations.add(SimpleMetricsExportAutoConfiguration.class);
implementations.add(StatsdMetricsExportAutoConfiguration.class);
IMPLEMENTATIONS = Collections.unmodifiableSet(implementations);
EXPORT_AUTO_CONFIGURATIONS = Collections.unmodifiableSet(implementations);
}
private static final AutoConfigurations AUTO_CONFIGURATIONS = AutoConfigurations.of(
MetricsAutoConfiguration.class, RabbitMetricsAutoConfiguration.class,
CacheMetricsAutoConfiguration.class,
DataSourcePoolMetricsAutoConfiguration.class,
RestTemplateMetricsAutoConfiguration.class,
WebFluxMetricsAutoConfiguration.class, WebMvcMetricsAutoConfiguration.class);
private MetricsRun() {
}
@ -75,24 +88,24 @@ public final class MetricsRun {
/**
* Return a function that configures the run to be limited to the specified
* implementations.
* @param implementations the implementations to include
* @param exportAutoConfigurations the export auto-configurations to include
* @return the function to apply
*/
public static Function<ApplicationContextRunner, ApplicationContextRunner> limitedTo(
Class<?>... implementations) {
return (contextRunner) -> apply(contextRunner, implementations);
Class<?>... exportAutoConfigurations) {
return (contextRunner) -> apply(contextRunner, exportAutoConfigurations);
}
private static ApplicationContextRunner apply(ApplicationContextRunner contextRunner,
Class<?>[] implementations) {
for (Class<?> implementation : implementations) {
Assert.state(IMPLEMENTATIONS.contains(implementation),
"Unknown implementation " + implementation.getName());
Class<?>[] exportAutoConfigurations) {
for (Class<?> configuration : exportAutoConfigurations) {
Assert.state(EXPORT_AUTO_CONFIGURATIONS.contains(configuration),
"Unknown export auto-configuration " + configuration.getName());
}
return contextRunner
.withPropertyValues("management.metrics.use-global-registry=false")
.withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(implementations));
.withConfiguration(AUTO_CONFIGURATIONS)
.withConfiguration(AutoConfigurations.of(exportAutoConfigurations));
}
}

@ -37,12 +37,12 @@ import static org.springframework.test.web.client.match.MockRestRequestMatchers.
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
/**
* Tests for {@link RestTemplateMetricsConfiguration}.
* Tests for {@link RestTemplateMetricsAutoConfiguration}.
*
* @author Stephane Nicoll
* @author Jon Schneider
*/
public class RestTemplateMetricsConfigurationTests {
public class RestTemplateMetricsAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.simple()).withConfiguration(
Loading…
Cancel
Save