From 49f21a22647a0e328e145d453f4cc2ef3c73e247 Mon Sep 17 00:00:00 2001 From: Jon Schneider Date: Mon, 12 Feb 2018 17:16:03 -0600 Subject: [PATCH 1/2] Remove unnecessary config options for JDBC, Rabbit, and Cache metrics See gh-12017 --- .../amqp/RabbitMetricsAutoConfiguration.java | 12 +----- .../metrics/amqp/RabbitMetricsProperties.java | 43 ------------------- .../cache/CacheMetricsAutoConfiguration.java | 2 - ...ataSourcePoolMetricsAutoConfiguration.java | 16 ++----- .../metrics/jdbc/JdbcMetricsProperties.java | 43 ------------------- ...itional-spring-configuration-metadata.json | 18 -------- .../RabbitMetricsAutoConfigurationTests.java | 13 +----- .../CacheMetricsAutoConfigurationTests.java | 2 +- ...urcePoolMetricsAutoConfigurationTests.java | 27 +++--------- .../actuate/metrics/amqp/RabbitMetrics.java | 10 +---- .../metrics/jdbc/DataSourcePoolMetrics.java | 18 ++++---- .../metrics/amqp/RabbitMetricsTests.java | 10 ++--- .../jdbc/DataSourcePoolMetricsTests.java | 2 +- 13 files changed, 31 insertions(+), 185 deletions(-) delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsProperties.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/JdbcMetricsProperties.java diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfiguration.java index 56825552ec..caf1ed15e0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfiguration.java @@ -32,8 +32,6 @@ 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; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; @@ -49,20 +47,14 @@ import org.springframework.util.StringUtils; SimpleMetricsExportAutoConfiguration.class }) @ConditionalOnClass({ ConnectionFactory.class, AbstractConnectionFactory.class }) @ConditionalOnBean({ AbstractConnectionFactory.class, MeterRegistry.class }) -@ConditionalOnProperty(value = "management.metrics.rabbitmq.instrument", matchIfMissing = true) -@EnableConfigurationProperties(RabbitMetricsProperties.class) public class RabbitMetricsAutoConfiguration { private static final String CONNECTION_FACTORY_SUFFIX = "connectionFactory"; private final MeterRegistry registry; - private final String metricName; - - public RabbitMetricsAutoConfiguration(MeterRegistry registry, - RabbitMetricsProperties rabbitMetricsProperties) { + public RabbitMetricsAutoConfiguration(MeterRegistry registry) { this.registry = registry; - this.metricName = rabbitMetricsProperties.getMetricName(); } @Autowired @@ -76,7 +68,7 @@ public class RabbitMetricsAutoConfiguration { ConnectionFactory rabbitConnectionFactory = connectionFactory .getRabbitConnectionFactory(); String connectionFactoryName = getConnectionFactoryName(beanName); - new RabbitMetrics(rabbitConnectionFactory, this.metricName, + new RabbitMetrics(rabbitConnectionFactory, Tags.of("name", connectionFactoryName)).bindTo(this.registry); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsProperties.java deleted file mode 100644 index 681cf34808..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsProperties.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - * 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.amqp; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * Configuration properties for RabbitMQ-based metrics. - * - * @author Stephane Nicoll - * @since 2.0.0 - */ -@ConfigurationProperties("management.metrics.rabbitmq") -public class RabbitMetricsProperties { - - /** - * Name of the metric for RabbitMQ usage. - */ - private String metricName = "rabbitmq"; - - public String getMetricName() { - return this.metricName; - } - - public void setMetricName(String metricName) { - this.metricName = metricName; - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfiguration.java index b66bccaa21..afc58ce202 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfiguration.java @@ -21,7 +21,6 @@ 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; import org.springframework.cache.CacheManager; import org.springframework.context.annotation.Configuration; @@ -37,7 +36,6 @@ import org.springframework.context.annotation.Import; @Configuration @AutoConfigureAfter({ MetricsAutoConfiguration.class, CacheAutoConfiguration.class }) @ConditionalOnBean(CacheManager.class) -@ConditionalOnProperty(value = "management.metrics.cache.instrument", matchIfMissing = true) @Import({ CacheMeterBinderProvidersConfiguration.class, CacheMetricsRegistrarConfiguration.class }) public class CacheMetricsAutoConfiguration { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java index 6db7f4975f..ed9ecab975 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java @@ -17,12 +17,12 @@ package org.springframework.boot.actuate.autoconfigure.metrics.jdbc; import java.util.Collection; +import java.util.Collections; import java.util.Map; import javax.sql.DataSource; 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; @@ -31,9 +31,7 @@ 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; @@ -50,8 +48,6 @@ import org.springframework.util.StringUtils; SimpleMetricsExportAutoConfiguration.class }) @ConditionalOnBean({ DataSource.class, DataSourcePoolMetadataProvider.class, MeterRegistry.class }) -@ConditionalOnProperty(value = "management.metrics.jdbc.instrument", matchIfMissing = true) -@EnableConfigurationProperties(JdbcMetricsProperties.class) public class DataSourcePoolMetricsAutoConfiguration { private static final String DATASOURCE_SUFFIX = "dataSource"; @@ -60,14 +56,10 @@ public class DataSourcePoolMetricsAutoConfiguration { private final Collection metadataProviders; - private final String metricName; - public DataSourcePoolMetricsAutoConfiguration(MeterRegistry registry, - Collection metadataProviders, - JdbcMetricsProperties jdbcMetricsProperties) { + Collection metadataProviders) { this.registry = registry; this.metadataProviders = metadataProviders; - this.metricName = jdbcMetricsProperties.getMetricName(); } @Autowired @@ -77,8 +69,8 @@ public class DataSourcePoolMetricsAutoConfiguration { private void bindDataSourceToRegistry(String beanName, DataSource dataSource) { String dataSourceName = getDataSourceName(beanName); - new DataSourcePoolMetrics(dataSource, this.metadataProviders, this.metricName, - Tags.of("name", dataSourceName)).bindTo(this.registry); + new DataSourcePoolMetrics(dataSource, this.metadataProviders, + dataSourceName, Collections.emptyList()).bindTo(this.registry); } /** diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/JdbcMetricsProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/JdbcMetricsProperties.java deleted file mode 100644 index 8d839e0a03..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/JdbcMetricsProperties.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - * 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.jdbc; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * Configuration properties for JDBC-based metrics. - * - * @author Stephane Nicoll - * @since 2.0.0 - */ -@ConfigurationProperties("management.metrics.jdbc") -public class JdbcMetricsProperties { - - /** - * Name of the metric for data source usage. - */ - private String metricName = "data.source"; - - public String getMetricName() { - return this.metricName; - } - - public void setMetricName(String metricName) { - this.metricName = metricName; - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 9292b87717..d44005d147 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -209,24 +209,6 @@ "description": "Whether to enable uptime metrics.", "defaultValue": true }, - { - "name": "management.metrics.cache.instrument", - "type": "java.lang.Boolean", - "description": "Instrument all available caches.", - "defaultValue": true - }, - { - "name": "management.metrics.jdbc.instrument", - "type": "java.lang.Boolean", - "description": "Instrument all available data sources.", - "defaultValue": true - }, - { - "name": "management.metrics.rabbitmq.instrument", - "type": "java.lang.Boolean", - "description": "Instrument all available connection factories.", - "defaultValue": true - }, { "name": "management.trace.http.enabled", "type": "java.lang.Boolean", diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfigurationTests.java index 94e6195430..8fb9d9ec31 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfigurationTests.java @@ -45,21 +45,10 @@ public class RabbitMetricsAutoConfigurationTests { }); } - @Test - public void autoConfiguredConnectionFactoryWithCustomMetricName() { - this.contextRunner - .withPropertyValues("management.metrics.rabbitmq.metric-name=custom.name") - .run((context) -> { - MeterRegistry registry = context.getBean(MeterRegistry.class); - registry.get("custom.name.connections").meter(); - assertThat(registry.find("rabbitmq.connections").meter()).isNull(); - }); - } - @Test public void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() { this.contextRunner - .withPropertyValues("management.metrics.rabbitmq.instrument=false") + .withPropertyValues("management.metrics.enable.rabbitmq=false") .run((context) -> { MeterRegistry registry = context.getBean(MeterRegistry.class); assertThat(registry.find("rabbitmq.connections").meter()).isNull(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfigurationTests.java index 02a95e62c7..b70cca7fe6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMetricsAutoConfigurationTests.java @@ -66,7 +66,7 @@ public class CacheMetricsAutoConfigurationTests { @Test public void cacheInstrumentationCanBeDisabled() { this.contextRunner - .withPropertyValues("management.metrics.cache.instrument=false", + .withPropertyValues("management.metrics.enable.cache=false", "spring.cache.type=caffeine", "spring.cache.cache-names=cache1") .run((context) -> { MeterRegistry registry = context.getBean(MeterRegistry.class); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfigurationTests.java index de70fd09fb..9cee2f7e27 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfigurationTests.java @@ -24,6 +24,7 @@ import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.junit.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.jdbc.DataSourceBuilder; @@ -42,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class DataSourcePoolMetricsAutoConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .with(MetricsRun.simple()) .withConfiguration( AutoConfigurations.of(DataSourcePoolMetricsAutoConfiguration.class)) .withUserConfiguration(BaseConfiguration.class); @@ -55,22 +57,7 @@ public class DataSourcePoolMetricsAutoConfigurationTests { .run((context) -> { context.getBean(DataSource.class).getConnection().getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); - registry.get("data.source.max.connections").tags("name", "dataSource") - .meter(); - }); - } - - @Test - public void autoConfiguredDataSourceWithCustomMetricName() { - this.contextRunner - .withConfiguration( - AutoConfigurations.of(DataSourceAutoConfiguration.class)) - .withPropertyValues("spring.datasource.generate-unique-name=true", - "management.metrics.jdbc.metric-name=custom.name") - .run((context) -> { - context.getBean(DataSource.class).getConnection().getMetaData(); - MeterRegistry registry = context.getBean(MeterRegistry.class); - registry.get("custom.name.max.connections").tags("name", "dataSource") + registry.get("jdbc.max.connections").tags("name", "dataSource") .meter(); }); } @@ -81,11 +68,11 @@ public class DataSourcePoolMetricsAutoConfigurationTests { .withConfiguration( AutoConfigurations.of(DataSourceAutoConfiguration.class)) .withPropertyValues("spring.datasource.generate-unique-name=true", - "management.metrics.jdbc.instrument=false") + "management.metrics.enable.jdbc=false") .run((context) -> { context.getBean(DataSource.class).getConnection().getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); - assertThat(registry.find("data.source.max.connections") + assertThat(registry.find("jdbc.max.connections") .tags("name", "dataSource").meter()).isNull(); }); } @@ -101,9 +88,9 @@ public class DataSourcePoolMetricsAutoConfigurationTests { context.getBean("secondOne", DataSource.class).getConnection() .getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); - registry.get("data.source.max.connections").tags("name", "first") + registry.get("jdbc.max.connections").tags("name", "first") .meter(); - registry.get("data.source.max.connections").tags("name", "secondOne") + registry.get("jdbc.max.connections").tags("name", "secondOne") .meter(); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetrics.java index a83dfc3830..05be8e9eb2 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetrics.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetrics.java @@ -37,29 +37,23 @@ public class RabbitMetrics implements MeterBinder { private final Iterable tags; - private final String name; - private final ConnectionFactory connectionFactory; /** * Create a new meter binder recording the specified {@link ConnectionFactory}. * @param connectionFactory the {@link ConnectionFactory} to instrument - * @param name the name prefix of the metrics * @param tags tags to apply to all recorded metrics */ - public RabbitMetrics(ConnectionFactory connectionFactory, String name, - Iterable tags) { + public RabbitMetrics(ConnectionFactory connectionFactory, Iterable tags) { Assert.notNull(connectionFactory, "ConnectionFactory must not be null"); - Assert.notNull(name, "Name must not be null"); this.connectionFactory = connectionFactory; - this.name = name; this.tags = (tags != null ? tags : Collections.emptyList()); } @Override public void bindTo(MeterRegistry registry) { this.connectionFactory.setMetricsCollector( - new MicrometerMetricsCollector(registry, this.name, this.tags)); + new MicrometerMetricsCollector(registry, "rabbitmq", this.tags)); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java index 7d71193e86..a25d2bc0bb 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java @@ -24,6 +24,7 @@ import javax.sql.DataSource; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.binder.MeterBinder; import org.springframework.boot.jdbc.metadata.CompositeDataSourcePoolMetadataProvider; @@ -45,15 +46,13 @@ public class DataSourcePoolMetrics implements MeterBinder { private final CachingDataSourcePoolMetadataProvider metadataProvider; - private final String name; - private final Iterable tags; public DataSourcePoolMetrics(DataSource dataSource, - Collection metadataProviders, String name, + Collection metadataProviders, String dataSourceName, Iterable tags) { this(dataSource, new CompositeDataSourcePoolMetadataProvider(metadataProviders), - name, tags); + dataSourceName, tags); } public DataSourcePoolMetrics(DataSource dataSource, @@ -64,8 +63,7 @@ public class DataSourcePoolMetrics implements MeterBinder { this.dataSource = dataSource; this.metadataProvider = new CachingDataSourcePoolMetadataProvider( metadataProvider); - this.name = name; - this.tags = tags; + this.tags = Tags.concat(tags, "name", name); } @Override @@ -77,15 +75,15 @@ public class DataSourcePoolMetrics implements MeterBinder { } } - private void bindPoolMetadata(MeterRegistry registry, String name, + private void bindPoolMetadata(MeterRegistry registry, String metricName, Function function) { - bindDataSource(registry, name, this.metadataProvider.getValueFunction(function)); + bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function)); } - private void bindDataSource(MeterRegistry registry, String name, + private void bindDataSource(MeterRegistry registry, String metricName, Function function) { if (function.apply(this.dataSource) != null) { - registry.gauge(this.name + "." + name + ".connections", this.tags, + registry.gauge("jdbc." + metricName + ".connections", this.tags, this.dataSource, (m) -> function.apply(m).doubleValue()); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java index 4f483c30e4..87d54123f1 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java @@ -35,19 +35,19 @@ public class RabbitMetricsTests { public void connectionFactoryIsInstrumented() { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); SimpleMeterRegistry registry = new SimpleMeterRegistry(); - new RabbitMetrics(connectionFactory, "rabbit", null).bindTo(registry); - registry.get("rabbit.connections"); + new RabbitMetrics(connectionFactory, null).bindTo(registry); + registry.get("rabbitmq.connections"); } @Test public void connectionFactoryWithTagsIsInstrumented() { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); SimpleMeterRegistry registry = new SimpleMeterRegistry(); - new RabbitMetrics(connectionFactory, "test", Tags.of("env", "prod")) + new RabbitMetrics(connectionFactory, Tags.of("env", "prod")) .bindTo(registry); - assertThat(registry.get("test.connections").tags("env", "prod").meter()) + assertThat(registry.get("rabbitmq.connections").tags("env", "prod").meter()) .isNotNull(); - assertThat(registry.find("test.connections").tags("env", "dev").meter()).isNull(); + assertThat(registry.find("rabbitmq.connections").tags("env", "dev").meter()).isNull(); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetricsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetricsTests.java index 1e48a31651..8450e19f3b 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetricsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetricsTests.java @@ -51,7 +51,7 @@ public class DataSourcePoolMetricsTests { .run((context) -> { context.getBean(DataSource.class).getConnection().getMetaData(); context.getBean(MeterRegistry.class) - .get("data.source.max.connections").meter(); + .get("jdbc.max.connections").meter(); }); } From b28cabdb127f236ac8786b3e5525b674fc8bb570 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 13 Feb 2018 14:35:45 +0100 Subject: [PATCH 2/2] Polish "Remove unnecessary config options for metrics" Closes gh-12017" --- .../actuate/metrics/jdbc/DataSourcePoolMetrics.java | 4 ++-- .../boot/actuate/metrics/amqp/RabbitMetricsTests.java | 3 ++- .../asciidoc/appendix-application-properties.adoc | 5 ----- .../src/main/asciidoc/production-ready-features.adoc | 11 ++++------- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java index a25d2bc0bb..9fbf200243 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java @@ -80,8 +80,8 @@ public class DataSourcePoolMetrics implements MeterBinder { bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function)); } - private void bindDataSource(MeterRegistry registry, String metricName, - Function function) { + private void bindDataSource(MeterRegistry registry, + String metricName, Function function) { if (function.apply(this.dataSource) != null) { registry.gauge("jdbc." + metricName + ".connections", this.tags, this.dataSource, (m) -> function.apply(m).doubleValue()); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java index 87d54123f1..68abd688f7 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/amqp/RabbitMetricsTests.java @@ -47,7 +47,8 @@ public class RabbitMetricsTests { .bindTo(registry); assertThat(registry.get("rabbitmq.connections").tags("env", "prod").meter()) .isNotNull(); - assertThat(registry.find("rabbitmq.connections").tags("env", "dev").meter()).isNull(); + assertThat(registry.find("rabbitmq.connections").tags("env", "dev").meter()) + .isNull(); } } diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index ede4481c4c..26543ff2cc 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -1300,7 +1300,6 @@ content into your application. Rather, pick only the properties that you need. management.metrics.binders.logback.enabled=true # Whether to enable Logback metrics. management.metrics.binders.processor.enabled=true # Whether to enable processor metrics. management.metrics.binders.uptime.enabled=true # Whether to enable uptime metrics. - management.metrics.cache.instrument=true # Instrument all available caches. management.metrics.distribution.percentiles-histogram.*= # Whether meter IDs starting-with the specified name should be publish percentile histograms. management.metrics.distribution.percentiles.*= # Specific computed non-aggregable percentiles to ship to the backend for meter IDs starting-with the specified name. management.metrics.distribution.sla.*= Specific SLA boundaries for meter IDs starting-with the specified name. The longest match wins, the key `all` can also be used to configure all meters. @@ -1391,10 +1390,6 @@ content into your application. Rather, pick only the properties that you need. management.metrics.export.statsd.polling-frequency=10s # How often gauges will be polled. When a gauge is polled, its value is recalculated and if the value has changed, it is sent to the StatsD server. management.metrics.export.statsd.port=8125 # Port of the StatsD server to receive exported metrics. management.metrics.export.statsd.queue-size=2147483647 # Maximum size of the queue of items waiting to be sent to the StatsD server. - management.metrics.jdbc.instrument=true # Instrument all available data sources. - management.metrics.jdbc.metric-name=data.source # Name of the metric for data source usage. - management.metrics.rabbitmq.instrument=true # Instrument all available connection factories. - management.metrics.rabbitmq.metric-name=rabbitmq # Name of the metric for RabbitMQ usage. management.metrics.use-global-registry=true # Whether auto-configured MeterRegistry implementations should be bound to the global static registry on Metrics. management.metrics.web.client.max-uri-tags=100 # Maximum number of unique URI tag values allowed. After the max number of tag values is reached, metrics with additional tag values are denied by filter. management.metrics.web.client.record-request-percentiles=false # Whether instrumented requests record percentiles histogram buckets by default. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 2ebc8da37f..a25d818f69 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -1243,11 +1243,9 @@ is required. A `CacheMetricsRegistrar` bean is made available to make that proce [[production-ready-metrics-jdbc]] === DataSource Metrics Auto-configuration enables the instrumentation of all available ``DataSource`` objects -with a metric named `data.source`. Data source instrumentation results in gauges -representing the currently active, maximum allowed, and minimum allowed connections in the -pool. Each of these gauges has a name that is prefixed by `data.source` by default. The -prefix can be customized by setting the `management.metrics.jdbc.metric-name` -property. +with a metric named `jdbc`. Data source instrumentation results in gauges representing the +currently active, maximum allowed, and minimum allowed connections in the pool. Each of +these gauges has a name that is prefixed by `jdbc`. Metrics are also tagged by the name of the `DataSource` computed based on the bean name. @@ -1256,8 +1254,7 @@ Metrics are also tagged by the name of the `DataSource` computed based on the be [[production-ready-metrics-rabbitmq]] === RabbitMQ metrics Auto-configuration will enable the instrumentation of all available RabbitMQ connection -factories with a metric named `rabbitmq`. The prefix can be customized by using the -`management.metrics.rabbitmq.metric-name` property. +factories with a metric named `rabbitmq`.