From 59693f2b12e4ea7cc7081cda45ebaab72fcb2dda Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 16 Feb 2024 15:03:18 +0100 Subject: [PATCH] Move "micrometer.observations.*" configuration properties This commit moves the "micrometer.observations.*" configuration properties to "management.observations.*" namespace, as it was introduced in the wrong namespace initially. The former configuration property is deprecated and will be removed in a future version. Fixes gh-39600 --- .../MetricsAspectsAutoConfiguration.java | 23 ++++++++++++++++++- .../MicrometerTracingAutoConfiguration.java | 22 +++++++++++++++++- ...itional-spring-configuration-metadata.json | 12 ++++++++-- .../MetricsAspectsAutoConfigurationTests.java | 13 ++++++++++- ...crometerTracingAutoConfigurationTests.java | 17 +++++++++++--- .../src/docs/asciidoc/actuator/metrics.adoc | 2 +- .../docs/asciidoc/actuator/observability.adoc | 2 +- 7 files changed, 81 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAspectsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAspectsAutoConfiguration.java index 1541778479a9..959789adfd50 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAspectsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAspectsAutoConfiguration.java @@ -23,13 +23,16 @@ import org.aspectj.weaver.Advice; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAspectsAutoConfiguration.ObservationAnnotationsEnabledCondition; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; /** * {@link EnableAutoConfiguration Auto-configuration} for Micrometer-based metrics @@ -40,7 +43,7 @@ */ @AutoConfiguration(after = { MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class }) @ConditionalOnClass({ MeterRegistry.class, Advice.class }) -@ConditionalOnProperty(prefix = "micrometer.observations.annotations", name = "enabled", havingValue = "true") +@Conditional(ObservationAnnotationsEnabledCondition.class) @ConditionalOnBean(MeterRegistry.class) public class MetricsAspectsAutoConfiguration { @@ -59,4 +62,22 @@ TimedAspect timedAspect(MeterRegistry registry, return timedAspect; } + static final class ObservationAnnotationsEnabledCondition extends AnyNestedCondition { + + ObservationAnnotationsEnabledCondition() { + super(ConfigurationPhase.PARSE_CONFIGURATION); + } + + @ConditionalOnProperty(prefix = "micrometer.observations.annotations", name = "enabled", havingValue = "true") + static class MicrometerObservationsEnabledCondition { + + } + + @ConditionalOnProperty(prefix = "management.observations.annotations", name = "enabled", havingValue = "true") + static class ManagementObservationsEnabledCondition { + + } + + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfiguration.java index 1ef058236f8a..b53699f2c1f4 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfiguration.java @@ -32,11 +32,13 @@ import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; @@ -97,7 +99,7 @@ public PropagatingReceiverTracingObservationHandler propagatingReceiverTracin @Configuration(proxyBeanMethods = false) @ConditionalOnClass(Advice.class) - @ConditionalOnProperty(prefix = "micrometer.observations.annotations", name = "enabled", havingValue = "true") + @Conditional(ObservationAnnotationsEnabledCondition.class) static class SpanAspectConfiguration { @Bean @@ -124,4 +126,22 @@ SpanAspect spanAspect(MethodInvocationProcessor methodInvocationProcessor) { } + static final class ObservationAnnotationsEnabledCondition extends AnyNestedCondition { + + ObservationAnnotationsEnabledCondition() { + super(ConfigurationPhase.PARSE_CONFIGURATION); + } + + @ConditionalOnProperty(prefix = "micrometer.observations.annotations", name = "enabled", havingValue = "true") + static class MicrometerObservationsEnabledCondition { + + } + + @ConditionalOnProperty(prefix = "management.observations.annotations", name = "enabled", havingValue = "true") + static class ManagementObservationsEnabledCondition { + + } + + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 77d1b96acf9d..f5cac72f8ac0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -2073,6 +2073,12 @@ "level": "error" } }, + { + "name": "management.observations.annotations.enabled", + "type": "java.lang.Boolean", + "description": "Whether auto-configuration of Micrometer annotations is enabled.", + "defaultValue": false + }, { "name": "management.otlp.metrics.export.base-time-unit", "defaultValue": "milliseconds" @@ -2245,8 +2251,10 @@ { "name": "micrometer.observations.annotations.enabled", "type": "java.lang.Boolean", - "description": "Whether auto-configuration of Micrometer annotations is enabled.", - "defaultValue": false + "deprecation": { + "level": "error", + "replacement": "management.observations.annotations.enabled" + } } ], "hints": [ diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAspectsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAspectsAutoConfigurationTests.java index d2ecaf6f06d2..5371146e0f42 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAspectsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAspectsAutoConfigurationTests.java @@ -41,7 +41,7 @@ class MetricsAspectsAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple()) - .withPropertyValues("micrometer.observations.annotations.enabled=true") + .withPropertyValues("management.observations.annotations.enabled=true") .withConfiguration(AutoConfigurations.of(MetricsAspectsAutoConfiguration.class)); @Test @@ -54,6 +54,17 @@ void shouldNotConfigureAspectsByDefault() { }); } + @Test + void shouldConfigureAspectsWithLegacyProperty() { + new ApplicationContextRunner().with(MetricsRun.simple()) + .withConfiguration(AutoConfigurations.of(MetricsAspectsAutoConfiguration.class)) + .withPropertyValues("micrometer.observations.annotations.enabled=true") + .run((context) -> { + assertThat(context).hasSingleBean(CountedAspect.class); + assertThat(context).hasSingleBean(TimedAspect.class); + }); + } + @Test void shouldConfigureAspects() { this.contextRunner.run((context) -> { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfigurationTests.java index f671d494159e..5fb5e7d6af8f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfigurationTests.java @@ -52,13 +52,12 @@ class MicrometerTracingAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withPropertyValues("micrometer.observations.annotations.enabled=true") + .withPropertyValues("management.observations.annotations.enabled=true") .withConfiguration(AutoConfigurations.of(MicrometerTracingAutoConfiguration.class)); @Test void shouldSupplyBeans() { this.contextRunner.withUserConfiguration(TracerConfiguration.class, PropagatorConfiguration.class) - .withPropertyValues("micrometer.observations.annotations.enabled=true") .run((context) -> { assertThat(context).hasSingleBean(DefaultTracingObservationHandler.class); assertThat(context).hasSingleBean(PropagatingReceiverTracingObservationHandler.class); @@ -133,7 +132,7 @@ void shouldNotSupplyBeansIfTracerIsMissing() { @Test void shouldNotSupplyAspectBeansIfPropertyIsDisabled() { this.contextRunner.withUserConfiguration(TracerConfiguration.class, PropagatorConfiguration.class) - .withPropertyValues("micrometer.observations.annotations.enabled=false") + .withPropertyValues("management.observations.annotations.enabled=false") .run((context) -> { assertThat(context).doesNotHaveBean(DefaultNewSpanParser.class); assertThat(context).doesNotHaveBean(ImperativeMethodInvocationProcessor.class); @@ -141,6 +140,18 @@ void shouldNotSupplyAspectBeansIfPropertyIsDisabled() { }); } + @Test + void shouldSupplyAspectBeansIfLegacyPropertyIsEnabled() { + new ApplicationContextRunner().withPropertyValues("micrometer.observations.annotations.enabled=true") + .withConfiguration(AutoConfigurations.of(MicrometerTracingAutoConfiguration.class)) + .withUserConfiguration(TracerConfiguration.class, PropagatorConfiguration.class) + .run((context) -> { + assertThat(context).hasSingleBean(DefaultNewSpanParser.class); + assertThat(context).hasSingleBean(ImperativeMethodInvocationProcessor.class); + assertThat(context).hasSingleBean(SpanAspect.class); + }); + } + @Test void shouldNotSupplyBeansIfAspectjIsMissing() { this.contextRunner.withUserConfiguration(TracerConfiguration.class) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc index 0fe6739f3c44..184f8c80eb92 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/metrics.adoc @@ -1067,7 +1067,7 @@ Metrics for Jetty's `Connector` instances are bound by using Micrometer's `Jetty [[actuator.metrics.supported.timed-annotation]] ==== @Timed Annotation Support -To enable scanning of `@Timed` annotations, you will need to set the configprop:micrometer.observations.annotations.enabled[] property to `true`. +To enable scanning of `@Timed` annotations, you will need to set the configprop:management.observations.annotations.enabled[] property to `true`. Please refer to the {micrometer-concepts-docs}#_the_timed_annotation[Micrometer documentation]. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/observability.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/observability.adoc index 54d2e5ba4c96..11b641484d33 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/observability.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/observability.adoc @@ -92,5 +92,5 @@ The next sections will provide more details about logging, metrics and traces. [[actuator.observability.annotations]] === Micrometer Observation Annotations support -To enable scanning of metrics and tracing annotations like `@Timed`, `@Counted`, `@MeterTag` and `@NewSpan` annotations, you will need to set the configprop:micrometer.observations.annotations.enabled[] property to `true`. +To enable scanning of metrics and tracing annotations like `@Timed`, `@Counted`, `@MeterTag` and `@NewSpan` annotations, you will need to set the configprop:management.observations.annotations.enabled[] property to `true`. This feature is supported Micrometer directly, please refer to the {micrometer-concepts-docs}#_the_timed_annotation[Micrometer] and {micrometer-tracing-docs}/api.html#_aspect_oriented_programming[Micrometer Tracing] reference docs.