Polish "Disable metrics export in integration tests"

See gh-21658
This commit is contained in:
Stephane Nicoll
2020-07-17 16:57:51 +02:00
parent b1830da0da
commit 3530ac9b0c
54 changed files with 265 additions and 240 deletions

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* 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.ElementType;
@@ -25,11 +25,11 @@ 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.
* {@link Conditional @Conditional} that checks whether or not a metrics exporter is
* enabled. If the {@code management.metrics.export.<name>.enabled} property is configured
* then its value is used to determine if it matches. Otherwise, matches if the value of
* the {@code management.metrics.export.defaults.enabled} property is {@code true} or if
* it is not configured.
*
* @author Chris Bono
* @since 2.4.0
@@ -41,10 +41,7 @@ import org.springframework.context.annotation.Conditional;
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'.
* The name of the metrics exporter.
* @return the name of the metrics exporter
*/
String value();

View File

@@ -0,0 +1,33 @@
/*
* 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);
}
}

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -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.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.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -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.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.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,75 +0,0 @@
/*
* 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)));
}
}

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -23,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -23,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -23,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -22,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -22,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -23,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -23,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -22,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -23,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -27,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -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;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -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.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.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;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -22,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -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.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.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

View File

@@ -22,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -22,7 +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.ConditionalOnEnabledMetricsExport;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -26,7 +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.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;

View File

@@ -345,6 +345,12 @@
"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",
"type": "java.lang.Integer",

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -14,26 +14,23 @@
* 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.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.
* Tests for {@link ConditionalOnEnabledMetricsExport}.
*
* @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
void exporterIsEnabledByDefault() {
@@ -48,14 +45,14 @@ class ConditonalOnEnabledMetricsExportAutoConfigurationTests {
@Test
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"));
}
@Test
void exporterCanBeGloballyDisabledWitSpecificOverride() {
this.contextRunner
.withPropertyValues("management.metrics.export.enabled=false",
.withPropertyValues("management.metrics.export.defaults.enabled=false",
"management.metrics.export.simple.enabled=true")
.run((context) -> assertThat(context).hasBean("simpleMeterRegistry"));
}

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -52,10 +52,11 @@ class AppOpticsMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(AppOpticsMeterRegistry.class).doesNotHaveBean(AppOpticsConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(AppOpticsMeterRegistry.class)
.doesNotHaveBean(AppOpticsConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -51,10 +51,11 @@ class AtlasMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(AtlasMeterRegistry.class).doesNotHaveBean(AtlasConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(AtlasMeterRegistry.class)
.doesNotHaveBean(AtlasConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -59,10 +59,11 @@ class DatadogMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(DatadogMeterRegistry.class).doesNotHaveBean(DatadogConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(DatadogMeterRegistry.class)
.doesNotHaveBean(DatadogConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -61,10 +61,11 @@ class DynatraceMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(DynatraceMeterRegistry.class).doesNotHaveBean(DynatraceConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(DynatraceMeterRegistry.class)
.doesNotHaveBean(DynatraceConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -51,10 +51,11 @@ class ElasticMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(ElasticMeterRegistry.class).doesNotHaveBean(ElasticConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(ElasticMeterRegistry.class)
.doesNotHaveBean(ElasticConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -51,10 +51,11 @@ class GangliaMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(GangliaMeterRegistry.class).doesNotHaveBean(GangliaConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(GangliaMeterRegistry.class)
.doesNotHaveBean(GangliaConfig.class));
}
@Test

View File

@@ -77,10 +77,11 @@ class GraphiteMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(GraphiteMeterRegistry.class).doesNotHaveBean(GraphiteConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(GraphiteMeterRegistry.class)
.doesNotHaveBean(GraphiteConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -52,10 +52,11 @@ class HumioMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(HumioMeterRegistry.class).doesNotHaveBean(HumioConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(HumioMeterRegistry.class)
.doesNotHaveBean(HumioConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -51,10 +51,11 @@ class InfluxMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(InfluxMeterRegistry.class).doesNotHaveBean(InfluxConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(InfluxMeterRegistry.class)
.doesNotHaveBean(InfluxConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -51,10 +51,11 @@ class JmxMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(JmxMeterRegistry.class).doesNotHaveBean(JmxConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(JmxMeterRegistry.class)
.doesNotHaveBean(JmxConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -51,10 +51,11 @@ class KairosMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(KairosMeterRegistry.class).doesNotHaveBean(KairosConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(KairosMeterRegistry.class)
.doesNotHaveBean(KairosConfig.class));
}
@Test

View File

@@ -102,10 +102,11 @@ class NewRelicMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(NewRelicMeterRegistry.class).doesNotHaveBean(NewRelicConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(NewRelicMeterRegistry.class)
.doesNotHaveBean(NewRelicConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -62,10 +62,11 @@ class PrometheusMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(PrometheusMeterRegistry.class).doesNotHaveBean(PrometheusConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(PrometheusMeterRegistry.class)
.doesNotHaveBean(CollectorRegistry.class).doesNotHaveBean(PrometheusConfig.class));
}
@Test
@@ -73,7 +74,7 @@ class PrometheusMetricsExportAutoConfigurationTests {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.prometheus.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(PrometheusMeterRegistry.class)
.doesNotHaveBean(PrometheusConfig.class));
.doesNotHaveBean(CollectorRegistry.class).doesNotHaveBean(PrometheusConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -59,10 +59,11 @@ class SignalFxMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(SignalFxMeterRegistry.class).doesNotHaveBean(SignalFxConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(SignalFxMeterRegistry.class)
.doesNotHaveBean(SignalFxConfig.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -49,10 +49,11 @@ class SimpleMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(SimpleMeterRegistry.class).doesNotHaveBean(SimpleConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(SimpleMeterRegistry.class)
.doesNotHaveBean(SimpleConfig.class));
}
@Test

View File

@@ -59,10 +59,11 @@ class StackdriverMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(StackdriverMeterRegistry.class).doesNotHaveBean(StackdriverConfig.class));
.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(StackdriverMeterRegistry.class)
.doesNotHaveBean(StackdriverConfig.class));
}
@Test

View File

@@ -51,16 +51,15 @@ class StatsdMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.enabled=false").run((context) -> assertThat(context)
.doesNotHaveBean(StatsdMeterRegistry.class).doesNotHaveBean(StatsdConfig.class));
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withPropertyValues("management.metrics.export.defaults.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(StatsdMeterRegistry.class)
.doesNotHaveBean(StatsdConfig.class));
}
@Test
void autoConfigurationCanBeDisabledWithSpecificEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.statsd.enabled=false")
this.contextRunner.withPropertyValues("management.metrics.export.statsd.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(StatsdMeterRegistry.class)
.doesNotHaveBean(StatsdConfig.class));
}

View File

@@ -54,10 +54,10 @@ class WavefrontMetricsExportAutoConfigurationTests {
}
@Test
void autoConfigurationCanBeDisabledWithGlobalEnabledProperty() {
void autoConfigurationCanBeDisabledWithDefaultsEnabledProperty() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.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)
.doesNotHaveBean(WavefrontConfig.class).doesNotHaveBean(WavefrontSender.class));
}

View File

@@ -1428,6 +1428,13 @@ For example, to disable Datadog:
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:
[source,properties,indent=0,configprops]

View File

@@ -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]]
==== Mocking and Spying Beans
When running tests, it is sometimes necessary to mock certain components within your application context.

View File

@@ -57,6 +57,7 @@ dependencies {
testImplementation("com.unboundid:unboundid-ldapsdk")
testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo")
testImplementation("io.lettuce:lettuce-core")
testImplementation("io.micrometer:micrometer-registry-prometheus")
testImplementation("io.projectreactor:reactor-core")
testImplementation("io.projectreactor:reactor-test")
testImplementation("io.r2dbc:r2dbc-h2")

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* 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.ElementType;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.autoconfigure.metrics;
package org.springframework.boot.test.autoconfigure.actuate.metrics;
import java.util.List;
@@ -28,30 +28,28 @@ 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.
* {@link ContextCustomizerFactory} that globally disables metrics export unless
* {@link AutoConfigureMetrics} is set on the test class.
*
* @author Chris Bono
*/
class ExcludeMetricExportersContextCustomizerFactory implements ContextCustomizerFactory {
class MetricsExportContextCustomizerFactory implements ContextCustomizerFactory {
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configAttributes) {
boolean metricExportersEnabled = MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY)
boolean disableMetricsExport = !MergedAnnotations.from(testClass, SearchStrategy.TYPE_HIERARCHY)
.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
public void customizeContext(ConfigurableApplicationContext context,
MergedContextConfiguration mergedContextConfiguration) {
TestPropertyValues
.of("management.metrics.export.enabled=false", "management.metrics.export.simple.enabled=true")
.applyTo(context);
TestPropertyValues.of("management.metrics.export.defaults.enabled=false",
"management.metrics.export.simple.enabled=true").applyTo(context);
}
@Override

View File

@@ -0,0 +1,20 @@
/*
* 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;

View File

@@ -185,8 +185,8 @@ org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExe
# Spring Test ContextCustomizerFactories
org.springframework.test.context.ContextCustomizerFactory=\
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.metrics.ExcludeMetricExportersContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -14,12 +14,16 @@
* 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.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import static org.assertj.core.api.Assertions.assertThat;
@@ -33,13 +37,17 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
class AutoConfigureMetricsMissingIntegrationTests {
@Autowired
private Environment environment;
@Test
void customizerRunsAndOnlyEnablesSimpleMeterRegistryWhenNoAnnotationPresent(
@Autowired ApplicationContext applicationContext) {
assertThat(applicationContext.getBean(MeterRegistry.class)).isInstanceOf(SimpleMeterRegistry.class);
assertThat(applicationContext.getBeansOfType(PrometheusMeterRegistry.class)).isEmpty();
}
@Test
void customizerRunsAndSetsExclusionPropertiesWhenNoAnnotationPresent() {
assertThat(this.environment.getProperty("management.metrics.export.enabled")).isEqualTo("false");
assertThat(this.environment.getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
void customizerRunsAndSetsExclusionPropertiesWhenNoAnnotationPresent(@Autowired Environment environment) {
assertThat(environment.getProperty("management.metrics.export.defaults.enabled")).isEqualTo("false");
assertThat(environment.getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
}
}

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -14,12 +14,14 @@
* 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.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import static org.assertj.core.api.Assertions.assertThat;
@@ -34,13 +36,16 @@ import static org.assertj.core.api.Assertions.assertThat;
@AutoConfigureMetrics
class AutoConfigureMetricsPresentIntegrationTests {
@Autowired
private Environment environment;
@Test
void customizerDoesNotDisableAvailableMeterRegistriesWhenAnnotationPresent(
@Autowired ApplicationContext applicationContext) {
assertThat(applicationContext.getBeansOfType(PrometheusMeterRegistry.class)).hasSize(1);
}
@Test
void customizerDoesNotRunWhenAnnotationPresent() {
assertThat(this.environment.containsProperty("management.metrics.export.enabled")).isFalse();
assertThat(this.environment.containsProperty("management.metrics.export.simple.enabled")).isFalse();
void customizerDoesNotSetExclusionPropertiesWhenAnnotationPresent(@Autowired Environment environment) {
assertThat(environment.containsProperty("management.metrics.export.enabled")).isFalse();
assertThat(environment.containsProperty("management.metrics.export.simple.enabled")).isFalse();
}
}

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* 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.autoconfigure.EnableAutoConfiguration;

View File

@@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,9 @@
* 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;
@@ -26,21 +28,23 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link AutoConfigureMetrics} and
* {@link ExcludeMetricExportersContextCustomizerFactory} working together.
* {@link MetricsExportContextCustomizerFactory} working together.
*
* @author Chris Bono
*/
class ExcludeMetricExportersContextCustomizerFactoryTests {
class MetricsExportContextCustomizerFactoryTests {
private ExcludeMetricExportersContextCustomizerFactory factory = new ExcludeMetricExportersContextCustomizerFactory();
private final MetricsExportContextCustomizerFactory factory = new MetricsExportContextCustomizerFactory();
@Test
void getContextCustomizerWhenHasNoAnnotationShouldReturnCustomizer() {
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null);
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class,
Collections.emptyList());
assertThat(customizer).isNotNull();
ConfigurableApplicationContext context = new GenericApplicationContext();
customizer.customizeContext(context, null);
assertThat(context.getEnvironment().getProperty("management.metrics.export.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");
}

View File

@@ -16,6 +16,7 @@
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.security.servlet.SecurityAutoConfiguration;
@@ -24,7 +25,7 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi
*
* @author Andy Wilkinson
*/
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class })
public class RestDocsTestApplication {
}