Resolve TODOs for observability tests

See gh-33481
pull/33514/head
Johnny Lim 2 years ago committed by Moritz Halbritter
parent ad63cb8e62
commit d21572a189

@ -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'?");
});

@ -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'?");
});

Loading…
Cancel
Save