Skip to content

Commit

Permalink
Add tests for gh-33867
Browse files Browse the repository at this point in the history
Closes gh-33867
  • Loading branch information
bclozel committed Nov 12, 2024
1 parent 4c3aeb3 commit 47f7e44
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO

private static final String DEFAULT_NAME = "http.client.requests";

private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+/?");
private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+");

private static final KeyValue URI_NONE = KeyValue.of(LowCardinalityKeyNames.URI, KeyValue.NONE_VALUE);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -88,6 +88,16 @@ void addsKeyValuesForRequestWithUriTemplateWithHost() {
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).contains(KeyValue.of("http.url", "https://example.org/resource/42"));
}

@Test
void addsKeyValuesForRequestWithUriTemplateWithoutPath() {
ClientRequestObservationContext context = createContext(
new MockClientHttpRequest(HttpMethod.GET, "https://example.org"), response);
context.setUriTemplate("https://example.org");
assertThat(this.observationConvention.getLowCardinalityKeyValues(context))
.contains(KeyValue.of("exception", "none"), KeyValue.of("method", "GET"), KeyValue.of("uri", "/"),
KeyValue.of("status", "200"), KeyValue.of("client.name", "example.org"), KeyValue.of("outcome", "SUCCESS"));
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).contains(KeyValue.of("http.url", "https://example.org"));
}

@Test
void addsKeyValuesForRequestWithoutUriTemplate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO

private static final String ROOT_PATH = "/";

private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+/?");
private static final Pattern PATTERN_BEFORE_PATH = Pattern.compile("^https?://[^/]+");

private static final KeyValue URI_NONE = KeyValue.of(LowCardinalityKeyNames.URI, KeyValue.NONE_VALUE);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -91,6 +91,19 @@ void shouldAddKeyValuesForRequestWithUriTemplate() {
.contains(KeyValue.of("http.url", "/resource/42"));
}

@Test
void shouldAddKeyValuesForRequestWithUriTemplateNoPath() {
ClientRequest.Builder request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.org"))
.attribute(WebClient.class.getName() + ".uriTemplate", "https://example.org");
ClientRequestObservationContext context = createContext(request);
context.setUriTemplate("https://example.org");
assertThat(this.observationConvention.getLowCardinalityKeyValues(context))
.contains(KeyValue.of("exception", "none"), KeyValue.of("method", "GET"), KeyValue.of("uri", "/"),
KeyValue.of("status", "200"), KeyValue.of("client.name", "example.org"), KeyValue.of("outcome", "SUCCESS"));
assertThat(this.observationConvention.getHighCardinalityKeyValues(context)).hasSize(1)
.contains(KeyValue.of("http.url", "https://example.org"));
}

@Test
void shouldAddKeyValuesForRequestWithoutUriTemplate() {
ClientRequestObservationContext context = createContext(ClientRequest.create(HttpMethod.GET, URI.create("/resource/42")));
Expand Down

0 comments on commit 47f7e44

Please sign in to comment.