mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
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
This commit is contained in:
parent
d6d70828f1
commit
59693f2b12
@ -23,13 +23,16 @@ import io.micrometer.core.instrument.MeterRegistry;
|
|||||||
import org.aspectj.weaver.Advice;
|
import org.aspectj.weaver.Advice;
|
||||||
|
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
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.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
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.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Conditional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for Micrometer-based metrics
|
* {@link EnableAutoConfiguration Auto-configuration} for Micrometer-based metrics
|
||||||
@ -40,7 +43,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
*/
|
*/
|
||||||
@AutoConfiguration(after = { MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class })
|
@AutoConfiguration(after = { MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class })
|
||||||
@ConditionalOnClass({ MeterRegistry.class, Advice.class })
|
@ConditionalOnClass({ MeterRegistry.class, Advice.class })
|
||||||
@ConditionalOnProperty(prefix = "micrometer.observations.annotations", name = "enabled", havingValue = "true")
|
@Conditional(ObservationAnnotationsEnabledCondition.class)
|
||||||
@ConditionalOnBean(MeterRegistry.class)
|
@ConditionalOnBean(MeterRegistry.class)
|
||||||
public class MetricsAspectsAutoConfiguration {
|
public class MetricsAspectsAutoConfiguration {
|
||||||
|
|
||||||
@ -59,4 +62,22 @@ public class MetricsAspectsAutoConfiguration {
|
|||||||
return timedAspect;
|
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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,13 @@ import org.aspectj.weaver.Advice;
|
|||||||
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
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.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
@ -97,7 +99,7 @@ public class MicrometerTracingAutoConfiguration {
|
|||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(Advice.class)
|
@ConditionalOnClass(Advice.class)
|
||||||
@ConditionalOnProperty(prefix = "micrometer.observations.annotations", name = "enabled", havingValue = "true")
|
@Conditional(ObservationAnnotationsEnabledCondition.class)
|
||||||
static class SpanAspectConfiguration {
|
static class SpanAspectConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -124,4 +126,22 @@ public class MicrometerTracingAutoConfiguration {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2073,6 +2073,12 @@
|
|||||||
"level": "error"
|
"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",
|
"name": "management.otlp.metrics.export.base-time-unit",
|
||||||
"defaultValue": "milliseconds"
|
"defaultValue": "milliseconds"
|
||||||
@ -2245,8 +2251,10 @@
|
|||||||
{
|
{
|
||||||
"name": "micrometer.observations.annotations.enabled",
|
"name": "micrometer.observations.annotations.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "Whether auto-configuration of Micrometer annotations is enabled.",
|
"deprecation": {
|
||||||
"defaultValue": false
|
"level": "error",
|
||||||
|
"replacement": "management.observations.annotations.enabled"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hints": [
|
"hints": [
|
||||||
|
@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
class MetricsAspectsAutoConfigurationTests {
|
class MetricsAspectsAutoConfigurationTests {
|
||||||
|
|
||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple())
|
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));
|
.withConfiguration(AutoConfigurations.of(MetricsAspectsAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -54,6 +54,17 @@ class MetricsAspectsAutoConfigurationTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
void shouldConfigureAspects() {
|
void shouldConfigureAspects() {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.run((context) -> {
|
||||||
|
@ -52,13 +52,12 @@ import static org.mockito.Mockito.mock;
|
|||||||
class MicrometerTracingAutoConfigurationTests {
|
class MicrometerTracingAutoConfigurationTests {
|
||||||
|
|
||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withPropertyValues("micrometer.observations.annotations.enabled=true")
|
.withPropertyValues("management.observations.annotations.enabled=true")
|
||||||
.withConfiguration(AutoConfigurations.of(MicrometerTracingAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(MicrometerTracingAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldSupplyBeans() {
|
void shouldSupplyBeans() {
|
||||||
this.contextRunner.withUserConfiguration(TracerConfiguration.class, PropagatorConfiguration.class)
|
this.contextRunner.withUserConfiguration(TracerConfiguration.class, PropagatorConfiguration.class)
|
||||||
.withPropertyValues("micrometer.observations.annotations.enabled=true")
|
|
||||||
.run((context) -> {
|
.run((context) -> {
|
||||||
assertThat(context).hasSingleBean(DefaultTracingObservationHandler.class);
|
assertThat(context).hasSingleBean(DefaultTracingObservationHandler.class);
|
||||||
assertThat(context).hasSingleBean(PropagatingReceiverTracingObservationHandler.class);
|
assertThat(context).hasSingleBean(PropagatingReceiverTracingObservationHandler.class);
|
||||||
@ -133,7 +132,7 @@ class MicrometerTracingAutoConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void shouldNotSupplyAspectBeansIfPropertyIsDisabled() {
|
void shouldNotSupplyAspectBeansIfPropertyIsDisabled() {
|
||||||
this.contextRunner.withUserConfiguration(TracerConfiguration.class, PropagatorConfiguration.class)
|
this.contextRunner.withUserConfiguration(TracerConfiguration.class, PropagatorConfiguration.class)
|
||||||
.withPropertyValues("micrometer.observations.annotations.enabled=false")
|
.withPropertyValues("management.observations.annotations.enabled=false")
|
||||||
.run((context) -> {
|
.run((context) -> {
|
||||||
assertThat(context).doesNotHaveBean(DefaultNewSpanParser.class);
|
assertThat(context).doesNotHaveBean(DefaultNewSpanParser.class);
|
||||||
assertThat(context).doesNotHaveBean(ImperativeMethodInvocationProcessor.class);
|
assertThat(context).doesNotHaveBean(ImperativeMethodInvocationProcessor.class);
|
||||||
@ -141,6 +140,18 @@ class MicrometerTracingAutoConfigurationTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
void shouldNotSupplyBeansIfAspectjIsMissing() {
|
void shouldNotSupplyBeansIfAspectjIsMissing() {
|
||||||
this.contextRunner.withUserConfiguration(TracerConfiguration.class)
|
this.contextRunner.withUserConfiguration(TracerConfiguration.class)
|
||||||
|
@ -1067,7 +1067,7 @@ Metrics for Jetty's `Connector` instances are bound by using Micrometer's `Jetty
|
|||||||
|
|
||||||
[[actuator.metrics.supported.timed-annotation]]
|
[[actuator.metrics.supported.timed-annotation]]
|
||||||
==== @Timed Annotation Support
|
==== @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].
|
Please refer to the {micrometer-concepts-docs}#_the_timed_annotation[Micrometer documentation].
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,5 +92,5 @@ The next sections will provide more details about logging, metrics and traces.
|
|||||||
|
|
||||||
[[actuator.observability.annotations]]
|
[[actuator.observability.annotations]]
|
||||||
=== Micrometer Observation Annotations support
|
=== 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.
|
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.
|
||||||
|
Loading…
Reference in New Issue
Block a user