From d21572a18939edc4f56929786ee4a43deb15b52f Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Tue, 6 Dec 2022 23:52:30 +0900 Subject: [PATCH] Resolve TODOs for observability tests See gh-33481 --- ...RestTemplateObservationConfigurationTests.java | 8 +++++--- .../WebClientObservationConfigurationTests.java | 15 +++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/RestTemplateObservationConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/RestTemplateObservationConfigurationTests.java index a9b34f4c62..5be2fdeff7 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/RestTemplateObservationConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/RestTemplateObservationConfigurationTests.java @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.observation.web.client; import io.micrometer.common.KeyValues; +import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tags; import io.micrometer.observation.ObservationRegistry; @@ -134,7 +135,6 @@ class RestTemplateObservationConfigurationTests { void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) { this.contextRunner.with(MetricsRun.simple()).withPropertyValues("management.metrics.web.client.max-uri-tags=2") .run((context) -> { - RestTemplate restTemplate = context.getBean(RestTemplateBuilder.class).build(); MockRestServiceServer server = MockRestServiceServer.createServer(restTemplate); for (int i = 0; i < 3; i++) { @@ -144,8 +144,10 @@ class RestTemplateObservationConfigurationTests { restTemplate.getForObject("/test/" + i, String.class); } TestObservationRegistry registry = context.getBean(TestObservationRegistry.class); - TestObservationRegistryAssert.assertThat(registry); - // TODO: check observation count for name + TestObservationRegistryAssert.assertThat(registry) + .hasNumberOfObservationsWithNameEqualTo("http.client.requests", 3); + MeterRegistry meterRegistry = context.getBean(MeterRegistry.class); + assertThat(meterRegistry.find("http.client.requests").timers()).hasSize(2); assertThat(output).contains("Reached the maximum number of URI tags for 'http.client.requests'.") .contains("Are you using 'uriVariables'?"); }); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/WebClientObservationConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/WebClientObservationConfigurationTests.java index c9a5cd8f8a..28e09337ea 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/WebClientObservationConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/web/client/WebClientObservationConfigurationTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.observation.web.client; import java.time.Duration; import io.micrometer.common.KeyValues; +import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.tck.TestObservationRegistry; import io.micrometer.observation.tck.TestObservationRegistryAssert; @@ -105,8 +106,12 @@ class WebClientObservationConfigurationTests { void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) { this.contextRunner.withPropertyValues("management.metrics.web.client.max-uri-tags=2").run((context) -> { TestObservationRegistry registry = getInitializedRegistry(context); - // TODO check size is 2 - TestObservationRegistryAssert.assertThat(registry).hasObservationWithNameEqualTo("http.client.requests"); + TestObservationRegistryAssert.assertThat(registry) + .hasNumberOfObservationsWithNameEqualTo("http.client.requests", 3); + MeterRegistry meterRegistry = context.getBean(MeterRegistry.class); + assertThat(meterRegistry.find("http.client.requests").timers()).hasSize(1); + // MeterFilter.maximumAllowableTags() works with prefix matching. + assertThat(meterRegistry.find("http.client.requests.active").longTaskTimers()).hasSize(1); assertThat(output).contains("Reached the maximum number of URI tags for 'http.client.requests'.") .contains("Are you using 'uriVariables'?"); }); @@ -116,8 +121,10 @@ class WebClientObservationConfigurationTests { void shouldNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput output) { this.contextRunner.withPropertyValues("management.metrics.web.client.max-uri-tags=5").run((context) -> { TestObservationRegistry registry = getInitializedRegistry(context); - // TODO check size is 3 - TestObservationRegistryAssert.assertThat(registry).hasObservationWithNameEqualTo("http.client.requests"); + TestObservationRegistryAssert.assertThat(registry) + .hasNumberOfObservationsWithNameEqualTo("http.client.requests", 3); + MeterRegistry meterRegistry = context.getBean(MeterRegistry.class); + assertThat(meterRegistry.find("http.client.requests").timers()).hasSize(3); assertThat(output).doesNotContain("Reached the maximum number of URI tags for 'http.client.requests'.") .doesNotContain("Are you using 'uriVariables'?"); });