|
|
@ -34,7 +34,6 @@ import io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObserv
|
|
|
|
import io.micrometer.observation.ObservationPredicate;
|
|
|
|
import io.micrometer.observation.ObservationPredicate;
|
|
|
|
import io.micrometer.observation.ObservationRegistry;
|
|
|
|
import io.micrometer.observation.ObservationRegistry;
|
|
|
|
import io.micrometer.tracing.Tracer;
|
|
|
|
import io.micrometer.tracing.Tracer;
|
|
|
|
import io.micrometer.tracing.handler.TracingAwareMeterObservationHandler;
|
|
|
|
|
|
|
|
import io.micrometer.tracing.handler.TracingObservationHandler;
|
|
|
|
import io.micrometer.tracing.handler.TracingObservationHandler;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.mockito.Answers;
|
|
|
|
import org.mockito.Answers;
|
|
|
@ -56,7 +55,6 @@ import static org.mockito.Mockito.mock;
|
|
|
|
* Tests for {@link ObservationAutoConfiguration}.
|
|
|
|
* Tests for {@link ObservationAutoConfiguration}.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Moritz Halbritter
|
|
|
|
* @author Moritz Halbritter
|
|
|
|
* @author Jonatan Ivanov
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class ObservationAutoConfigurationTests {
|
|
|
|
class ObservationAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
@ -67,16 +65,6 @@ class ObservationAutoConfigurationTests {
|
|
|
|
private final ApplicationContextRunner tracingContextRunner = new ApplicationContextRunner()
|
|
|
|
private final ApplicationContextRunner tracingContextRunner = new ApplicationContextRunner()
|
|
|
|
.with(MetricsRun.simple()).withConfiguration(AutoConfigurations.of(ObservationAutoConfiguration.class));
|
|
|
|
.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
|
|
|
|
@Test
|
|
|
|
void autoConfiguresDefaultMeterObservationHandler() {
|
|
|
|
void autoConfiguresDefaultMeterObservationHandler() {
|
|
|
|
this.contextRunner.run((context) -> {
|
|
|
|
this.contextRunner.run((context) -> {
|
|
|
@ -87,17 +75,9 @@ class ObservationAutoConfigurationTests {
|
|
|
|
// Observation leads to a timer
|
|
|
|
// Observation leads to a timer
|
|
|
|
MeterRegistry meterRegistry = context.getBean(MeterRegistry.class);
|
|
|
|
MeterRegistry meterRegistry = context.getBean(MeterRegistry.class);
|
|
|
|
assertThat(meterRegistry.get("test-observation").timer().count()).isEqualTo(1);
|
|
|
|
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
|
|
|
|
@Test
|
|
|
|
void autoConfiguresObservationPredicates() {
|
|
|
|
void autoConfiguresObservationPredicates() {
|
|
|
|
this.contextRunner.withUserConfiguration(ObservationPredicates.class).run((context) -> {
|
|
|
|
this.contextRunner.withUserConfiguration(ObservationPredicates.class).run((context) -> {
|
|
|
@ -139,8 +119,6 @@ class ObservationAutoConfigurationTests {
|
|
|
|
assertThat(handlers.get(1)).isInstanceOf(CustomMeterObservationHandler.class);
|
|
|
|
assertThat(handlers.get(1)).isInstanceOf(CustomMeterObservationHandler.class);
|
|
|
|
assertThat(((CustomMeterObservationHandler) handlers.get(1)).getName())
|
|
|
|
assertThat(((CustomMeterObservationHandler) handlers.get(1)).getName())
|
|
|
|
.isEqualTo("customMeterObservationHandler1");
|
|
|
|
.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();
|
|
|
|
Observation.start("test-observation", () -> customContext, observationRegistry).stop();
|
|
|
|
assertThat(handlers).hasSize(1);
|
|
|
|
assertThat(handlers).hasSize(1);
|
|
|
|
assertThat(handlers.get(0)).isInstanceOf(ObservationHandlerWithCustomContext.class);
|
|
|
|
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<ObservationHandler<?>> 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
|
|
|
|
@Test
|
|
|
|
void autoConfiguresObservationHandlerWhenTracingIsActive() {
|
|
|
|
void autoConfiguresObservationHandlerWhenTracingIsActive() {
|
|
|
|
this.tracingContextRunner.withUserConfiguration(ObservationHandlersTracing.class).run((context) -> {
|
|
|
|
this.tracingContextRunner.withUserConfiguration(ObservationHandlersTracing.class).run((context) -> {
|
|
|
@ -195,8 +156,6 @@ class ObservationAutoConfigurationTests {
|
|
|
|
assertThat(handlers.get(2)).isInstanceOf(CustomMeterObservationHandler.class);
|
|
|
|
assertThat(handlers.get(2)).isInstanceOf(CustomMeterObservationHandler.class);
|
|
|
|
assertThat(((CustomMeterObservationHandler) handlers.get(2)).getName())
|
|
|
|
assertThat(((CustomMeterObservationHandler) handlers.get(2)).getName())
|
|
|
|
.isEqualTo("customMeterObservationHandler1");
|
|
|
|
.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)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Import(CalledHandlersConfiguration.class)
|
|
|
|
@Import(CalledHandlersConfiguration.class)
|
|
|
|
static class ObservationHandlersTracing {
|
|
|
|
static class ObservationHandlersTracing {
|
|
|
@ -339,11 +282,6 @@ class ObservationAutoConfigurationTests {
|
|
|
|
return new CustomMeterObservationHandler("customMeterObservationHandler1", calledHandlers);
|
|
|
|
return new CustomMeterObservationHandler("customMeterObservationHandler1", calledHandlers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
Tracer tracer() {
|
|
|
|
|
|
|
|
return mock(Tracer.class); // simulating tracer configuration
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class CustomTracingObservationHandler implements TracingObservationHandler<Context> {
|
|
|
|
private static class CustomTracingObservationHandler implements TracingObservationHandler<Context> {
|
|
|
|