Skip to content

Commit

Permalink
Resolve TODOs for observability tests
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye authored and mhalbritter committed Dec 9, 2022
1 parent ad63cb8 commit d21572a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,7 +135,6 @@ void restTemplateCreatedWithBuilderUsesCustomConvention() {
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++) {
Expand All @@ -144,8 +144,10 @@ void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) {
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'?");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -105,8 +106,12 @@ void shouldUseCustomConventionIfAvailable() {
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'?");
});
Expand All @@ -116,8 +121,10 @@ void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) {
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'?");
});
Expand Down

0 comments on commit d21572a

Please sign in to comment.