Skip to content

Commit a3737cd

Browse files
committed
Merge branch '2.1.x'
2 parents d5ae59d + 958e08c commit a3737cd

File tree

2 files changed

+38
-5
lines changed
  • spring-boot-project/spring-boot-actuator/src

2 files changed

+38
-5
lines changed

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,6 +41,8 @@ public final class WebFluxTags {
4141

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

44+
private static final Tag URI_UNKNOWN = Tag.of("uri", "UNKNOWN");
45+
4446
private static final Tag EXCEPTION_NONE = Tag.of("exception", "None");
4547

4648
private static final Tag OUTCOME_UNKNOWN = Tag.of("outcome", "UNKNOWN");
@@ -86,7 +88,10 @@ public static Tag status(ServerWebExchange exchange) {
8688

8789
/**
8890
* Creates a {@code uri} tag based on the URI of the given {@code exchange}. Uses the
89-
* {@link HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE} best matching pattern.
91+
* {@link HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE} best matching pattern if
92+
* available. Falling back to {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND}
93+
* for 404 responses, {@code root} for requests with no path info, and {@code UNKNOWN}
94+
* for all other requests.
9095
* @param exchange the exchange
9196
* @return the uri tag derived from the exchange
9297
*/
@@ -105,11 +110,17 @@ public static Tag uri(ServerWebExchange exchange) {
105110
return URI_NOT_FOUND;
106111
}
107112
}
108-
String path = exchange.getRequest().getPath().value();
113+
String path = getPathInfo(exchange);
109114
if (path.isEmpty()) {
110115
return URI_ROOT;
111116
}
112-
return Tag.of("uri", path);
117+
return URI_UNKNOWN;
118+
}
119+
120+
private static String getPathInfo(ServerWebExchange exchange) {
121+
String path = exchange.getRequest().getPath().value();
122+
String uri = StringUtils.hasText(path) ? path : "/";
123+
return uri.replaceAll("//+", "/").replaceAll("/$", "");
113124
}
114125

115126
/**

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,6 +79,28 @@ public void uriTagToleratesCustomResponseStatus() {
7979
assertThat(tag.getValue()).isEqualTo("root");
8080
}
8181

82+
@Test
83+
public void uriTagValueIsRootWhenRequestHasNoPatternOrPathInfo() {
84+
Tag tag = WebFluxTags.uri(this.exchange);
85+
assertThat(tag.getValue()).isEqualTo("root");
86+
}
87+
88+
@Test
89+
public void uriTagValueIsRootWhenRequestHasNoPatternAndSlashPathInfo() {
90+
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
91+
ServerWebExchange exchange = MockServerWebExchange.from(request);
92+
Tag tag = WebFluxTags.uri(exchange);
93+
assertThat(tag.getValue()).isEqualTo("root");
94+
}
95+
96+
@Test
97+
public void uriTagValueIsUnknownWhenRequestHasNoPatternAndNonRootPathInfo() {
98+
MockServerHttpRequest request = MockServerHttpRequest.get("/example").build();
99+
ServerWebExchange exchange = MockServerWebExchange.from(request);
100+
Tag tag = WebFluxTags.uri(exchange);
101+
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
102+
}
103+
82104
@Test
83105
public void methodTagToleratesNonStandardHttpMethods() {
84106
ServerWebExchange exchange = mock(ServerWebExchange.class);

0 commit comments

Comments
 (0)