Skip to content

Commit

Permalink
Add tests verifying that Apache (Async) HTTP clients don't have speci…
Browse files Browse the repository at this point in the history
…al handling for 404

See micrometer-metricsgh-5812

Signed-off-by: Johnny Lim <[email protected]>
  • Loading branch information
izeye committed Jan 29, 2025
1 parent 099323d commit 78efa4e
Showing 1 changed file with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,27 @@ void recordClientErrorExchanges(@WiremockResolver.Wiremock WireMockServer server
.that()
.hasLowCardinalityKeyValue(OUTCOME.withValue("CLIENT_ERROR"))
.hasLowCardinalityKeyValue(STATUS.withValue("404"))
.hasLowCardinalityKeyValue(METHOD.withValue("GET"));
.hasLowCardinalityKeyValue(METHOD.withValue("GET"))
.hasLowCardinalityKeyValue(URI.withValue("UNKNOWN"));
}

@Test
void recordClientErrorExchangesWithUriPatternHeader(@WiremockResolver.Wiremock WireMockServer server)
throws Exception {
String uriPattern = "/resources/{id}";

server.stubFor(any(urlEqualTo("/resources/1")).willReturn(aResponse().withStatus(404)));
try (CloseableHttpClient client = classicClient()) {
HttpGet request = new HttpGet(server.baseUrl() + "/resources/1");
request.addHeader(DefaultUriMapper.URI_PATTERN_HEADER, uriPattern);
executeClassic(client, request);
}
assertThat(observationRegistry).hasObservationWithNameEqualTo(DEFAULT_METER_NAME)
.that()
.hasLowCardinalityKeyValue(OUTCOME.withValue("CLIENT_ERROR"))
.hasLowCardinalityKeyValue(STATUS.withValue("404"))
.hasLowCardinalityKeyValue(METHOD.withValue("GET"))
.hasLowCardinalityKeyValue(URI.withValue(uriPattern));
}

@Test
Expand Down Expand Up @@ -281,7 +301,27 @@ void recordClientErrorExchanges(@WiremockResolver.Wiremock WireMockServer server
.that()
.hasLowCardinalityKeyValue(OUTCOME.withValue("CLIENT_ERROR"))
.hasLowCardinalityKeyValue(STATUS.withValue("404"))
.hasLowCardinalityKeyValue(METHOD.withValue("GET"));
.hasLowCardinalityKeyValue(METHOD.withValue("GET"))
.hasLowCardinalityKeyValue(URI.withValue("UNKNOWN"));
}

@Test
void recordClientErrorExchangesWithUriPatternHeader(@WiremockResolver.Wiremock WireMockServer server)
throws Exception {
String uriPattern = "/resources/{id}";

server.stubFor(any(urlEqualTo("/notfound")).willReturn(aResponse().withStatus(404)));
try (CloseableHttpAsyncClient client = asyncClient()) {
SimpleHttpRequest request = SimpleRequestBuilder.get(server.baseUrl() + "/notfound").build();
request.addHeader(DefaultUriMapper.URI_PATTERN_HEADER, uriPattern);
executeAsync(client, request);
}
assertThat(observationRegistry).hasObservationWithNameEqualTo(DEFAULT_METER_NAME)
.that()
.hasLowCardinalityKeyValue(OUTCOME.withValue("CLIENT_ERROR"))
.hasLowCardinalityKeyValue(STATUS.withValue("404"))
.hasLowCardinalityKeyValue(METHOD.withValue("GET"))
.hasLowCardinalityKeyValue(URI.withValue(uriPattern));
}

@Test
Expand Down

0 comments on commit 78efa4e

Please sign in to comment.