Disable metrics export in integration tests
This commit introduces a new property to globally disable metrics export. In integration tests, this property is automatically set to disable everything but in-memory metrics. This commit also introduces a `@AutoConfigureMetrics` annotation that can be used for integration tests that require metrics export to operate as they would in an application. See gh-21658
This commit is contained in:
@@ -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.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(AppOpticsMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.appoptics", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("appoptics")
|
||||
@EnableConfigurationProperties(AppOpticsProperties.class)
|
||||
public class AppOpticsMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -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.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -46,8 +46,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(AtlasMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.atlas", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("atlas")
|
||||
@EnableConfigurationProperties(AtlasProperties.class)
|
||||
public class AtlasMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.condition;
|
||||
|
||||
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 particular 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.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, typically derived from the name of the
|
||||
* corresponding auto-configuration class which follows the typical naming scheme of
|
||||
* {@code <name>MetricsExportAutoConfiguration}. For example, the
|
||||
* {@code DatadogMetricsExportAutoConfiguration} would have a name of 'datadog'.
|
||||
* @return the name of the metrics exporter
|
||||
*/
|
||||
String value();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.condition;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
||||
/**
|
||||
* Metrics exporter enabled condition. All exporters can be disabled globally via the
|
||||
* {@code management.metrics.export.enabled} property or individually via the
|
||||
* {@code management.metrics.export.<name>.enabled} property (where {@code <name>} is the
|
||||
* name of the exporter.
|
||||
*
|
||||
* @author Chris Bono
|
||||
* @since 2.4.0
|
||||
*/
|
||||
public class OnMetricsExportEnabledCondition extends SpringBootCondition {
|
||||
|
||||
private static final String PREFIX = "management.metrics.export";
|
||||
|
||||
private static final Class<? extends Annotation> ANNOTATION_TYPE = ConditionalOnEnabledMetricsExport.class;
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
AnnotationAttributes annotationAttributes = AnnotationAttributes
|
||||
.fromMap(metadata.getAnnotationAttributes(this.ANNOTATION_TYPE.getName()));
|
||||
String exporterName = annotationAttributes.getString("value");
|
||||
ConditionOutcome outcome = getSpecificExporterOutcome(context, exporterName);
|
||||
if (outcome != null) {
|
||||
return outcome;
|
||||
}
|
||||
return getGlobalExporterOutcome(context);
|
||||
}
|
||||
|
||||
protected ConditionOutcome getSpecificExporterOutcome(ConditionContext context, String exporterName) {
|
||||
Environment environment = context.getEnvironment();
|
||||
String enabledProperty = String.format("%s.%s.enabled", this.PREFIX, exporterName);
|
||||
if (!environment.containsProperty(enabledProperty)) {
|
||||
return null;
|
||||
}
|
||||
boolean match = environment.getProperty(enabledProperty, Boolean.class);
|
||||
return new ConditionOutcome(match, ConditionMessage.forCondition(this.ANNOTATION_TYPE)
|
||||
.because(String.format("%s is %b", enabledProperty, match)));
|
||||
}
|
||||
|
||||
protected ConditionOutcome getGlobalExporterOutcome(ConditionContext context) {
|
||||
Environment environment = context.getEnvironment();
|
||||
String enabledProperty = String.format("%s.enabled", this.PREFIX);
|
||||
boolean match = environment.getProperty(enabledProperty, Boolean.class, true);
|
||||
return new ConditionOutcome(match, ConditionMessage.forCondition(this.ANNOTATION_TYPE)
|
||||
.because(String.format("%s is considered %b", enabledProperty, match)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import io.micrometer.datadog.DatadogMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(DatadogMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.datadog", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("datadog")
|
||||
@EnableConfigurationProperties(DatadogProperties.class)
|
||||
public class DatadogMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.micrometer.dynatrace.DynatraceMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(DynatraceMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.dynatrace", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("dynatrace")
|
||||
@EnableConfigurationProperties(DynatraceProperties.class)
|
||||
public class DynatraceMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.micrometer.elastic.ElasticMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(ElasticMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.elastic", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("elastic")
|
||||
@EnableConfigurationProperties(ElasticProperties.class)
|
||||
public class ElasticMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.micrometer.ganglia.GangliaMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(GangliaMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.ganglia", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("ganglia")
|
||||
@EnableConfigurationProperties(GangliaProperties.class)
|
||||
public class GangliaMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.micrometer.graphite.GraphiteMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(GraphiteMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.graphite", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("graphite")
|
||||
@EnableConfigurationProperties(GraphiteProperties.class)
|
||||
public class GraphiteMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.micrometer.humio.HumioMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(HumioMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.humio", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("humio")
|
||||
@EnableConfigurationProperties(HumioProperties.class)
|
||||
public class HumioMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.micrometer.influx.InfluxMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(InfluxMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.influx", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("influx")
|
||||
@EnableConfigurationProperties(InfluxProperties.class)
|
||||
public class InfluxMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.micrometer.jmx.JmxMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(JmxMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.jmx", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("jmx")
|
||||
@EnableConfigurationProperties(JmxProperties.class)
|
||||
public class JmxMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.micrometer.kairos.KairosMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(KairosMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.kairos", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("kairos")
|
||||
@EnableConfigurationProperties(KairosProperties.class)
|
||||
public class KairosMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.micrometer.newrelic.NewRelicMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -34,7 +35,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -52,8 +52,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(NewRelicMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.newrelic", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("newrelic")
|
||||
@EnableConfigurationProperties(NewRelicProperties.class)
|
||||
public class NewRelicMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -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.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
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.ShutdownOperation;
|
||||
@@ -61,8 +62,7 @@ import org.springframework.core.log.LogMessage;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(PrometheusMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.prometheus", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("prometheus")
|
||||
@EnableConfigurationProperties(PrometheusProperties.class)
|
||||
public class PrometheusMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.micrometer.signalfx.SignalFxMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -46,8 +46,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(SignalFxMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.signalfx", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("signalfx")
|
||||
@EnableConfigurationProperties(SignalFxProperties.class)
|
||||
public class SignalFxMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -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.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@EnableConfigurationProperties(SimpleProperties.class)
|
||||
@ConditionalOnMissingBean(MeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.simple", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("simple")
|
||||
public class SimpleMetricsExportAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.micrometer.stackdriver.StackdriverMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,8 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(StackdriverMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.stackdriver", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("stackdriver")
|
||||
@EnableConfigurationProperties(StackdriverProperties.class)
|
||||
public class StackdriverMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.micrometer.statsd.StatsdMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -45,8 +45,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass(StatsdMeterRegistry.class)
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.statsd", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("statsd")
|
||||
@EnableConfigurationProperties(StatsdProperties.class)
|
||||
public class StatsdMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import io.micrometer.wavefront.WavefrontMeterRegistry;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.condition.ConditionalOnEnabledMetricsExport;
|
||||
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.autoconfigure.AutoConfigureAfter;
|
||||
@@ -34,7 +35,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -54,8 +54,7 @@ import org.springframework.util.unit.DataSize;
|
||||
@AutoConfigureAfter(MetricsAutoConfiguration.class)
|
||||
@ConditionalOnBean(Clock.class)
|
||||
@ConditionalOnClass({ WavefrontMeterRegistry.class, WavefrontSender.class })
|
||||
@ConditionalOnProperty(prefix = "management.metrics.export.wavefront", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnEnabledMetricsExport("wavefront")
|
||||
@EnableConfigurationProperties(WavefrontProperties.class)
|
||||
public class WavefrontMetricsExportAutoConfiguration {
|
||||
|
||||
|
||||
@@ -52,7 +52,14 @@ class AppOpticsMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(AppOpticsMeterRegistry.class).doesNotHaveBean(AppOpticsConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.appoptics.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(AppOpticsMeterRegistry.class)
|
||||
|
||||
@@ -51,7 +51,14 @@ class AtlasMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(AtlasMeterRegistry.class).doesNotHaveBean(AtlasConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.atlas.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(AtlasMeterRegistry.class)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.condition;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
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} - uses the
|
||||
* {@link SimpleMetricsExportAutoConfiguration} as the target for the conditional
|
||||
* enablement to avoid creating a test export auto config.
|
||||
*
|
||||
* @author Chris Bono
|
||||
*/
|
||||
class ConditonalOnEnabledMetricsExportAutoConfigurationTests {
|
||||
|
||||
private 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.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean("simpleMeterRegistry"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void exporterCanBeGloballyDisabledWitSpecificOverride() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("management.metrics.export.enabled=false",
|
||||
"management.metrics.export.simple.enabled=true")
|
||||
.run((context) -> assertThat(context).hasBean("simpleMeterRegistry"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -59,7 +59,14 @@ class DatadogMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(DatadogMeterRegistry.class).doesNotHaveBean(DatadogConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.datadog.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(DatadogMeterRegistry.class)
|
||||
|
||||
@@ -61,7 +61,14 @@ class DynatraceMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(DynatraceMeterRegistry.class).doesNotHaveBean(DynatraceConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.dynatrace.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(DynatraceMeterRegistry.class)
|
||||
|
||||
@@ -51,7 +51,14 @@ class ElasticMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ElasticMeterRegistry.class).doesNotHaveBean(ElasticConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.elastic.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(ElasticMeterRegistry.class)
|
||||
|
||||
@@ -51,7 +51,14 @@ class GangliaMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(GangliaMeterRegistry.class).doesNotHaveBean(GangliaConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.ganglia.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(GangliaMeterRegistry.class)
|
||||
|
||||
@@ -77,7 +77,14 @@ class GraphiteMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(GraphiteMeterRegistry.class).doesNotHaveBean(GraphiteConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.graphite.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(GraphiteMeterRegistry.class)
|
||||
|
||||
@@ -52,7 +52,14 @@ class HumioMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(HumioMeterRegistry.class).doesNotHaveBean(HumioConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.humio.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(HumioMeterRegistry.class)
|
||||
|
||||
@@ -51,7 +51,14 @@ class InfluxMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(InfluxMeterRegistry.class).doesNotHaveBean(InfluxConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.influx.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(InfluxMeterRegistry.class)
|
||||
|
||||
@@ -51,7 +51,14 @@ class JmxMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(JmxMeterRegistry.class).doesNotHaveBean(JmxConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.jmx.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(JmxMeterRegistry.class).doesNotHaveBean(JmxConfig.class));
|
||||
|
||||
@@ -51,7 +51,14 @@ class KairosMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(KairosMeterRegistry.class).doesNotHaveBean(KairosConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.kairos.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(KairosMeterRegistry.class)
|
||||
|
||||
@@ -102,7 +102,14 @@ class NewRelicMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(NewRelicMeterRegistry.class).doesNotHaveBean(NewRelicConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.newrelic.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(NewRelicMeterRegistry.class)
|
||||
|
||||
@@ -62,10 +62,18 @@ class PrometheusMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
this.contextRunner.withPropertyValues("management.metrics.export.prometheus.enabled=false")
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(PrometheusMeterRegistry.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)
|
||||
.doesNotHaveBean(CollectorRegistry.class).doesNotHaveBean(PrometheusConfig.class));
|
||||
.doesNotHaveBean(PrometheusConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -59,7 +59,14 @@ class SignalFxMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(SignalFxMeterRegistry.class).doesNotHaveBean(SignalFxConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.signalfx.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(SignalFxMeterRegistry.class)
|
||||
|
||||
@@ -49,7 +49,14 @@ class SimpleMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void backsOffWhenSpecificallyDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(SimpleMeterRegistry.class).doesNotHaveBean(SimpleConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.simple.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(SimpleMeterRegistry.class)
|
||||
|
||||
@@ -59,7 +59,14 @@ class StackdriverMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(StackdriverMeterRegistry.class).doesNotHaveBean(StackdriverConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.stackdriver.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(StackdriverMeterRegistry.class)
|
||||
|
||||
@@ -51,8 +51,16 @@ class StatsdMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
this.contextRunner.withPropertyValues("management.metrics.export.statsd.enabled=false")
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(StatsdMeterRegistry.class).doesNotHaveBean(StatsdConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.statsd.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(StatsdMeterRegistry.class)
|
||||
.doesNotHaveBean(StatsdConfig.class));
|
||||
}
|
||||
|
||||
@@ -54,7 +54,16 @@ class WavefrontMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabled() {
|
||||
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.wavefront.api-token=abcde",
|
||||
"management.metrics.export.enabled=false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(WavefrontMeterRegistry.class)
|
||||
.doesNotHaveBean(WavefrontConfig.class).doesNotHaveBean(WavefrontSender.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.wavefront.api-token=abcde",
|
||||
"management.metrics.export.wavefront.enabled=false")
|
||||
|
||||
@@ -48,6 +48,8 @@ dependencies {
|
||||
optional("org.mongodb:mongodb-driver-reactivestreams")
|
||||
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("ch.qos.logback:logback-classic")
|
||||
testImplementation("com.fasterxml.jackson.module:jackson-module-parameter-names")
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.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 {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.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 creates a customizer that globally disables
|
||||
* metrics exporters unless the {@link AutoConfigureMetrics} annotation is specified on
|
||||
* the test class.
|
||||
*
|
||||
* @author Chris Bono
|
||||
*/
|
||||
class ExcludeMetricExportersContextCustomizerFactory implements ContextCustomizerFactory {
|
||||
|
||||
@Override
|
||||
public ContextCustomizer createContextCustomizer(Class<?> testClass,
|
||||
List<ContextConfigurationAttributes> configAttributes) {
|
||||
boolean metricExportersEnabled = MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY)
|
||||
.get(AutoConfigureMetrics.class).isPresent();
|
||||
return !metricExportersEnabled ? new ExcludeMetricExportersContextCustomizer() : null;
|
||||
}
|
||||
|
||||
static class ExcludeMetricExportersContextCustomizer implements ContextCustomizer {
|
||||
|
||||
@Override
|
||||
public void customizeContext(ConfigurableApplicationContext context,
|
||||
MergedContextConfiguration mergedContextConfiguration) {
|
||||
TestPropertyValues
|
||||
.of("management.metrics.export.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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test auto-configuration support for actuator metrics.
|
||||
*/
|
||||
package org.springframework.boot.test.autoconfigure.metrics;
|
||||
@@ -186,6 +186,7 @@ org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExe
|
||||
org.springframework.test.context.ContextCustomizerFactory=\
|
||||
org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory,\
|
||||
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizerFactory,\
|
||||
org.springframework.boot.test.autoconfigure.metrics.ExcludeMetricExportersContextCustomizerFactory,\
|
||||
org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizerFactory,\
|
||||
org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.metrics;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
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 {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
void customizerRunsAndSetsExclusionPropertiesWhenNoAnnotationPresent() {
|
||||
assertThat(this.environment.getProperty("management.metrics.export.enabled")).isEqualTo("false");
|
||||
assertThat(this.environment.getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.metrics;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
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 {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
void customizerDoesNotRunWhenAnnotationPresent() {
|
||||
assertThat(this.environment.containsProperty("management.metrics.export.enabled")).isFalse();
|
||||
assertThat(this.environment.containsProperty("management.metrics.export.simple.enabled")).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.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 {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.metrics;
|
||||
|
||||
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 ExcludeMetricExportersContextCustomizerFactory} working together.
|
||||
*
|
||||
* @author Chris Bono
|
||||
*/
|
||||
class ExcludeMetricExportersContextCustomizerFactoryTests {
|
||||
|
||||
private ExcludeMetricExportersContextCustomizerFactory factory = new ExcludeMetricExportersContextCustomizerFactory();
|
||||
|
||||
@Test
|
||||
void getContextCustomizerWhenHasNoAnnotationShouldReturnCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null);
|
||||
assertThat(customizer).isNotNull();
|
||||
ConfigurableApplicationContext context = new GenericApplicationContext();
|
||||
customizer.customizeContext(context, null);
|
||||
assertThat(context.getEnvironment().getProperty("management.metrics.export.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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user