Commit db462c4a authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #21658 from bono007

* pr/21658:
  Polish "Disable metrics export in integration tests"
  Disable metrics export in integration tests

Closes gh-21658
parents 9242ef43 3530ac9b
/*
* Copyright 2012-2020 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
*
* https://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.export;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Conditional;
/**
* {@link Conditional @Conditional} that checks whether or not a metrics exporter is
* enabled. If the {@code management.metrics.export.<name>.enabled} property is configured
* then its value is used to determine if it matches. Otherwise, matches if the value of
* the {@code management.metrics.export.defaults.enabled} property is {@code true} or if
* it is not configured.
*
* @author Chris Bono
* @since 2.4.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@Conditional(OnMetricsExportEnabledCondition.class)
public @interface ConditionalOnEnabledMetricsExport {
/**
* The name of the metrics exporter.
* @return the name of the metrics exporter
*/
String value();
}
/*
* Copyright 2012-2020 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
*
* https://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.export;
import org.springframework.boot.actuate.autoconfigure.OnEndpointElementCondition;
import org.springframework.context.annotation.Condition;
/**
* {@link Condition} that checks if a metrics exporter is enabled.
*
* @author Chris Bono
*/
class OnMetricsExportEnabledCondition extends OnEndpointElementCondition {
protected OnMetricsExportEnabledCondition() {
super("management.metrics.export.", ConditionalOnEnabledMetricsExport.class);
}
}
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,6 +23,7 @@ import io.micrometer.core.ipc.http.HttpUrlConnectionSender; ...@@ -23,6 +23,7 @@ import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(AppOpticsMeterRegistry.class) @ConditionalOnClass(AppOpticsMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.appoptics", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("appoptics")
matchIfMissing = true)
@EnableConfigurationProperties(AppOpticsProperties.class) @EnableConfigurationProperties(AppOpticsProperties.class)
public class AppOpticsMetricsExportAutoConfiguration { public class AppOpticsMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -22,6 +22,7 @@ import io.micrometer.core.instrument.Clock; ...@@ -22,6 +22,7 @@ import io.micrometer.core.instrument.Clock;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -46,8 +46,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -46,8 +46,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(AtlasMeterRegistry.class) @ConditionalOnClass(AtlasMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.atlas", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("atlas")
matchIfMissing = true)
@EnableConfigurationProperties(AtlasProperties.class) @EnableConfigurationProperties(AtlasProperties.class)
public class AtlasMetricsExportAutoConfiguration { public class AtlasMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,6 +23,7 @@ import io.micrometer.datadog.DatadogMeterRegistry; ...@@ -23,6 +23,7 @@ import io.micrometer.datadog.DatadogMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(DatadogMeterRegistry.class) @ConditionalOnClass(DatadogMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.datadog", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("datadog")
matchIfMissing = true)
@EnableConfigurationProperties(DatadogProperties.class) @EnableConfigurationProperties(DatadogProperties.class)
public class DatadogMetricsExportAutoConfiguration { public class DatadogMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,6 +23,7 @@ import io.micrometer.dynatrace.DynatraceMeterRegistry; ...@@ -23,6 +23,7 @@ import io.micrometer.dynatrace.DynatraceMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(DynatraceMeterRegistry.class) @ConditionalOnClass(DynatraceMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.dynatrace", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("dynatrace")
matchIfMissing = true)
@EnableConfigurationProperties(DynatraceProperties.class) @EnableConfigurationProperties(DynatraceProperties.class)
public class DynatraceMetricsExportAutoConfiguration { public class DynatraceMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,6 +23,7 @@ import io.micrometer.elastic.ElasticMeterRegistry; ...@@ -23,6 +23,7 @@ import io.micrometer.elastic.ElasticMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(ElasticMeterRegistry.class) @ConditionalOnClass(ElasticMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.elastic", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("elastic")
matchIfMissing = true)
@EnableConfigurationProperties(ElasticProperties.class) @EnableConfigurationProperties(ElasticProperties.class)
public class ElasticMetricsExportAutoConfiguration { public class ElasticMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -22,6 +22,7 @@ import io.micrometer.ganglia.GangliaMeterRegistry; ...@@ -22,6 +22,7 @@ import io.micrometer.ganglia.GangliaMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(GangliaMeterRegistry.class) @ConditionalOnClass(GangliaMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.ganglia", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("ganglia")
matchIfMissing = true)
@EnableConfigurationProperties(GangliaProperties.class) @EnableConfigurationProperties(GangliaProperties.class)
public class GangliaMetricsExportAutoConfiguration { public class GangliaMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -22,6 +22,7 @@ import io.micrometer.graphite.GraphiteMeterRegistry; ...@@ -22,6 +22,7 @@ import io.micrometer.graphite.GraphiteMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(GraphiteMeterRegistry.class) @ConditionalOnClass(GraphiteMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.graphite", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("graphite")
matchIfMissing = true)
@EnableConfigurationProperties(GraphiteProperties.class) @EnableConfigurationProperties(GraphiteProperties.class)
public class GraphiteMetricsExportAutoConfiguration { public class GraphiteMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,6 +23,7 @@ import io.micrometer.humio.HumioMeterRegistry; ...@@ -23,6 +23,7 @@ import io.micrometer.humio.HumioMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(HumioMeterRegistry.class) @ConditionalOnClass(HumioMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.humio", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("humio")
matchIfMissing = true)
@EnableConfigurationProperties(HumioProperties.class) @EnableConfigurationProperties(HumioProperties.class)
public class HumioMetricsExportAutoConfiguration { public class HumioMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,6 +23,7 @@ import io.micrometer.influx.InfluxMeterRegistry; ...@@ -23,6 +23,7 @@ import io.micrometer.influx.InfluxMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(InfluxMeterRegistry.class) @ConditionalOnClass(InfluxMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.influx", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("influx")
matchIfMissing = true)
@EnableConfigurationProperties(InfluxProperties.class) @EnableConfigurationProperties(InfluxProperties.class)
public class InfluxMetricsExportAutoConfiguration { public class InfluxMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -22,6 +22,7 @@ import io.micrometer.jmx.JmxMeterRegistry; ...@@ -22,6 +22,7 @@ import io.micrometer.jmx.JmxMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(JmxMeterRegistry.class) @ConditionalOnClass(JmxMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.jmx", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("jmx")
matchIfMissing = true)
@EnableConfigurationProperties(JmxProperties.class) @EnableConfigurationProperties(JmxProperties.class)
public class JmxMetricsExportAutoConfiguration { public class JmxMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,6 +23,7 @@ import io.micrometer.kairos.KairosMeterRegistry; ...@@ -23,6 +23,7 @@ import io.micrometer.kairos.KairosMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(KairosMeterRegistry.class) @ConditionalOnClass(KairosMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.kairos", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("kairos")
matchIfMissing = true)
@EnableConfigurationProperties(KairosProperties.class) @EnableConfigurationProperties(KairosProperties.class)
public class KairosMetricsExportAutoConfiguration { public class KairosMetricsExportAutoConfiguration {
......
...@@ -27,6 +27,7 @@ import io.micrometer.newrelic.NewRelicMeterRegistry; ...@@ -27,6 +27,7 @@ import io.micrometer.newrelic.NewRelicMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -34,7 +35,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -34,7 +35,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -52,8 +52,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -52,8 +52,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(NewRelicMeterRegistry.class) @ConditionalOnClass(NewRelicMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.newrelic", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("newrelic")
matchIfMissing = true)
@EnableConfigurationProperties(NewRelicProperties.class) @EnableConfigurationProperties(NewRelicProperties.class)
public class NewRelicMetricsExportAutoConfiguration { public class NewRelicMetricsExportAutoConfiguration {
......
/*
* Copyright 2012-2020 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
*
* https://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.
*/
/**
* Auto-configuration for metrics exporter.
*/
package org.springframework.boot.actuate.autoconfigure.metrics.export;
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFactory; ...@@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager; import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager;
import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager.ShutdownOperation; import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager.ShutdownOperation;
...@@ -61,8 +62,7 @@ import org.springframework.core.log.LogMessage; ...@@ -61,8 +62,7 @@ import org.springframework.core.log.LogMessage;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(PrometheusMeterRegistry.class) @ConditionalOnClass(PrometheusMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.prometheus", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("prometheus")
matchIfMissing = true)
@EnableConfigurationProperties(PrometheusProperties.class) @EnableConfigurationProperties(PrometheusProperties.class)
public class PrometheusMetricsExportAutoConfiguration { public class PrometheusMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -22,6 +22,7 @@ import io.micrometer.signalfx.SignalFxMeterRegistry; ...@@ -22,6 +22,7 @@ import io.micrometer.signalfx.SignalFxMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -46,8 +46,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -46,8 +46,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(SignalFxMeterRegistry.class) @ConditionalOnClass(SignalFxMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.signalfx", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("signalfx")
matchIfMissing = true)
@EnableConfigurationProperties(SignalFxProperties.class) @EnableConfigurationProperties(SignalFxProperties.class)
public class SignalFxMetricsExportAutoConfiguration { public class SignalFxMetricsExportAutoConfiguration {
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,12 +23,12 @@ import io.micrometer.core.instrument.simple.SimpleMeterRegistry; ...@@ -23,12 +23,12 @@ import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
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.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@EnableConfigurationProperties(SimpleProperties.class) @EnableConfigurationProperties(SimpleProperties.class)
@ConditionalOnMissingBean(MeterRegistry.class) @ConditionalOnMissingBean(MeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.simple", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("simple")
matchIfMissing = true)
public class SimpleMetricsExportAutoConfiguration { public class SimpleMetricsExportAutoConfiguration {
@Bean @Bean
......
...@@ -22,6 +22,7 @@ import io.micrometer.stackdriver.StackdriverMeterRegistry; ...@@ -22,6 +22,7 @@ import io.micrometer.stackdriver.StackdriverMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(StackdriverMeterRegistry.class) @ConditionalOnClass(StackdriverMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.stackdriver", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("stackdriver")
matchIfMissing = true)
@EnableConfigurationProperties(StackdriverProperties.class) @EnableConfigurationProperties(StackdriverProperties.class)
public class StackdriverMetricsExportAutoConfiguration { public class StackdriverMetricsExportAutoConfiguration {
......
...@@ -22,6 +22,7 @@ import io.micrometer.statsd.StatsdMeterRegistry; ...@@ -22,6 +22,7 @@ import io.micrometer.statsd.StatsdMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass(StatsdMeterRegistry.class) @ConditionalOnClass(StatsdMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.statsd", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("statsd")
matchIfMissing = true)
@EnableConfigurationProperties(StatsdProperties.class) @EnableConfigurationProperties(StatsdProperties.class)
public class StatsdMetricsExportAutoConfiguration { public class StatsdMetricsExportAutoConfiguration {
......
...@@ -26,6 +26,7 @@ import io.micrometer.wavefront.WavefrontMeterRegistry; ...@@ -26,6 +26,7 @@ import io.micrometer.wavefront.WavefrontMeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront.WavefrontProperties.Sender; import org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront.WavefrontProperties.Sender;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
...@@ -34,7 +35,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; ...@@ -34,7 +35,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -54,8 +54,7 @@ import org.springframework.util.unit.DataSize; ...@@ -54,8 +54,7 @@ import org.springframework.util.unit.DataSize;
@AutoConfigureAfter(MetricsAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class) @ConditionalOnBean(Clock.class)
@ConditionalOnClass({ WavefrontMeterRegistry.class, WavefrontSender.class }) @ConditionalOnClass({ WavefrontMeterRegistry.class, WavefrontSender.class })
@ConditionalOnProperty(prefix = "management.metrics.export.wavefront", name = "enabled", havingValue = "true", @ConditionalOnEnabledMetricsExport("wavefront")
matchIfMissing = true)
@EnableConfigurationProperties(WavefrontProperties.class) @EnableConfigurationProperties(WavefrontProperties.class)
public class WavefrontMetricsExportAutoConfiguration { public class WavefrontMetricsExportAutoConfiguration {
......
...@@ -345,6 +345,12 @@ ...@@ -345,6 +345,12 @@
"level": "error" "level": "error"
} }
}, },
{
"name": "management.metrics.export.defaults.enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable default metrics exporters.",
"defaultValue": true
},
{ {
"name": "management.metrics.export.dynatrace.num-threads", "name": "management.metrics.export.dynatrace.num-threads",
"type": "java.lang.Integer", "type": "java.lang.Integer",
......
/*
* Copyright 2012-2020 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
*
* https://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.export;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ConditionalOnEnabledMetricsExport}.
*
* @author Chris Bono
*/
class ConditionalOnEnabledMetricsExportAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple());
@Test
void exporterIsEnabledByDefault() {
this.contextRunner.run((context) -> assertThat(context).hasBean("simpleMeterRegistry"));
}
@Test
void exporterCanBeSpecificallyDisabled() {
this.contextRunner.withPropertyValues("management.metrics.export.simple.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean("simpleMeterRegistry"));
}
@Test
void exporterCanBeGloballyDisabled() {
this.contextRunner.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean("simpleMeterRegistry"));
}
@Test
void exporterCanBeGloballyDisabledWitSpecificOverride() {
this.contextRunner
.withPropertyValues("management.metrics.export.defaults.enabled=false",
"management.metrics.export.simple.enabled=true")
.run((context) -> assertThat(context).hasBean("simpleMeterRegistry"));
}
}
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -52,7 +52,15 @@ class AppOpticsMetricsExportAutoConfigurationTests { ...@@ -52,7 +52,15 @@ class AppOpticsMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(AppOpticsMeterRegistry.class)
.doesNotHaveBean(AppOpticsConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.appoptics.enabled=false") .withPropertyValues("management.metrics.export.appoptics.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(AppOpticsMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(AppOpticsMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -51,7 +51,15 @@ class AtlasMetricsExportAutoConfigurationTests { ...@@ -51,7 +51,15 @@ class AtlasMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(AtlasMeterRegistry.class)
.doesNotHaveBean(AtlasConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.atlas.enabled=false") .withPropertyValues("management.metrics.export.atlas.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(AtlasMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(AtlasMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -59,7 +59,15 @@ class DatadogMetricsExportAutoConfigurationTests { ...@@ -59,7 +59,15 @@ class DatadogMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(DatadogMeterRegistry.class)
.doesNotHaveBean(DatadogConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.datadog.enabled=false") .withPropertyValues("management.metrics.export.datadog.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(DatadogMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(DatadogMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -61,7 +61,15 @@ class DynatraceMetricsExportAutoConfigurationTests { ...@@ -61,7 +61,15 @@ class DynatraceMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(DynatraceMeterRegistry.class)
.doesNotHaveBean(DynatraceConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.dynatrace.enabled=false") .withPropertyValues("management.metrics.export.dynatrace.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(DynatraceMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(DynatraceMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -51,7 +51,15 @@ class ElasticMetricsExportAutoConfigurationTests { ...@@ -51,7 +51,15 @@ class ElasticMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(ElasticMeterRegistry.class)
.doesNotHaveBean(ElasticConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.elastic.enabled=false") .withPropertyValues("management.metrics.export.elastic.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(ElasticMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(ElasticMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -51,7 +51,15 @@ class GangliaMetricsExportAutoConfigurationTests { ...@@ -51,7 +51,15 @@ class GangliaMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(GangliaMeterRegistry.class)
.doesNotHaveBean(GangliaConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.ganglia.enabled=false") .withPropertyValues("management.metrics.export.ganglia.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(GangliaMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(GangliaMeterRegistry.class)
......
...@@ -77,7 +77,15 @@ class GraphiteMetricsExportAutoConfigurationTests { ...@@ -77,7 +77,15 @@ class GraphiteMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(GraphiteMeterRegistry.class)
.doesNotHaveBean(GraphiteConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.graphite.enabled=false") .withPropertyValues("management.metrics.export.graphite.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(GraphiteMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(GraphiteMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -52,7 +52,15 @@ class HumioMetricsExportAutoConfigurationTests { ...@@ -52,7 +52,15 @@ class HumioMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(HumioMeterRegistry.class)
.doesNotHaveBean(HumioConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.humio.enabled=false") .withPropertyValues("management.metrics.export.humio.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(HumioMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(HumioMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -51,7 +51,15 @@ class InfluxMetricsExportAutoConfigurationTests { ...@@ -51,7 +51,15 @@ class InfluxMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(InfluxMeterRegistry.class)
.doesNotHaveBean(InfluxConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.influx.enabled=false") .withPropertyValues("management.metrics.export.influx.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(InfluxMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(InfluxMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -51,7 +51,15 @@ class JmxMetricsExportAutoConfigurationTests { ...@@ -51,7 +51,15 @@ class JmxMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(JmxMeterRegistry.class)
.doesNotHaveBean(JmxConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.jmx.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.jmx.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(JmxMeterRegistry.class).doesNotHaveBean(JmxConfig.class)); .doesNotHaveBean(JmxMeterRegistry.class).doesNotHaveBean(JmxConfig.class));
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -51,7 +51,15 @@ class KairosMetricsExportAutoConfigurationTests { ...@@ -51,7 +51,15 @@ class KairosMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(KairosMeterRegistry.class)
.doesNotHaveBean(KairosConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.kairos.enabled=false") .withPropertyValues("management.metrics.export.kairos.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(KairosMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(KairosMeterRegistry.class)
......
...@@ -102,7 +102,15 @@ class NewRelicMetricsExportAutoConfigurationTests { ...@@ -102,7 +102,15 @@ class NewRelicMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(NewRelicMeterRegistry.class)
.doesNotHaveBean(NewRelicConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.newrelic.enabled=false") .withPropertyValues("management.metrics.export.newrelic.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(NewRelicMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(NewRelicMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -62,8 +62,17 @@ class PrometheusMetricsExportAutoConfigurationTests { ...@@ -62,8 +62,17 @@ class PrometheusMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withPropertyValues("management.metrics.export.prometheus.enabled=false") this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(PrometheusMeterRegistry.class)
.doesNotHaveBean(CollectorRegistry.class).doesNotHaveBean(PrometheusConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.prometheus.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(PrometheusMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(PrometheusMeterRegistry.class)
.doesNotHaveBean(CollectorRegistry.class).doesNotHaveBean(PrometheusConfig.class)); .doesNotHaveBean(CollectorRegistry.class).doesNotHaveBean(PrometheusConfig.class));
} }
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -59,7 +59,15 @@ class SignalFxMetricsExportAutoConfigurationTests { ...@@ -59,7 +59,15 @@ class SignalFxMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(SignalFxMeterRegistry.class)
.doesNotHaveBean(SignalFxConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.signalfx.enabled=false") .withPropertyValues("management.metrics.export.signalfx.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(SignalFxMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(SignalFxMeterRegistry.class)
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -49,7 +49,15 @@ class SimpleMetricsExportAutoConfigurationTests { ...@@ -49,7 +49,15 @@ class SimpleMetricsExportAutoConfigurationTests {
} }
@Test @Test
void backsOffWhenSpecificallyDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(SimpleMeterRegistry.class)
.doesNotHaveBean(SimpleConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.simple.enabled=false") .withPropertyValues("management.metrics.export.simple.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(SimpleMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(SimpleMeterRegistry.class)
......
...@@ -59,7 +59,15 @@ class StackdriverMetricsExportAutoConfigurationTests { ...@@ -59,7 +59,15 @@ class StackdriverMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(StackdriverMeterRegistry.class)
.doesNotHaveBean(StackdriverConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.stackdriver.enabled=false") .withPropertyValues("management.metrics.export.stackdriver.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(StackdriverMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(StackdriverMeterRegistry.class)
......
...@@ -51,7 +51,14 @@ class StatsdMetricsExportAutoConfigurationTests { ...@@ -51,7 +51,14 @@ class StatsdMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(StatsdMeterRegistry.class)
.doesNotHaveBean(StatsdConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withPropertyValues("management.metrics.export.statsd.enabled=false") this.contextRunner.withPropertyValues("management.metrics.export.statsd.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(StatsdMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(StatsdMeterRegistry.class)
.doesNotHaveBean(StatsdConfig.class)); .doesNotHaveBean(StatsdConfig.class));
......
...@@ -54,7 +54,16 @@ class WavefrontMetricsExportAutoConfigurationTests { ...@@ -54,7 +54,16 @@ class WavefrontMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabled() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.wavefront.api-token=abcde",
"management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(WavefrontMeterRegistry.class)
.doesNotHaveBean(WavefrontConfig.class).doesNotHaveBean(WavefrontSender.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.wavefront.api-token=abcde", .withPropertyValues("management.metrics.export.wavefront.api-token=abcde",
"management.metrics.export.wavefront.enabled=false") "management.metrics.export.wavefront.enabled=false")
......
...@@ -1428,6 +1428,13 @@ For example, to disable Datadog: ...@@ -1428,6 +1428,13 @@ For example, to disable Datadog:
management.metrics.export.datadog.enabled=false management.metrics.export.datadog.enabled=false
---- ----
You can also disable all registries unless stated otherwise by the registry-specific property, as shown in the following example:
[source,properties,indent=0,configprops]
----
management.metrics.export.defaults.enabled=false
----
Spring Boot will also add any auto-configured registries to the global static composite registry on the `Metrics` class unless you explicitly tell it not to: Spring Boot will also add any auto-configured registries to the global static composite registry on the `Metrics` class unless you explicitly tell it not to:
[source,properties,indent=0,configprops] [source,properties,indent=0,configprops]
......
...@@ -6638,6 +6638,14 @@ include::{test-examples}/jmx/SampleJmxTests.java[tag=test] ...@@ -6638,6 +6638,14 @@ include::{test-examples}/jmx/SampleJmxTests.java[tag=test]
[[boot-features-testing-spring-boot-applications-metrics]]
==== Using Metrics
Regardless of your classpath, meter registries, except the in-memory backed, are not auto-configured when using `@SpringBootTest`.
If you need to export metrics to a different backend as part of an integration test, annotate it with `@AutoConfigureMetrics`.
[[boot-features-testing-spring-boot-applications-mocking-beans]] [[boot-features-testing-spring-boot-applications-mocking-beans]]
==== Mocking and Spying Beans ==== Mocking and Spying Beans
When running tests, it is sometimes necessary to mock certain components within your application context. When running tests, it is sometimes necessary to mock certain components within your application context.
......
...@@ -48,6 +48,8 @@ dependencies { ...@@ -48,6 +48,8 @@ dependencies {
optional("org.mongodb:mongodb-driver-reactivestreams") optional("org.mongodb:mongodb-driver-reactivestreams")
optional("org.mongodb:mongodb-driver-sync") optional("org.mongodb:mongodb-driver-sync")
testImplementation(project(":spring-boot-project:spring-boot-actuator"))
testImplementation(project(":spring-boot-project:spring-boot-actuator-autoconfigure"))
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testImplementation("ch.qos.logback:logback-classic") testImplementation("ch.qos.logback:logback-classic")
testImplementation("com.fasterxml.jackson.module:jackson-module-parameter-names") testImplementation("com.fasterxml.jackson.module:jackson-module-parameter-names")
...@@ -55,6 +57,7 @@ dependencies { ...@@ -55,6 +57,7 @@ dependencies {
testImplementation("com.unboundid:unboundid-ldapsdk") testImplementation("com.unboundid:unboundid-ldapsdk")
testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo") testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo")
testImplementation("io.lettuce:lettuce-core") testImplementation("io.lettuce:lettuce-core")
testImplementation("io.micrometer:micrometer-registry-prometheus")
testImplementation("io.projectreactor:reactor-core") testImplementation("io.projectreactor:reactor-core")
testImplementation("io.projectreactor:reactor-test") testImplementation("io.projectreactor:reactor-test")
testImplementation("io.r2dbc:r2dbc-h2") testImplementation("io.r2dbc:r2dbc-h2")
......
/*
* Copyright 2012-2020 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
*
* https://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.test.autoconfigure.actuate.metrics;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation that can be applied to a test class to enable auto-configuration for metrics
* exporters.
*
* @author Chris Bono
* @since 2.4.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface AutoConfigureMetrics {
}
/*
* Copyright 2012-2020 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
*
* https://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.test.autoconfigure.actuate.metrics;
import java.util.List;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
import org.springframework.test.context.ContextConfigurationAttributes;
import org.springframework.test.context.ContextCustomizer;
import org.springframework.test.context.ContextCustomizerFactory;
import org.springframework.test.context.MergedContextConfiguration;
/**
* {@link ContextCustomizerFactory} that globally disables metrics export unless
* {@link AutoConfigureMetrics} is set on the test class.
*
* @author Chris Bono
*/
class MetricsExportContextCustomizerFactory implements ContextCustomizerFactory {
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configAttributes) {
boolean disableMetricsExport = !MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY)
.get(AutoConfigureMetrics.class).isPresent();
return disableMetricsExport ? new DisableMetricExportContextCustomizer() : null;
}
static class DisableMetricExportContextCustomizer implements ContextCustomizer {
@Override
public void customizeContext(ConfigurableApplicationContext context,
MergedContextConfiguration mergedContextConfiguration) {
TestPropertyValues.of("management.metrics.export.defaults.enabled=false",
"management.metrics.export.simple.enabled=true").applyTo(context);
}
@Override
public boolean equals(Object obj) {
return (obj != null) && (getClass() == obj.getClass());
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}
}
/*
* Copyright 2012-2020 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
*
* https://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.
*/
/**
* Auto-configuration for handling metrics in tests.
*/
package org.springframework.boot.test.autoconfigure.actuate.metrics;
...@@ -185,6 +185,7 @@ org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExe ...@@ -185,6 +185,7 @@ org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExe
# Spring Test ContextCustomizerFactories # Spring Test ContextCustomizerFactories
org.springframework.test.context.ContextCustomizerFactory=\ org.springframework.test.context.ContextCustomizerFactory=\
org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory,\ org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizerFactory,\ org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizerFactory,\ org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory
......
/*
* Copyright 2012-2020 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
*
* https://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.test.autoconfigure.actuate.metrics;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test to verify behaviour when
* {@link AutoConfigureMetrics @AutoConfigureMetrics} is not present on the test class.
*
* @author Chris Bono
*/
@SpringBootTest
class AutoConfigureMetricsMissingIntegrationTests {
@Test
void customizerRunsAndOnlyEnablesSimpleMeterRegistryWhenNoAnnotationPresent(
@Autowired ApplicationContext applicationContext) {
assertThat(applicationContext.getBean(MeterRegistry.class)).isInstanceOf(SimpleMeterRegistry.class);
assertThat(applicationContext.getBeansOfType(PrometheusMeterRegistry.class)).isEmpty();
}
@Test
void customizerRunsAndSetsExclusionPropertiesWhenNoAnnotationPresent(@Autowired Environment environment) {
assertThat(environment.getProperty("management.metrics.export.defaults.enabled")).isEqualTo("false");
assertThat(environment.getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
}
}
/*
* Copyright 2012-2020 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
*
* https://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.test.autoconfigure.actuate.metrics;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test to verify behaviour when
* {@link AutoConfigureMetrics @AutoConfigureMetrics} is present on the test class.
*
* @author Chris Bono
*/
@SpringBootTest
@AutoConfigureMetrics
class AutoConfigureMetricsPresentIntegrationTests {
@Test
void customizerDoesNotDisableAvailableMeterRegistriesWhenAnnotationPresent(
@Autowired ApplicationContext applicationContext) {
assertThat(applicationContext.getBeansOfType(PrometheusMeterRegistry.class)).hasSize(1);
}
@Test
void customizerDoesNotSetExclusionPropertiesWhenAnnotationPresent(@Autowired Environment environment) {
assertThat(environment.containsProperty("management.metrics.export.enabled")).isFalse();
assertThat(environment.containsProperty("management.metrics.export.simple.enabled")).isFalse();
}
}
/*
* Copyright 2012-2020 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
*
* https://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.test.autoconfigure.actuate.metrics;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Example {@link SpringBootApplication @SpringBootApplication} for use with
* {@link AutoConfigureMetrics @AutoConfigureMetrics} tests.
*
* @author Chris Bono
*/
@SpringBootConfiguration
@EnableAutoConfiguration
class AutoConfigureMetricsSpringBootApplication {
}
/*
* Copyright 2012-2020 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
*
* https://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.test.autoconfigure.actuate.metrics;
import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.context.ContextCustomizer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link AutoConfigureMetrics} and
* {@link MetricsExportContextCustomizerFactory} working together.
*
* @author Chris Bono
*/
class MetricsExportContextCustomizerFactoryTests {
private final MetricsExportContextCustomizerFactory factory = new MetricsExportContextCustomizerFactory();
@Test
void getContextCustomizerWhenHasNoAnnotationShouldReturnCustomizer() {
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class,
Collections.emptyList());
assertThat(customizer).isNotNull();
ConfigurableApplicationContext context = new GenericApplicationContext();
customizer.customizeContext(context, null);
assertThat(context.getEnvironment().getProperty("management.metrics.export.defaults.enabled"))
.isEqualTo("false");
assertThat(context.getEnvironment().getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
}
@Test
void getContextCustomizerWhenHasAnnotationShouldReturnNull() {
ContextCustomizer customizer = this.factory.createContextCustomizer(WithAnnotation.class, null);
assertThat(customizer).isNull();
}
@Test
void hashCodeAndEquals() {
ContextCustomizer customizer1 = this.factory.createContextCustomizer(NoAnnotation.class, null);
ContextCustomizer customizer2 = this.factory.createContextCustomizer(OtherWithNoAnnotation.class, null);
assertThat(customizer1.hashCode()).isEqualTo(customizer2.hashCode());
assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2);
}
static class NoAnnotation {
}
static class OtherWithNoAnnotation {
}
@AutoConfigureMetrics
static class WithAnnotation {
}
}
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.springframework.boot.test.autoconfigure.restdocs; package org.springframework.boot.test.autoconfigure.restdocs;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
...@@ -24,7 +25,7 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi ...@@ -24,7 +25,7 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi
* *
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@SpringBootApplication(exclude = SecurityAutoConfiguration.class) @SpringBootApplication(exclude = { SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class })
public class RestDocsTestApplication { public class RestDocsTestApplication {
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment