Commit 3530ac9b authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Disable metrics export in integration tests"

See gh-21658
parent b1830da0
/* /*
* 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.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.actuate.autoconfigure.metrics.export.condition; package org.springframework.boot.actuate.autoconfigure.metrics.export;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
...@@ -25,11 +25,11 @@ import java.lang.annotation.Target; ...@@ -25,11 +25,11 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Conditional;
/** /**
* {@link Conditional @Conditional} that checks whether or not a particular metrics * {@link Conditional @Conditional} that checks whether or not a metrics exporter is
* exporter is enabled. If the {@code management.metrics.export.<name>.enabled} property * enabled. If the {@code management.metrics.export.<name>.enabled} property is configured
* is configured then its value is used to determine if it matches. Otherwise, matches if * then its value is used to determine if it matches. Otherwise, matches if the value of
* the value of the {@code management.metrics.export.enabled} property is {@code true} or * the {@code management.metrics.export.defaults.enabled} property is {@code true} or if
* if it is not configured. * it is not configured.
* *
* @author Chris Bono * @author Chris Bono
* @since 2.4.0 * @since 2.4.0
...@@ -41,10 +41,7 @@ import org.springframework.context.annotation.Conditional; ...@@ -41,10 +41,7 @@ import org.springframework.context.annotation.Conditional;
public @interface ConditionalOnEnabledMetricsExport { public @interface ConditionalOnEnabledMetricsExport {
/** /**
* The name of the metrics exporter, typically derived from the name of the * The name of the metrics exporter.
* 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 * @return the name of the metrics exporter
*/ */
String value(); 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,7 +23,7 @@ import io.micrometer.core.ipc.http.HttpUrlConnectionSender; ...@@ -23,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +22,7 @@ import io.micrometer.core.instrument.Clock; ...@@ -22,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/*
* 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)));
}
}
/* /*
* 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,7 +23,7 @@ import io.micrometer.datadog.DatadogMeterRegistry; ...@@ -23,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +23,7 @@ import io.micrometer.dynatrace.DynatraceMeterRegistry; ...@@ -23,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +23,7 @@ import io.micrometer.elastic.ElasticMeterRegistry; ...@@ -23,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +22,7 @@ import io.micrometer.ganglia.GangliaMeterRegistry; ...@@ -22,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +22,7 @@ import io.micrometer.graphite.GraphiteMeterRegistry; ...@@ -22,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +23,7 @@ import io.micrometer.humio.HumioMeterRegistry; ...@@ -23,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +23,7 @@ import io.micrometer.influx.InfluxMeterRegistry; ...@@ -23,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +22,7 @@ import io.micrometer.jmx.JmxMeterRegistry; ...@@ -22,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +23,7 @@ import io.micrometer.kairos.KairosMeterRegistry; ...@@ -23,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
...@@ -27,7 +27,7 @@ import io.micrometer.newrelic.NewRelicMeterRegistry; ...@@ -27,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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.
...@@ -15,6 +15,6 @@ ...@@ -15,6 +15,6 @@
*/ */
/** /**
* Test auto-configuration support for actuator metrics. * Auto-configuration for metrics exporter.
*/ */
package org.springframework.boot.test.autoconfigure.metrics; 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,7 +32,7 @@ import org.apache.commons.logging.LogFactory; ...@@ -32,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +22,7 @@ import io.micrometer.signalfx.SignalFxMeterRegistry; ...@@ -22,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
/* /*
* 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,7 +23,7 @@ import io.micrometer.core.instrument.simple.SimpleMeterRegistry; ...@@ -23,7 +23,7 @@ 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.condition.ConditionalOnEnabledMetricsExport; 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;
......
...@@ -22,7 +22,7 @@ import io.micrometer.stackdriver.StackdriverMeterRegistry; ...@@ -22,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
...@@ -22,7 +22,7 @@ import io.micrometer.statsd.StatsdMeterRegistry; ...@@ -22,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
...@@ -26,7 +26,7 @@ import io.micrometer.wavefront.WavefrontMeterRegistry; ...@@ -26,7 +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.condition.ConditionalOnEnabledMetricsExport; 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;
......
...@@ -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-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.
...@@ -14,26 +14,23 @@ ...@@ -14,26 +14,23 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.actuate.autoconfigure.metrics.export.condition; package org.springframework.boot.actuate.autoconfigure.metrics.export;
import org.junit.jupiter.api.Test; 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.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link ConditionalOnEnabledMetricsExport} - uses the * Tests for {@link ConditionalOnEnabledMetricsExport}.
* {@link SimpleMetricsExportAutoConfiguration} as the target for the conditional
* enablement to avoid creating a test export auto config.
* *
* @author Chris Bono * @author Chris Bono
*/ */
class ConditonalOnEnabledMetricsExportAutoConfigurationTests { class ConditionalOnEnabledMetricsExportAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple()); private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple());
@Test @Test
void exporterIsEnabledByDefault() { void exporterIsEnabledByDefault() {
...@@ -48,14 +45,14 @@ class ConditonalOnEnabledMetricsExportAutoConfigurationTests { ...@@ -48,14 +45,14 @@ class ConditonalOnEnabledMetricsExportAutoConfigurationTests {
@Test @Test
void exporterCanBeGloballyDisabled() { void exporterCanBeGloballyDisabled() {
this.contextRunner.withPropertyValues("management.metrics.export.enabled=false") this.contextRunner.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean("simpleMeterRegistry")); .run((context) -> assertThat(context).doesNotHaveBean("simpleMeterRegistry"));
} }
@Test @Test
void exporterCanBeGloballyDisabledWitSpecificOverride() { void exporterCanBeGloballyDisabledWitSpecificOverride() {
this.contextRunner this.contextRunner
.withPropertyValues("management.metrics.export.enabled=false", .withPropertyValues("management.metrics.export.defaults.enabled=false",
"management.metrics.export.simple.enabled=true") "management.metrics.export.simple.enabled=true")
.run((context) -> assertThat(context).hasBean("simpleMeterRegistry")); .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,10 +52,11 @@ class AppOpticsMetricsExportAutoConfigurationTests { ...@@ -52,10 +52,11 @@ class AppOpticsMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(AppOpticsMeterRegistry.class).doesNotHaveBean(AppOpticsConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(AppOpticsMeterRegistry.class)
.doesNotHaveBean(AppOpticsConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +51,11 @@ class AtlasMetricsExportAutoConfigurationTests { ...@@ -51,10 +51,11 @@ class AtlasMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(AtlasMeterRegistry.class).doesNotHaveBean(AtlasConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(AtlasMeterRegistry.class)
.doesNotHaveBean(AtlasConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +59,11 @@ class DatadogMetricsExportAutoConfigurationTests { ...@@ -59,10 +59,11 @@ class DatadogMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(DatadogMeterRegistry.class).doesNotHaveBean(DatadogConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(DatadogMeterRegistry.class)
.doesNotHaveBean(DatadogConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +61,11 @@ class DynatraceMetricsExportAutoConfigurationTests { ...@@ -61,10 +61,11 @@ class DynatraceMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(DynatraceMeterRegistry.class).doesNotHaveBean(DynatraceConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(DynatraceMeterRegistry.class)
.doesNotHaveBean(DynatraceConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +51,11 @@ class ElasticMetricsExportAutoConfigurationTests { ...@@ -51,10 +51,11 @@ class ElasticMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(ElasticMeterRegistry.class).doesNotHaveBean(ElasticConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(ElasticMeterRegistry.class)
.doesNotHaveBean(ElasticConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +51,11 @@ class GangliaMetricsExportAutoConfigurationTests { ...@@ -51,10 +51,11 @@ class GangliaMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(GangliaMeterRegistry.class).doesNotHaveBean(GangliaConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(GangliaMeterRegistry.class)
.doesNotHaveBean(GangliaConfig.class));
} }
@Test @Test
......
...@@ -77,10 +77,11 @@ class GraphiteMetricsExportAutoConfigurationTests { ...@@ -77,10 +77,11 @@ class GraphiteMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(GraphiteMeterRegistry.class).doesNotHaveBean(GraphiteConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(GraphiteMeterRegistry.class)
.doesNotHaveBean(GraphiteConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +52,11 @@ class HumioMetricsExportAutoConfigurationTests { ...@@ -52,10 +52,11 @@ class HumioMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(HumioMeterRegistry.class).doesNotHaveBean(HumioConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(HumioMeterRegistry.class)
.doesNotHaveBean(HumioConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +51,11 @@ class InfluxMetricsExportAutoConfigurationTests { ...@@ -51,10 +51,11 @@ class InfluxMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(InfluxMeterRegistry.class).doesNotHaveBean(InfluxConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(InfluxMeterRegistry.class)
.doesNotHaveBean(InfluxConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +51,11 @@ class JmxMetricsExportAutoConfigurationTests { ...@@ -51,10 +51,11 @@ class JmxMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(JmxMeterRegistry.class).doesNotHaveBean(JmxConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(JmxMeterRegistry.class)
.doesNotHaveBean(JmxConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +51,11 @@ class KairosMetricsExportAutoConfigurationTests { ...@@ -51,10 +51,11 @@ class KairosMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(KairosMeterRegistry.class).doesNotHaveBean(KairosConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(KairosMeterRegistry.class)
.doesNotHaveBean(KairosConfig.class));
} }
@Test @Test
......
...@@ -102,10 +102,11 @@ class NewRelicMetricsExportAutoConfigurationTests { ...@@ -102,10 +102,11 @@ class NewRelicMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(NewRelicMeterRegistry.class).doesNotHaveBean(NewRelicConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(NewRelicMeterRegistry.class)
.doesNotHaveBean(NewRelicConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +62,11 @@ class PrometheusMetricsExportAutoConfigurationTests { ...@@ -62,10 +62,11 @@ class PrometheusMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(PrometheusMeterRegistry.class).doesNotHaveBean(PrometheusConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(PrometheusMeterRegistry.class)
.doesNotHaveBean(CollectorRegistry.class).doesNotHaveBean(PrometheusConfig.class));
} }
@Test @Test
...@@ -73,7 +74,7 @@ class PrometheusMetricsExportAutoConfigurationTests { ...@@ -73,7 +74,7 @@ class PrometheusMetricsExportAutoConfigurationTests {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.prometheus.enabled=false") .withPropertyValues("management.metrics.export.prometheus.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(PrometheusMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(PrometheusMeterRegistry.class)
.doesNotHaveBean(PrometheusConfig.class)); .doesNotHaveBean(CollectorRegistry.class).doesNotHaveBean(PrometheusConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +59,11 @@ class SignalFxMetricsExportAutoConfigurationTests { ...@@ -59,10 +59,11 @@ class SignalFxMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(SignalFxMeterRegistry.class).doesNotHaveBean(SignalFxConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(SignalFxMeterRegistry.class)
.doesNotHaveBean(SignalFxConfig.class));
} }
@Test @Test
......
/* /*
* 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,10 +49,11 @@ class SimpleMetricsExportAutoConfigurationTests { ...@@ -49,10 +49,11 @@ class SimpleMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(SimpleMeterRegistry.class).doesNotHaveBean(SimpleConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(SimpleMeterRegistry.class)
.doesNotHaveBean(SimpleConfig.class));
} }
@Test @Test
......
...@@ -59,10 +59,11 @@ class StackdriverMetricsExportAutoConfigurationTests { ...@@ -59,10 +59,11 @@ class StackdriverMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .withPropertyValues("management.metrics.export.defaults.enabled=false")
.doesNotHaveBean(StackdriverMeterRegistry.class).doesNotHaveBean(StackdriverConfig.class)); .run((context) -> assertThat(context).doesNotHaveBean(StackdriverMeterRegistry.class)
.doesNotHaveBean(StackdriverConfig.class));
} }
@Test @Test
......
...@@ -51,16 +51,15 @@ class StatsdMetricsExportAutoConfigurationTests { ...@@ -51,16 +51,15 @@ class StatsdMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withPropertyValues("management.metrics.export.defaults.enabled=false")
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context) .run((context) -> assertThat(context).doesNotHaveBean(StatsdMeterRegistry.class)
.doesNotHaveBean(StatsdMeterRegistry.class).doesNotHaveBean(StatsdConfig.class)); .doesNotHaveBean(StatsdConfig.class));
} }
@Test @Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() { void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class) this.contextRunner.withPropertyValues("management.metrics.export.statsd.enabled=false")
.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,10 +54,10 @@ class WavefrontMetricsExportAutoConfigurationTests { ...@@ -54,10 +54,10 @@ class WavefrontMetricsExportAutoConfigurationTests {
} }
@Test @Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() { void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
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.enabled=false") "management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(WavefrontMeterRegistry.class) .run((context) -> assertThat(context).doesNotHaveBean(WavefrontMeterRegistry.class)
.doesNotHaveBean(WavefrontConfig.class).doesNotHaveBean(WavefrontSender.class)); .doesNotHaveBean(WavefrontConfig.class).doesNotHaveBean(WavefrontSender.class));
} }
......
...@@ -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.
......
...@@ -57,6 +57,7 @@ dependencies { ...@@ -57,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-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.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.autoconfigure.metrics; package org.springframework.boot.test.autoconfigure.actuate.metrics;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
......
/* /*
* 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.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.autoconfigure.metrics; package org.springframework.boot.test.autoconfigure.actuate.metrics;
import java.util.List; import java.util.List;
...@@ -28,30 +28,28 @@ import org.springframework.test.context.ContextCustomizerFactory; ...@@ -28,30 +28,28 @@ import org.springframework.test.context.ContextCustomizerFactory;
import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.MergedContextConfiguration;
/** /**
* {@link ContextCustomizerFactory} that creates a customizer that globally disables * {@link ContextCustomizerFactory} that globally disables metrics export unless
* metrics exporters unless the {@link AutoConfigureMetrics} annotation is specified on * {@link AutoConfigureMetrics} is set on the test class.
* the test class.
* *
* @author Chris Bono * @author Chris Bono
*/ */
class ExcludeMetricExportersContextCustomizerFactory implements ContextCustomizerFactory { class MetricsExportContextCustomizerFactory implements ContextCustomizerFactory {
@Override @Override
public ContextCustomizer createContextCustomizer(Class<?> testClass, public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configAttributes) { List<ContextConfigurationAttributes> configAttributes) {
boolean metricExportersEnabled = MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY) boolean disableMetricsExport = !MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY)
.get(AutoConfigureMetrics.class).isPresent(); .get(AutoConfigureMetrics.class).isPresent();
return !metricExportersEnabled ? new ExcludeMetricExportersContextCustomizer() : null; return disableMetricsExport ? new DisableMetricExportContextCustomizer() : null;
} }
static class ExcludeMetricExportersContextCustomizer implements ContextCustomizer { static class DisableMetricExportContextCustomizer implements ContextCustomizer {
@Override @Override
public void customizeContext(ConfigurableApplicationContext context, public void customizeContext(ConfigurableApplicationContext context,
MergedContextConfiguration mergedContextConfiguration) { MergedContextConfiguration mergedContextConfiguration) {
TestPropertyValues TestPropertyValues.of("management.metrics.export.defaults.enabled=false",
.of("management.metrics.export.enabled=false", "management.metrics.export.simple.enabled=true") "management.metrics.export.simple.enabled=true").applyTo(context);
.applyTo(context);
} }
@Override @Override
......
/*
* 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,8 +185,8 @@ org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExe ...@@ -185,8 +185,8 @@ 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.metrics.ExcludeMetricExportersContextCustomizerFactory,\
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-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.
...@@ -14,12 +14,16 @@ ...@@ -14,12 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.autoconfigure.metrics; 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.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -33,13 +37,17 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -33,13 +37,17 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest @SpringBootTest
class AutoConfigureMetricsMissingIntegrationTests { class AutoConfigureMetricsMissingIntegrationTests {
@Autowired @Test
private Environment environment; void customizerRunsAndOnlyEnablesSimpleMeterRegistryWhenNoAnnotationPresent(
@Autowired ApplicationContext applicationContext) {
assertThat(applicationContext.getBean(MeterRegistry.class)).isInstanceOf(SimpleMeterRegistry.class);
assertThat(applicationContext.getBeansOfType(PrometheusMeterRegistry.class)).isEmpty();
}
@Test @Test
void customizerRunsAndSetsExclusionPropertiesWhenNoAnnotationPresent() { void customizerRunsAndSetsExclusionPropertiesWhenNoAnnotationPresent(@Autowired Environment environment) {
assertThat(this.environment.getProperty("management.metrics.export.enabled")).isEqualTo("false"); assertThat(environment.getProperty("management.metrics.export.defaults.enabled")).isEqualTo("false");
assertThat(this.environment.getProperty("management.metrics.export.simple.enabled")).isEqualTo("true"); assertThat(environment.getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
} }
} }
/* /*
* 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.
...@@ -14,12 +14,14 @@ ...@@ -14,12 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.autoconfigure.metrics; package org.springframework.boot.test.autoconfigure.actuate.metrics;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -34,13 +36,16 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -34,13 +36,16 @@ import static org.assertj.core.api.Assertions.assertThat;
@AutoConfigureMetrics @AutoConfigureMetrics
class AutoConfigureMetricsPresentIntegrationTests { class AutoConfigureMetricsPresentIntegrationTests {
@Autowired @Test
private Environment environment; void customizerDoesNotDisableAvailableMeterRegistriesWhenAnnotationPresent(
@Autowired ApplicationContext applicationContext) {
assertThat(applicationContext.getBeansOfType(PrometheusMeterRegistry.class)).hasSize(1);
}
@Test @Test
void customizerDoesNotRunWhenAnnotationPresent() { void customizerDoesNotSetExclusionPropertiesWhenAnnotationPresent(@Autowired Environment environment) {
assertThat(this.environment.containsProperty("management.metrics.export.enabled")).isFalse(); assertThat(environment.containsProperty("management.metrics.export.enabled")).isFalse();
assertThat(this.environment.containsProperty("management.metrics.export.simple.enabled")).isFalse(); assertThat(environment.containsProperty("management.metrics.export.simple.enabled")).isFalse();
} }
} }
/* /*
* 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.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.autoconfigure.metrics; package org.springframework.boot.test.autoconfigure.actuate.metrics;
import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
......
/* /*
* 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.
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.autoconfigure.metrics; package org.springframework.boot.test.autoconfigure.actuate.metrics;
import java.util.Collections;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -26,21 +28,23 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -26,21 +28,23 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link AutoConfigureMetrics} and * Tests for {@link AutoConfigureMetrics} and
* {@link ExcludeMetricExportersContextCustomizerFactory} working together. * {@link MetricsExportContextCustomizerFactory} working together.
* *
* @author Chris Bono * @author Chris Bono
*/ */
class ExcludeMetricExportersContextCustomizerFactoryTests { class MetricsExportContextCustomizerFactoryTests {
private ExcludeMetricExportersContextCustomizerFactory factory = new ExcludeMetricExportersContextCustomizerFactory(); private final MetricsExportContextCustomizerFactory factory = new MetricsExportContextCustomizerFactory();
@Test @Test
void getContextCustomizerWhenHasNoAnnotationShouldReturnCustomizer() { void getContextCustomizerWhenHasNoAnnotationShouldReturnCustomizer() {
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null); ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class,
Collections.emptyList());
assertThat(customizer).isNotNull(); assertThat(customizer).isNotNull();
ConfigurableApplicationContext context = new GenericApplicationContext(); ConfigurableApplicationContext context = new GenericApplicationContext();
customizer.customizeContext(context, null); customizer.customizeContext(context, null);
assertThat(context.getEnvironment().getProperty("management.metrics.export.enabled")).isEqualTo("false"); assertThat(context.getEnvironment().getProperty("management.metrics.export.defaults.enabled"))
.isEqualTo("false");
assertThat(context.getEnvironment().getProperty("management.metrics.export.simple.enabled")).isEqualTo("true"); assertThat(context.getEnvironment().getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
} }
......
...@@ -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