Deprecate micrometer meter's enabled flags

This commit deprecates the few 'enabled' flags that control whether
certain meter binders are registered in the context.

Metrics auto-configuration for the JVM, Logback and System-related
information have been moved to individual auto-configurations so that
they can be excluded rather than using the now deprecated flag.

This harmonizes our policy with regards to disabling behaviour,
especially since other similar auto-configurations do not have such
flag.

Closes gh-13408
pull/14247/merge
Stephane Nicoll 6 years ago
parent 79a964e563
commit a170bfcc76

@ -0,0 +1,71 @@
/*
* 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;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
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 org.springframework.boot.autoconfigure.AutoConfigureAfter;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* {@link EnableAutoConfiguration Auto-configuration} for JVM metrics.
*
* @author Stephane Nicoll
* @since 2.1.0
*/
@Configuration
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnClass(MeterRegistry.class)
@ConditionalOnBean(MeterRegistry.class)
@ConditionalOnProperty(value = "management.metrics.binders.jvm.enabled", matchIfMissing = true)
public class JvmMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public JvmGcMetrics jvmGcMetrics() {
return new JvmGcMetrics();
}
@Bean
@ConditionalOnMissingBean
public JvmMemoryMetrics jvmMemoryMetrics() {
return new JvmMemoryMetrics();
}
@Bean
@ConditionalOnMissingBean
public JvmThreadMetrics jvmThreadMetrics() {
return new JvmThreadMetrics();
}
@Bean
@ConditionalOnMissingBean
public ClassLoaderMetrics classLoaderMetrics() {
return new ClassLoaderMetrics();
}
}

@ -0,0 +1,80 @@
/*
* 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;
import ch.qos.logback.classic.LoggerContext;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.logging.LogbackMetrics;
import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.autoconfigure.metrics.LogbackMetricsAutoConfiguration.LogbackLoggingCondition;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
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.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.AnnotatedTypeMetadata;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Logback metrics.
*
* @author Stephane Nicoll
* @since 2.1.0
*/
@Configuration
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnClass({ MeterRegistry.class, LoggerContext.class, LoggerFactory.class })
@ConditionalOnBean(MeterRegistry.class)
@Conditional(LogbackLoggingCondition.class)
@ConditionalOnProperty(value = "management.metrics.binders.logback.enabled", matchIfMissing = true)
public class LogbackMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public LogbackMetrics logbackMetrics() {
return new LogbackMetrics();
}
static class LogbackLoggingCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
ConditionMessage.Builder message = ConditionMessage
.forCondition("LogbackLoggingCondition");
if (loggerFactory instanceof LoggerContext) {
return ConditionOutcome.match(
message.because("ILoggerFactory is a Logback LoggerContext"));
}
return ConditionOutcome
.noMatch(message.because("ILoggerFactory is an instance of "
+ loggerFactory.getClass().getCanonicalName()));
}
}
}

@ -16,36 +16,18 @@
package org.springframework.boot.actuate.autoconfigure.metrics; package org.springframework.boot.actuate.autoconfigure.metrics;
import ch.qos.logback.classic.LoggerContext;
import io.micrometer.core.annotation.Timed; import io.micrometer.core.annotation.Timed;
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
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.FileDescriptorMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.core.type.AnnotatedTypeMetadata;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for Micrometer-based metrics. * {@link EnableAutoConfiguration Auto-configuration} for Micrometer-based metrics.
@ -78,89 +60,4 @@ public class MetricsAutoConfiguration {
return new PropertiesMeterFilter(properties); 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();
}
@Bean
@ConditionalOnMissingBean
public ClassLoaderMetrics classLoaderMetrics() {
return new ClassLoaderMetrics();
}
}
@Configuration
static class MeterBindersConfiguration {
@Bean
@ConditionalOnClass(name = { "ch.qos.logback.classic.LoggerContext",
"org.slf4j.LoggerFactory" })
@Conditional(LogbackLoggingCondition.class)
@ConditionalOnMissingBean
@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();
}
@Bean
@ConditionalOnProperty(name = "management.metrics.binders.files.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public FileDescriptorMetrics fileDescriptorMetrics() {
return new FileDescriptorMetrics();
}
}
static class LogbackLoggingCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
ConditionMessage.Builder message = ConditionMessage
.forCondition("LogbackLoggingCondition");
if (loggerFactory instanceof LoggerContext) {
return ConditionOutcome.match(
message.because("ILoggerFactory is a Logback LoggerContext"));
}
return ConditionOutcome
.noMatch(message.because("ILoggerFactory is an instance of "
+ loggerFactory.getClass().getCanonicalName()));
}
}
} }

@ -0,0 +1,66 @@
/*
* 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;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
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.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;
/**
* {@link EnableAutoConfiguration Auto-configuration} for system metrics.
*
* @author Stephane Nicoll
* @since 2.1.0
*/
@Configuration
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnClass(MeterRegistry.class)
@ConditionalOnBean(MeterRegistry.class)
public class SystemMetricsAutoConfiguration {
@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();
}
@Bean
@ConditionalOnProperty(name = "management.metrics.binders.files.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
public FileDescriptorMetrics fileDescriptorMetrics() {
return new FileDescriptorMetrics();
}
}

@ -192,31 +192,49 @@
"name": "management.metrics.binders.files.enabled", "name": "management.metrics.binders.files.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"description": "Whether to enable files metrics.", "description": "Whether to enable files metrics.",
"defaultValue": true "defaultValue": true,
"deprecation": {
"replacement": "management.metrics.enable.process.files",
"reason": "Instead, filter 'process.files' metrics."
}
}, },
{ {
"name": "management.metrics.binders.jvm.enabled", "name": "management.metrics.binders.jvm.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"description": "Whether to enable JVM metrics.", "description": "Whether to enable JVM metrics.",
"defaultValue": true "defaultValue": true,
"deprecation": {
"replacement": "management.metrics.enable.jvm",
"reason": "Instead, disable JvmMetricsAutoConfiguration or filter 'jvm' metrics."
}
}, },
{ {
"name": "management.metrics.binders.logback.enabled", "name": "management.metrics.binders.logback.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"description": "Whether to enable Logback metrics.", "description": "Whether to enable Logback metrics.",
"defaultValue": true "defaultValue": true,
"deprecation": {
"replacement": "management.metrics.enable.logback",
"reason": "Instead, disable LogbackMetricsAutoConfiguration or filter 'logback' metrics."
}
}, },
{ {
"name": "management.metrics.binders.processor.enabled", "name": "management.metrics.binders.processor.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"description": "Whether to enable processor metrics.", "description": "Whether to enable processor metrics.",
"defaultValue": true "defaultValue": true,
"deprecation": {
"reason": "Instead, filter 'system.cpu' and 'process.cpu' metrics."
}
}, },
{ {
"name": "management.metrics.binders.uptime.enabled", "name": "management.metrics.binders.uptime.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"description": "Whether to enable uptime metrics.", "description": "Whether to enable uptime metrics.",
"defaultValue": true "defaultValue": true,
"deprecation": {
"reason": "Instead, filter 'process.uptime' and 'process.start.time' metrics."
}
}, },
{ {
"name": "management.metrics.export.jmx.enabled", "name": "management.metrics.export.jmx.enabled",

@ -34,8 +34,11 @@ org.springframework.boot.actuate.autoconfigure.mail.MailHealthIndicatorAutoConfi
org.springframework.boot.actuate.autoconfigure.management.HeapDumpWebEndpointAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.management.HeapDumpWebEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.management.ThreadDumpEndpointAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.management.ThreadDumpEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.JvmMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.LogbackMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.MetricsEndpointAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.MetricsEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.SystemMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.export.atlas.AtlasMetricsExportAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.metrics.export.atlas.AtlasMetricsExportAutoConfiguration,\

@ -0,0 +1,147 @@
/*
* 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;
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
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 org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link JvmMetricsAutoConfiguration}.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
public class JvmMetricsAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(JvmMetricsAutoConfiguration.class));
@Test
public void autoConfiguresJvmMetrics() {
this.contextRunner.run((context) -> assertThat(context)
.hasSingleBean(JvmGcMetrics.class).hasSingleBean(JvmMemoryMetrics.class)
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class));
}
@Test
@Deprecated
public void allowsJvmMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.jvm.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(JvmGcMetrics.class)
.doesNotHaveBean(JvmMemoryMetrics.class)
.doesNotHaveBean(JvmThreadMetrics.class)
.doesNotHaveBean(ClassLoaderMetrics.class));
}
@Test
public void allowsCustomJvmGcMetricsToBeUsed() {
this.contextRunner.withUserConfiguration(CustomJvmGcMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
.hasBean("customJvmGcMetrics")
.hasSingleBean(JvmMemoryMetrics.class)
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class));
}
@Test
public void allowsCustomJvmMemoryMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomJvmMemoryMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
.hasSingleBean(JvmMemoryMetrics.class)
.hasBean("customJvmMemoryMetrics")
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class));
}
@Test
public void allowsCustomJvmThreadMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomJvmThreadMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
.hasSingleBean(JvmMemoryMetrics.class)
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class)
.hasBean("customJvmThreadMetrics"));
}
@Test
public void allowsCustomClassLoaderMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomClassLoaderMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
.hasSingleBean(JvmMemoryMetrics.class)
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class)
.hasBean("customClassLoaderMetrics"));
}
@Configuration
static class CustomJvmGcMetricsConfiguration {
@Bean
public JvmGcMetrics customJvmGcMetrics() {
return new JvmGcMetrics();
}
}
@Configuration
static class CustomJvmMemoryMetricsConfiguration {
@Bean
public JvmMemoryMetrics customJvmMemoryMetrics() {
return new JvmMemoryMetrics();
}
}
@Configuration
static class CustomJvmThreadMetricsConfiguration {
@Bean
public JvmThreadMetrics customJvmThreadMetrics() {
return new JvmThreadMetrics();
}
}
@Configuration
static class CustomClassLoaderMetricsConfiguration {
@Bean
public ClassLoaderMetrics customClassLoaderMetrics() {
return new ClassLoaderMetrics();
}
}
}

@ -0,0 +1,74 @@
/*
* 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;
import io.micrometer.core.instrument.binder.logging.LogbackMetrics;
import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link LogbackMetricsAutoConfiguration}.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
public class LogbackMetricsAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.simple()).withConfiguration(
AutoConfigurations.of(LogbackMetricsAutoConfiguration.class));
@Test
public void autoConfiguresLogbackMetrics() {
this.contextRunner.run(
(context) -> assertThat(context).hasSingleBean(LogbackMetrics.class));
}
@Test
@Deprecated
public void allowsLogbackMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.logback.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(LogbackMetrics.class));
}
@Test
public void allowsCustomLogbackMetricsToBeUsed() {
this.contextRunner.withUserConfiguration(CustomLogbackMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(LogbackMetrics.class)
.hasBean("customLogbackMetrics"));
}
@Configuration
static class CustomLogbackMetricsConfiguration {
@Bean
public LogbackMetrics customLogbackMetrics() {
return new LogbackMetrics();
}
}
}

@ -23,6 +23,7 @@ import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.atlas.AtlasMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.atlas.AtlasMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun; import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
/** /**
@ -34,7 +35,8 @@ public class MeterRegistryConfigurerIntegrationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.limitedTo(AtlasMetricsExportAutoConfiguration.class, .with(MetricsRun.limitedTo(AtlasMetricsExportAutoConfiguration.class,
PrometheusMetricsExportAutoConfiguration.class)); PrometheusMetricsExportAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(JvmMetricsAutoConfiguration.class));
@Test @Test
public void binderMetricsAreSearchableFromTheComposite() { public void binderMetricsAreSearchableFromTheComposite() {

@ -24,6 +24,7 @@ import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.atlas.AtlasMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.atlas.AtlasMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun; import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -40,7 +41,8 @@ public class MeterRegistryCustomizerTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.limitedTo(AtlasMetricsExportAutoConfiguration.class, .with(MetricsRun.limitedTo(AtlasMetricsExportAutoConfiguration.class,
PrometheusMetricsExportAutoConfiguration.class)); PrometheusMetricsExportAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(JvmMetricsAutoConfiguration.class));
@Test @Test
public void commonTagsAreAppliedToAutoConfiguredBinders() { public void commonTagsAreAppliedToAutoConfiguredBinders() {

@ -21,14 +21,6 @@ import java.util.List;
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder; import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
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.FileDescriptorMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import io.micrometer.core.instrument.config.MeterFilter; import io.micrometer.core.instrument.config.MeterFilter;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.junit.Test; import org.junit.Test;
@ -83,155 +75,6 @@ public class MetricsAutoConfigurationTests {
}); });
} }
@Test
public void autoConfiguresJvmMetrics() {
this.contextRunner.run((context) -> assertThat(context)
.hasSingleBean(JvmGcMetrics.class).hasSingleBean(JvmMemoryMetrics.class)
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class));
}
@Test
public void allowsJvmMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.jvm.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(JvmGcMetrics.class)
.doesNotHaveBean(JvmMemoryMetrics.class)
.doesNotHaveBean(JvmThreadMetrics.class)
.doesNotHaveBean(ClassLoaderMetrics.class));
}
@Test
public void allowsCustomJvmGcMetricsToBeUsed() {
this.contextRunner.withUserConfiguration(CustomJvmGcMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
.hasBean("customJvmGcMetrics")
.hasSingleBean(JvmMemoryMetrics.class)
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class));
}
@Test
public void allowsCustomJvmMemoryMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomJvmMemoryMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
.hasSingleBean(JvmMemoryMetrics.class)
.hasBean("customJvmMemoryMetrics")
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class));
}
@Test
public void allowsCustomJvmThreadMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomJvmThreadMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
.hasSingleBean(JvmMemoryMetrics.class)
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class)
.hasBean("customJvmThreadMetrics"));
}
@Test
public void allowsCustomClassLoaderMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomClassLoaderMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class)
.hasSingleBean(JvmMemoryMetrics.class)
.hasSingleBean(JvmThreadMetrics.class)
.hasSingleBean(ClassLoaderMetrics.class)
.hasBean("customClassLoaderMetrics"));
}
@Test
public void autoConfiguresLogbackMetrics() {
this.contextRunner.run(
(context) -> assertThat(context).hasSingleBean(LogbackMetrics.class));
}
@Test
public void allowsLogbackMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.logback.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(LogbackMetrics.class));
}
@Test
public void allowsCustomLogbackMetricsToBeUsed() {
this.contextRunner.withUserConfiguration(CustomLogbackMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(LogbackMetrics.class)
.hasBean("customLogbackMetrics"));
}
@Test
public void autoConfiguresUptimeMetrics() {
this.contextRunner
.run((context) -> assertThat(context).hasSingleBean(UptimeMetrics.class));
}
@Test
public void allowsUptimeMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.uptime.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(UptimeMetrics.class));
}
@Test
public void allowsCustomUptimeMetricsToBeUsed() {
this.contextRunner.withUserConfiguration(CustomUptimeMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(UptimeMetrics.class)
.hasBean("customUptimeMetrics"));
}
@Test
public void autoConfiguresProcessorMetrics() {
this.contextRunner.run(
(context) -> assertThat(context).hasSingleBean(ProcessorMetrics.class));
}
@Test
public void allowsProcessorMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.processor.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(ProcessorMetrics.class));
}
@Test
public void allowsCustomProcessorMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomProcessorMetricsConfiguration.class)
.run((context) -> assertThat(context)
.hasSingleBean(ProcessorMetrics.class)
.hasBean("customProcessorMetrics"));
}
@Test
public void autoConfiguresFileDescriptorMetrics() {
this.contextRunner.run((context) -> assertThat(context)
.hasSingleBean(FileDescriptorMetrics.class));
}
@Test
public void allowsFileDescriptorMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.files.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(FileDescriptorMetrics.class));
}
@Test
public void allowsCustomFileDescriptorMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomFileDescriptorMetricsConfiguration.class)
.run((context) -> assertThat(context)
.hasSingleBean(FileDescriptorMetrics.class)
.hasBean("customFileDescriptorMetrics"));
}
@Configuration @Configuration
static class CustomClockConfiguration { static class CustomClockConfiguration {
@ -264,84 +107,4 @@ public class MetricsAutoConfigurationTests {
} }
@Configuration
static class CustomJvmGcMetricsConfiguration {
@Bean
JvmGcMetrics customJvmGcMetrics() {
return new JvmGcMetrics();
}
}
@Configuration
static class CustomJvmMemoryMetricsConfiguration {
@Bean
JvmMemoryMetrics customJvmMemoryMetrics() {
return new JvmMemoryMetrics();
}
}
@Configuration
static class CustomJvmThreadMetricsConfiguration {
@Bean
JvmThreadMetrics customJvmThreadMetrics() {
return new JvmThreadMetrics();
}
}
@Configuration
static class CustomClassLoaderMetricsConfiguration {
@Bean
ClassLoaderMetrics customClassLoaderMetrics() {
return new ClassLoaderMetrics();
}
}
@Configuration
static class CustomLogbackMetricsConfiguration {
@Bean
LogbackMetrics customLogbackMetrics() {
return new LogbackMetrics();
}
}
@Configuration
static class CustomUptimeMetricsConfiguration {
@Bean
UptimeMetrics customUptimeMetrics() {
return new UptimeMetrics();
}
}
@Configuration
static class CustomProcessorMetricsConfiguration {
@Bean
ProcessorMetrics customProcessorMetrics() {
return new ProcessorMetrics();
}
}
@Configuration
static class CustomFileDescriptorMetricsConfiguration {
@Bean
FileDescriptorMetrics customFileDescriptorMetrics() {
return new FileDescriptorMetrics();
}
}
} }

@ -0,0 +1,144 @@
/*
* 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;
import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SystemMetricsAutoConfiguration}.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
public class SystemMetricsAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.with(MetricsRun.simple()).withConfiguration(
AutoConfigurations.of(SystemMetricsAutoConfiguration.class));
@Test
public void autoConfiguresUptimeMetrics() {
this.contextRunner
.run((context) -> assertThat(context).hasSingleBean(UptimeMetrics.class));
}
@Test
@Deprecated
public void allowsUptimeMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.uptime.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(UptimeMetrics.class));
}
@Test
public void allowsCustomUptimeMetricsToBeUsed() {
this.contextRunner.withUserConfiguration(CustomUptimeMetricsConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(UptimeMetrics.class)
.hasBean("customUptimeMetrics"));
}
@Test
public void autoConfiguresProcessorMetrics() {
this.contextRunner.run(
(context) -> assertThat(context).hasSingleBean(ProcessorMetrics.class));
}
@Test
@Deprecated
public void allowsProcessorMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.processor.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(ProcessorMetrics.class));
}
@Test
public void allowsCustomProcessorMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomProcessorMetricsConfiguration.class)
.run((context) -> assertThat(context)
.hasSingleBean(ProcessorMetrics.class)
.hasBean("customProcessorMetrics"));
}
@Test
public void autoConfiguresFileDescriptorMetrics() {
this.contextRunner.run((context) -> assertThat(context)
.hasSingleBean(FileDescriptorMetrics.class));
}
@Test
@Deprecated
public void allowsFileDescriptorMetricsToBeDisabled() {
this.contextRunner
.withPropertyValues("management.metrics.binders.files.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(FileDescriptorMetrics.class));
}
@Test
public void allowsCustomFileDescriptorMetricsToBeUsed() {
this.contextRunner
.withUserConfiguration(CustomFileDescriptorMetricsConfiguration.class)
.run((context) -> assertThat(context)
.hasSingleBean(FileDescriptorMetrics.class)
.hasBean("customFileDescriptorMetrics"));
}
@Configuration
static class CustomUptimeMetricsConfiguration {
@Bean
public UptimeMetrics customUptimeMetrics() {
return new UptimeMetrics();
}
}
@Configuration
static class CustomProcessorMetricsConfiguration {
@Bean
public ProcessorMetrics customProcessorMetrics() {
return new ProcessorMetrics();
}
}
@Configuration
static class CustomFileDescriptorMetricsConfiguration {
@Bean
public FileDescriptorMetrics customFileDescriptorMetrics() {
return new FileDescriptorMetrics();
}
}
}

@ -34,7 +34,9 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.metrics.JvmMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.SystemMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsAutoConfiguration; 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.cache.CacheMetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration;
@ -140,7 +142,9 @@ public class MetricsIntegrationTests {
@Configuration @Configuration
@ImportAutoConfiguration({ MetricsAutoConfiguration.class, @ImportAutoConfiguration({ MetricsAutoConfiguration.class,
RabbitMetricsAutoConfiguration.class, CacheMetricsAutoConfiguration.class, JvmMetricsAutoConfiguration.class, LogbackMetrics.class,
SystemMetricsAutoConfiguration.class, RabbitMetricsAutoConfiguration.class,
CacheMetricsAutoConfiguration.class,
DataSourcePoolMetricsAutoConfiguration.class, DataSourcePoolMetricsAutoConfiguration.class,
HibernateMetricsAutoConfiguration.class, HibernateMetricsAutoConfiguration.class,
HttpClientMetricsAutoConfiguration.class, HttpClientMetricsAutoConfiguration.class,

@ -1373,11 +1373,6 @@ content into your application. Rather, pick only the properties that you need.
management.info.git.mode=simple # Mode to use to expose git information. management.info.git.mode=simple # Mode to use to expose git information.
# METRICS # METRICS
management.metrics.binders.files.enabled=true # Whether to enable files metrics.
management.metrics.binders.jvm.enabled=true # Whether to enable JVM metrics.
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.distribution.percentiles-histogram.*= # Whether meter IDs starting with the specified name should publish percentile histograms. management.metrics.distribution.percentiles-histogram.*= # Whether meter IDs starting with the specified name should 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.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. 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.

Loading…
Cancel
Save