diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java index b60f60d49465..ec9e0e2d6fcf 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java @@ -36,8 +36,8 @@ public class DatadogProperties extends StepRegistryProperties { private String apiKey; /** - * Datadog application key. Not strictly required, but improves the Datadog experience - * by sending meter descriptions, types, and base units to Datadog. + * Datadog's application key. Not strictly required, but improves the Datadog + * experience by sending meter descriptions, types, and base units to Datadog. */ private String applicationKey; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java new file mode 100644 index 000000000000..607261591488 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java @@ -0,0 +1,109 @@ +/* + * Copyright 2012-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export; + +import java.lang.reflect.Method; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.Assert; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PropertiesConfigAdapter; + +/** + * Utility to test that all Micrometer config values are exposed via properties and + * settable using the corresponding {@link PropertiesConfigAdapter} implementation. + * + * @author Mirko Sobeck + */ +public final class TestConfigsToPropertiesExposure { + + private TestConfigsToPropertiesExposure() { + + } + + private static final List> classesForPropertiesList = List.of(Boolean.class, Byte.class, Character.class, + Short.class, Integer.class, Long.class, Double.class, Float.class, String.class, Duration.class); + + /** + * Assertion to test if default methods of a given config are overridden by the + * adapter which implements it. This can be an indicator for micrometer config fields, + * that have been forgotten to expose via spring properties. Not overridden default + * methods in adapters are the most common cause of forgotten field exposure, because + * they do not for force an override. + * @param config micrometer config + * @param adapter adapter for properties {@link PropertiesConfigAdapter} + * @param excludedConfigMethods config methods that should be excluded for the + * assertion + */ + public static void assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(Class config, + Class> adapter, String... excludedConfigMethods) { + List configDefaultMethodNames = Arrays.stream(config.getDeclaredMethods()) + .filter((method) -> method.isDefault() && isSettableUsingProperties(method.getReturnType())) + .map(Method::getName).collect(Collectors.toList()); + + configDefaultMethodNames.removeAll(Arrays.stream(excludedConfigMethods).toList()); + List notOverriddenDefaultMethods = new ArrayList<>(configDefaultMethodNames); + + Class currentClass = adapter; + // loop through adapter class and superclasses + // to find not overridden config methods + while (!Object.class.equals(currentClass)) { + List overriddenClassDefaultMethods = Arrays.stream(currentClass.getDeclaredMethods()) + .map(Method::getName).filter(configDefaultMethodNames::contains).toList(); + + notOverriddenDefaultMethods.removeAll(overriddenClassDefaultMethods); + currentClass = currentClass.getSuperclass(); + } + + if (notOverriddenDefaultMethods.size() >= 1) { + Assert.fail( + "Found config default methods that are not overridden by the related PropertiesConfigAdapter: \n" + + notOverriddenDefaultMethods + "\n" + + "This could be an indicator for not exposed properties fields.\n" + + "Please check if the fields are meant to be exposed and if not, " + + "exclude them from this test by providing them to the method."); + } + } + + /** + * Guess if a class can be set using properties. This will only catch the basic use + * cases regarding the micrometer configs to filter out methods that are not likely to + * be designed to be set via properties.
+	 *     isSettableUsingProperties(String.class) = true
+	 *     isSettableUsingProperties(boolean.class) = true
+	 *     isSettableUsingProperties(Object.class) = false
+	 * 
+ * @param clazz Class + * @return is likely to be settable using properties + */ + private static boolean isSettableUsingProperties(Class clazz) { + if (Void.TYPE.equals(clazz)) { + return false; + } + + if (clazz.isPrimitive()) { + return true; + } + + return classesForPropertiesList.contains(clazz); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java index 6b5de57c7fae..9768c1f18640 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 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. @@ -16,8 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.appoptics; +import io.micrometer.appoptics.AppOpticsConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -68,4 +70,10 @@ void whenPropertiesFloorTimesIsSetAdapterFloorTimesReturnsIt() { assertThat(createConfigAdapter(properties).floorTimes()).isTrue(); } + @Test + void allDefaultConfigMethodsAreOverriddenByAtlasPropertiesConfigAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(AppOpticsConfig.class, + AppOpticsPropertiesConfigAdapter.class, "connectTimeout"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java index 48b777c69d38..31f827d4e95c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java @@ -18,8 +18,11 @@ import java.time.Duration; +import com.netflix.spectator.atlas.AtlasConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -116,4 +119,11 @@ void whenPropertiesEvalUriIsSetAdapterEvalUriReturnsIt() { .isEqualTo("https://atlas.example.com/evaluate"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(AtlasConfig.class, + AtlasPropertiesConfigAdapter.class, "lwcIgnorePublishStep", "initialPollingDelay", "autoStart", + "lwcStep", "validTagCharacters"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java index b47892c439a5..165f7dec03d5 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java @@ -16,8 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.datadog; +import io.micrometer.datadog.DatadogConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -76,4 +78,10 @@ void whenPropertiesUriIsSetAdapterUriReturnsIt() { assertThat(createConfigAdapter(properties).uri()).isEqualTo("https://app.example.com/api/v1/series"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(DatadogConfig.class, + DatadogPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java index 86143ac76f5f..a1950046c0da 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -19,8 +19,11 @@ import java.util.HashMap; import io.micrometer.dynatrace.DynatraceApiVersion; +import io.micrometer.dynatrace.DynatraceConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -125,4 +128,10 @@ void defaultValues() { assertThat(properties.getV2().isUseDynatraceSummaryInstruments()).isTrue(); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(DynatraceConfig.class, + DynatracePropertiesConfigAdapter.class, "documentType"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java index 8e5313370358..b9bf20876d8f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 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. @@ -16,8 +16,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.elastic; +import io.micrometer.elastic.ElasticConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -97,4 +100,10 @@ void whenPropertiesApiKeyCredentialsIsSetAdapterPipelineReturnsIt() { assertThat(new ElasticPropertiesConfigAdapter(properties).apiKeyCredentials()).isEqualTo("secret"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(ElasticConfig.class, + ElasticPropertiesConfigAdapter.class, "documentType"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java index 3afd087f8b6a..8769c4020410 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java @@ -20,8 +20,11 @@ import java.util.concurrent.TimeUnit; import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode; +import io.micrometer.ganglia.GangliaConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -81,4 +84,10 @@ void whenPropertiesPortIsSetAdapterPortReturnsIt() { assertThat(new GangliaPropertiesConfigAdapter(properties).port()).isEqualTo(4242); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(GangliaConfig.class, + GangliaPropertiesConfigAdapter.class, "protocolVersion"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java index 68e6bef9cf5c..ce375464ba62 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java @@ -19,9 +19,12 @@ import java.time.Duration; import java.util.concurrent.TimeUnit; +import io.micrometer.graphite.GraphiteConfig; import io.micrometer.graphite.GraphiteProtocol; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -94,4 +97,10 @@ void whenPropertiesTagsAsPrefixIsSetAdapterTagsAsPrefixReturnsIt() { assertThat(new GraphitePropertiesConfigAdapter(properties).tagsAsPrefix()).isEqualTo(new String[] { "worker" }); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(GraphiteConfig.class, + GraphitePropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java index dffce7e8eb3e..243120bb32e6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java @@ -18,8 +18,11 @@ import java.util.Collections; +import io.micrometer.humio.HumioConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -51,4 +54,10 @@ void whenPropertiesUriIsSetAdapterUriReturnsIt() { assertThat(new HumioPropertiesConfigAdapter(properties).uri()).isEqualTo("https://humio.example.com"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(HumioConfig.class, + HumioPropertiesConfigAdapter.class, "connectTimeout"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java index 2d86262c668a..0d0a7142fbcc 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java @@ -17,8 +17,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.influx; import io.micrometer.influx.InfluxApiVersion; +import io.micrometer.influx.InfluxConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -58,4 +61,10 @@ void adaptInfluxV2BasicConfig() { assertThat(adapter.token()).isEqualTo("token"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(InfluxConfig.class, + InfluxPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java index 6ee12bfd5ada..e23a523d2d1a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java @@ -18,8 +18,11 @@ import java.time.Duration; +import io.micrometer.jmx.JmxConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -43,4 +46,10 @@ void whenPropertiesDomainIsSetAdapterDomainReturnsIt() { assertThat(new JmxPropertiesConfigAdapter(properties).domain()).isEqualTo("abc"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(JmxConfig.class, + JmxPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java index 711069faff72..0fb248d39f1b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java @@ -16,8 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.kairos; +import io.micrometer.kairos.KairosConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -62,4 +64,10 @@ void whenPropertiesPasswordIsSetAdapterPasswordReturnsIt() { assertThat(createConfigAdapter(properties).password()).isEqualTo("secret"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(KairosConfig.class, + KairosPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java index 5ef2fd99e7fd..3eba1bd12f9e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java @@ -17,8 +17,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic; import io.micrometer.newrelic.ClientProviderType; +import io.micrometer.newrelic.NewRelicConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -83,4 +85,10 @@ void whenPropertiesUriIsSetAdapterUriReturnsIt() { assertThat(createConfigAdapter(properties).uri()).isEqualTo("https://example.newrelic.com"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(NewRelicConfig.class, + NewRelicPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapterTests.java index 3253e01ccd28..8a47a779ae2e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpPropertiesConfigAdapterTests.java @@ -18,8 +18,11 @@ import java.util.Map; +import io.micrometer.registry.otlp.OtlpConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -51,4 +54,10 @@ void whenPropertiesHeadersIsSetAdapterHeadersReturnsIt() { assertThat(new OtlpPropertiesConfigAdapter(properties).headers()).containsEntry("header", "value"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(OtlpConfig.class, + OtlpPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java index 66aa5920aa1a..c9a43eaee7fb 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java @@ -19,8 +19,11 @@ import java.time.Duration; import io.micrometer.prometheus.HistogramFlavor; +import io.micrometer.prometheus.PrometheusConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -52,4 +55,10 @@ void whenPropertiesStepIsSetAdapterStepReturnsIt() { assertThat(new PrometheusPropertiesConfigAdapter(properties).step()).isEqualTo(Duration.ofSeconds(30)); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(PrometheusConfig.class, + PrometheusPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFXPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFXPropertiesConfigAdapterTests.java index 03ed7435b533..49261635e65d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFXPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFXPropertiesConfigAdapterTests.java @@ -16,8 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx; +import io.micrometer.signalfx.SignalFxConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -62,4 +64,10 @@ void whenPropertiesSourceIsSetAdapterSourceReturnsIt() { assertThat(createConfigAdapter(properties).source()).isEqualTo("DESKTOP-GA5"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(SignalFxConfig.class, + SignalFxPropertiesConfigAdapter.class, "publishDeltaHistogram", "publishCumulativeHistogram"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java index c62ddaeebc89..b163bf5320bd 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java @@ -19,8 +19,10 @@ import java.time.Duration; import io.micrometer.core.instrument.simple.CountingMode; +import io.micrometer.core.instrument.simple.SimpleConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxPropertiesConfigAdapter; import static org.assertj.core.api.Assertions.assertThat; @@ -46,4 +48,10 @@ void whenPropertiesAccessTokenIsSetAdapterAccessTokenReturnsIt() { assertThat(new SimplePropertiesConfigAdapter(properties).mode()).isEqualTo(CountingMode.STEP); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(SimpleConfig.class, + SimplePropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java index 6018cbc91ff4..7ebf3823cde1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java @@ -19,8 +19,11 @@ import java.util.HashMap; import java.util.Map; +import io.micrometer.stackdriver.StackdriverConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -62,4 +65,10 @@ void whenPropertiesUseSemanticMetricTypesIsSetAdapterUseSemanticMetricTypesRetur assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isTrue(); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(StackdriverConfig.class, + StackdriverPropertiesConfigAdapter.class, "metricTypePrefix"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java index e6bce8be431d..b476f2c9c60f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java @@ -18,10 +18,13 @@ import java.time.Duration; +import io.micrometer.statsd.StatsdConfig; import io.micrometer.statsd.StatsdFlavor; import io.micrometer.statsd.StatsdProtocol; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -104,4 +107,10 @@ void whenPropertiesBufferedIsSetAdapterBufferedReturnsIt() { assertThat(new StatsdPropertiesConfigAdapter(properties).buffered()).isEqualTo(properties.isBuffered()); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(StatsdConfig.class, + StatsdPropertiesConfigAdapter.class, "queueSize"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java index 6660d9319955..7336fac44fd5 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -18,8 +18,10 @@ import java.net.URI; +import io.micrometer.wavefront.WavefrontConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesConfigAdapterTests; import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties; import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.Metrics.Export; @@ -82,4 +84,11 @@ void whenPropertiesSourceIsSetAdapterSourceReturnsIt() { assertThat(new WavefrontPropertiesConfigAdapter(properties).source()).isEqualTo("DESKTOP-GA5"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(WavefrontConfig.class, + WavefrontPropertiesConfigAdapter.class, "distributionPort", "reportMinuteDistribution", + "reportHourDistribution", "reportDayDistribution"); + } + }