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-13408pull/14247/merge
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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue