diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java index b0412d3bd916..12fba3e48132 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java @@ -110,6 +110,9 @@ public static Tag uri(ServerWebExchange exchange, boolean ignoreTrailingSlash) { if (ignoreTrailingSlash && patternString.length() > 1) { patternString = TRAILING_SLASH_PATTERN.matcher(patternString).replaceAll(""); } + if (patternString.isEmpty()) { + return URI_ROOT; + } return Tag.of("uri", patternString); } HttpStatus status = exchange.getResponse().getStatusCode(); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java index beb69db0386b..e5e2147bf8bb 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java @@ -115,6 +115,9 @@ public static Tag uri(HttpServletRequest request, HttpServletResponse response, if (ignoreTrailingSlash && pattern.length() > 1) { pattern = TRAILING_SLASH_PATTERN.matcher(pattern).replaceAll(""); } + if (pattern.isEmpty()) { + return URI_ROOT; + } return Tag.of("uri", pattern); } if (response != null) { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java index 44f9f1a5a20a..36ba42db687b 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java @@ -58,6 +58,14 @@ void uriTagValueIsBestMatchingPatternWhenAvailable() { assertThat(tag.getValue()).isEqualTo("/spring/"); } + @Test + void uriTagValueIsRootWhenBestMatchingPatternIsEmpty() { + this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, ""); + this.response.setStatus(301); + Tag tag = WebMvcTags.uri(this.request, this.response); + assertThat(tag.getValue()).isEqualTo("root"); + } + @Test void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() { this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring/"); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java index 033d4d793250..90c6b3650431 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java @@ -61,6 +61,14 @@ void uriTagValueIsBestMatchingPatternWhenAvailable() { assertThat(tag.getValue()).isEqualTo("/spring/"); } + @Test + void uriTagValueIsRootWhenBestMatchingPatternIsEmpty() { + this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, this.parser.parse("")); + this.exchange.getResponse().setStatusCode(HttpStatus.MOVED_PERMANENTLY); + Tag tag = WebFluxTags.uri(this.exchange); + assertThat(tag.getValue()).isEqualTo("root"); + } + @Test void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() { this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,