Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
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;

Expand All @@ -49,20 +47,14 @@
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
Expand All @@ -76,7 +68,7 @@ private void bindConnectionFactoryToRegistry(String beanName,
ConnectionFactory rabbitConnectionFactory = connectionFactory
.getRabbitConnectionFactory();
String connectionFactoryName = getConnectionFactoryName(beanName);
new RabbitMetrics(rabbitConnectionFactory, this.metricName,
new RabbitMetrics(rabbitConnectionFactory,
Tags.of("name", connectionFactoryName)).bindTo(this.registry);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;
Expand All @@ -37,7 +36,6 @@
@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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,9 +31,7 @@
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;
Expand All @@ -50,8 +48,6 @@
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";
Expand All @@ -60,14 +56,10 @@ public class DataSourcePoolMetricsAutoConfiguration {

private final Collection<DataSourcePoolMetadataProvider> metadataProviders;

private final String metricName;

public DataSourcePoolMetricsAutoConfiguration(MeterRegistry registry,
Collection<DataSourcePoolMetadataProvider> metadataProviders,
JdbcMetricsProperties jdbcMetricsProperties) {
Collection<DataSourcePoolMetadataProvider> metadataProviders) {
this.registry = registry;
this.metadataProviders = metadataProviders;
this.metricName = jdbcMetricsProperties.getMetricName();
}

@Autowired
Expand All @@ -77,8 +69,8 @@ public void bindDataSourcesToRegistry(Map<String, DataSource> dataSources) {

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);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,10 @@ public void autoConfiguredConnectionFactoryIsInstrumented() {
});
}

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void autoConfiguredNonSupportedCacheManagerIsIgnored() {
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand All @@ -42,6 +43,7 @@
public class DataSourcePoolMetricsAutoConfigurationTests {

private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.simple())
.withConfiguration(
AutoConfigurations.of(DataSourcePoolMetricsAutoConfiguration.class))
.withUserConfiguration(BaseConfiguration.class);
Expand All @@ -55,22 +57,7 @@ public void autoConfiguredDataSourceIsInstrumented() {
.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();
});
}
Expand All @@ -81,11 +68,11 @@ public void dataSourceInstrumentationCanBeDisabled() {
.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();
});
}
Expand All @@ -101,9 +88,9 @@ public void allDataSourcesCanBeInstrumented() {
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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,23 @@ public class RabbitMetrics implements MeterBinder {

private final Iterable<Tag> 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<Tag> tags) {
public RabbitMetrics(ConnectionFactory connectionFactory, Iterable<Tag> 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));
}

}
Loading