From 7e9e64a2ea502202e1d2dfcaef51e0343a498601 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 12 Oct 2022 14:36:08 +0100 Subject: [PATCH] Revert "Merge pull request #32399 from jonatan-ivanov" This reverts commit ad40ef3398c704d8cf937c36a85bf60079f7dbae, reversing changes made to 6eb32647f58ff58ff839f5bdaae8b998f8970233. --- .../ObservationAutoConfiguration.java | 32 ++++------ .../ObservationAutoConfigurationTests.java | 62 ------------------- 2 files changed, 13 insertions(+), 81 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfiguration.java index ebff229197..0288371938 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfiguration.java @@ -20,21 +20,19 @@ import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler; import io.micrometer.core.instrument.observation.MeterObservationHandler; import io.micrometer.observation.GlobalObservationConvention; -import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; import io.micrometer.observation.ObservationPredicate; import io.micrometer.observation.ObservationRegistry; -import io.micrometer.tracing.Tracer; -import io.micrometer.tracing.handler.TracingAwareMeterObservationHandler; +import io.micrometer.tracing.handler.TracingObservationHandler; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; -import org.springframework.boot.actuate.autoconfigure.tracing.MicrometerTracingAutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 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.ConditionalOnMissingClass; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -44,10 +42,9 @@ import org.springframework.context.annotation.Configuration; * * @author Moritz Halbritter * @author Brian Clozel - * @author Jonatan Ivanov * @since 3.0.0 */ -@AutoConfiguration(after = { CompositeMeterRegistryAutoConfiguration.class, MicrometerTracingAutoConfiguration.class }) +@AutoConfiguration(after = CompositeMeterRegistryAutoConfiguration.class) @ConditionalOnClass(ObservationRegistry.class) @EnableConfigurationProperties(ObservationProperties.class) public class ObservationAutoConfiguration { @@ -70,16 +67,21 @@ public class ObservationAutoConfiguration { } @Configuration(proxyBeanMethods = false) - @ConditionalOnMissingBean(type = "io.micrometer.tracing.Tracer") - static class OnlyMetricsConfiguration { + @ConditionalOnBean(MeterRegistry.class) + static class MetricsConfiguration { @Bean @ConditionalOnMissingBean(MeterObservationHandler.class) - @ConditionalOnBean(MeterRegistry.class) DefaultMeterObservationHandler defaultMeterObservationHandler(MeterRegistry meterRegistry) { return new DefaultMeterObservationHandler(meterRegistry); } + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnMissingClass("io.micrometer.tracing.handler.TracingObservationHandler") + static class OnlyMetricsConfiguration { + @Bean OnlyMetricsObservationHandlerGrouping onlyMetricsObservationHandlerGrouping() { return new OnlyMetricsObservationHandlerGrouping(); @@ -88,16 +90,8 @@ public class ObservationAutoConfiguration { } @Configuration(proxyBeanMethods = false) - @ConditionalOnBean(Tracer.class) - static class MetricsWithTracingConfiguration { - - @Bean - @ConditionalOnMissingBean(MeterObservationHandler.class) - @ConditionalOnBean(MeterRegistry.class) - TracingAwareMeterObservationHandler tracingAwareMeterObservationHandler( - MeterRegistry meterRegistry, Tracer tracer) { - return new TracingAwareMeterObservationHandler<>(new DefaultMeterObservationHandler(meterRegistry), tracer); - } + @ConditionalOnClass(TracingObservationHandler.class) + static class TracingConfiguration { @Bean TracingObservationHandlerGrouping tracingObservationHandlerGrouping() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java index 0790c883e4..4f074e919f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java @@ -34,7 +34,6 @@ import io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObserv import io.micrometer.observation.ObservationPredicate; import io.micrometer.observation.ObservationRegistry; import io.micrometer.tracing.Tracer; -import io.micrometer.tracing.handler.TracingAwareMeterObservationHandler; import io.micrometer.tracing.handler.TracingObservationHandler; import org.junit.jupiter.api.Test; import org.mockito.Answers; @@ -56,7 +55,6 @@ import static org.mockito.Mockito.mock; * Tests for {@link ObservationAutoConfiguration}. * * @author Moritz Halbritter - * @author Jonatan Ivanov */ class ObservationAutoConfigurationTests { @@ -67,16 +65,6 @@ class ObservationAutoConfigurationTests { private final ApplicationContextRunner tracingContextRunner = new ApplicationContextRunner() .with(MetricsRun.simple()).withConfiguration(AutoConfigurations.of(ObservationAutoConfiguration.class)); - @Test - void beansShouldNotBeSuppliedWhenMicrometerObservationIsNotOnClassPath() { - this.tracingContextRunner.withClassLoader(new FilteredClassLoader("io.micrometer.observation")) - .run((context) -> { - assertThat(context).hasSingleBean(MeterRegistry.class); - assertThat(context).doesNotHaveBean(ObservationRegistry.class); - assertThat(context).doesNotHaveBean(MeterObservationHandler.class); - }); - } - @Test void autoConfiguresDefaultMeterObservationHandler() { this.contextRunner.run((context) -> { @@ -87,17 +75,9 @@ class ObservationAutoConfigurationTests { // Observation leads to a timer MeterRegistry meterRegistry = context.getBean(MeterRegistry.class); assertThat(meterRegistry.get("test-observation").timer().count()).isEqualTo(1); - assertThat(context).hasSingleBean(DefaultMeterObservationHandler.class); - assertThat(context.getBeansOfType(ObservationHandler.class)).hasSize(1); }); } - @Test - void allowsDefaultMeterObservationHandlerToBeDisabled() { - this.contextRunner.withClassLoader(new FilteredClassLoader(MeterRegistry.class)) - .run((context) -> assertThat(context).doesNotHaveBean(ObservationHandler.class)); - } - @Test void autoConfiguresObservationPredicates() { this.contextRunner.withUserConfiguration(ObservationPredicates.class).run((context) -> { @@ -139,8 +119,6 @@ class ObservationAutoConfigurationTests { assertThat(handlers.get(1)).isInstanceOf(CustomMeterObservationHandler.class); assertThat(((CustomMeterObservationHandler) handlers.get(1)).getName()) .isEqualTo("customMeterObservationHandler1"); - assertThat(context).doesNotHaveBean(DefaultMeterObservationHandler.class); - assertThat(context).doesNotHaveBean(TracingAwareMeterObservationHandler.class); }); } @@ -154,26 +132,9 @@ class ObservationAutoConfigurationTests { Observation.start("test-observation", () -> customContext, observationRegistry).stop(); assertThat(handlers).hasSize(1); assertThat(handlers.get(0)).isInstanceOf(ObservationHandlerWithCustomContext.class); - assertThat(context).hasSingleBean(DefaultMeterObservationHandler.class); - assertThat(context).doesNotHaveBean(TracingAwareMeterObservationHandler.class); }); } - @Test - void autoConfiguresTracingAwareMeterObservationHandler() { - this.tracingContextRunner.withUserConfiguration(CustomTracingObservationHandlers.class).run((context) -> { - ObservationRegistry observationRegistry = context.getBean(ObservationRegistry.class); - List> handlers = context.getBean(CalledHandlers.class).getCalledHandlers(); - // Intentionally not stopped since that will trigger additional logic in - // TracingAwareMeterObservationHandler that we don't test here - Observation.start("test-observation", observationRegistry); - assertThat(handlers).hasSize(1); - assertThat(handlers.get(0)).isInstanceOf(CustomTracingObservationHandler.class); - assertThat(context).hasSingleBean(TracingAwareMeterObservationHandler.class); - assertThat(context.getBeansOfType(ObservationHandler.class)).hasSize(2); - }); - } - @Test void autoConfiguresObservationHandlerWhenTracingIsActive() { this.tracingContextRunner.withUserConfiguration(ObservationHandlersTracing.class).run((context) -> { @@ -195,8 +156,6 @@ class ObservationAutoConfigurationTests { assertThat(handlers.get(2)).isInstanceOf(CustomMeterObservationHandler.class); assertThat(((CustomMeterObservationHandler) handlers.get(2)).getName()) .isEqualTo("customMeterObservationHandler1"); - assertThat(context).doesNotHaveBean(TracingAwareMeterObservationHandler.class); - assertThat(context).doesNotHaveBean(DefaultMeterObservationHandler.class); }); } @@ -277,22 +236,6 @@ class ObservationAutoConfigurationTests { } - @Configuration(proxyBeanMethods = false) - @Import(CalledHandlersConfiguration.class) - static class CustomTracingObservationHandlers { - - @Bean - CustomTracingObservationHandler customTracingHandler1(CalledHandlers calledHandlers) { - return new CustomTracingObservationHandler("customTracingHandler1", calledHandlers); - } - - @Bean - Tracer tracer() { - return mock(Tracer.class); // simulating tracer configuration - } - - } - @Configuration(proxyBeanMethods = false) @Import(CalledHandlersConfiguration.class) static class ObservationHandlersTracing { @@ -339,11 +282,6 @@ class ObservationAutoConfigurationTests { return new CustomMeterObservationHandler("customMeterObservationHandler1", calledHandlers); } - @Bean - Tracer tracer() { - return mock(Tracer.class); // simulating tracer configuration - } - } private static class CustomTracingObservationHandler implements TracingObservationHandler {