Skip to content

Commit

Permalink
Move "micrometer.observations.*" configuration properties
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bclozel committed Feb 16, 2024
1 parent d6d7082 commit 59693f2
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand All @@ -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 {

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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 {

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -133,14 +132,26 @@ 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);
assertThat(context).doesNotHaveBean(SpanAspect.class);
});
}

@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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].


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 59693f2

Please sign in to comment.