Skip to content

Commit 6fba477

Browse files
committed
Remove redundant handling of a null exchange from WebFluxTags.uri()
Closes gh-14504
1 parent 6020cb6 commit 6fba477

File tree

2 files changed

+16
-27
lines changed
  • spring-boot-project/spring-boot-actuator/src

2 files changed

+16
-27
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public final class WebFluxTags {
4040

4141
private static final Tag URI_ROOT = Tag.of("uri", "root");
4242

43-
private static final Tag URI_UNKNOWN = Tag.of("uri", "UNKNOWN");
44-
4543
private static final Tag EXCEPTION_NONE = Tag.of("exception", "None");
4644

4745
private WebFluxTags() {
@@ -80,26 +78,23 @@ public static Tag status(ServerWebExchange exchange) {
8078
* @return the uri tag derived from the exchange
8179
*/
8280
public static Tag uri(ServerWebExchange exchange) {
83-
if (exchange != null) {
84-
PathPattern pathPattern = exchange
85-
.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
86-
if (pathPattern != null) {
87-
return Tag.of("uri", pathPattern.getPatternString());
88-
}
89-
HttpStatus status = exchange.getResponse().getStatusCode();
90-
if (status != null && status.is3xxRedirection()) {
91-
return URI_REDIRECTION;
92-
}
93-
if (status != null && status.equals(HttpStatus.NOT_FOUND)) {
94-
return URI_NOT_FOUND;
95-
}
96-
String path = exchange.getRequest().getPath().value();
97-
if (path.isEmpty()) {
98-
return URI_ROOT;
99-
}
100-
return Tag.of("uri", path);
81+
PathPattern pathPattern = exchange
82+
.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
83+
if (pathPattern != null) {
84+
return Tag.of("uri", pathPattern.getPatternString());
85+
}
86+
HttpStatus status = exchange.getResponse().getStatusCode();
87+
if (status != null && status.is3xxRedirection()) {
88+
return URI_REDIRECTION;
89+
}
90+
if (status != null && status.equals(HttpStatus.NOT_FOUND)) {
91+
return URI_NOT_FOUND;
92+
}
93+
String path = exchange.getRequest().getPath().value();
94+
if (path.isEmpty()) {
95+
return URI_ROOT;
10196
}
102-
return URI_UNKNOWN;
97+
return Tag.of("uri", path);
10398
}
10499

105100
/**

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ public void uriTagToleratesCustomResponseStatus() {
7878
assertThat(tag.getValue()).isEqualTo("root");
7979
}
8080

81-
@Test
82-
public void uriTagIsUnknownWhenRequestIsNull() {
83-
Tag tag = WebFluxTags.uri(null);
84-
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
85-
}
86-
8781
@Test
8882
public void methodTagToleratesNonStandardHttpMethods() {
8983
ServerWebExchange exchange = mock(ServerWebExchange.class);

0 commit comments

Comments
 (0)