Skip to content

Commit e957051

Browse files
committed
use uri instead of servletpath
and use Optional to handle nullable query string
1 parent 4a9c9f5 commit e957051

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

src/main/java/nl/dtls/fairdatapoint/api/filter/RequestMetricsFilter.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.web.filter.OncePerRequestFilter;
1111

1212
import java.io.IOException;
13+
import java.util.Optional;
1314

1415
@Slf4j
1516
@Component
@@ -37,22 +38,17 @@ public void doFilterInternal(
3738
final HttpServletResponse response,
3839
final FilterChain filterChain
3940
) throws IOException, ServletException {
41+
log.debug("Actuator counting request for {}", request.getRequestURL());
42+
// From [servlet spec]: requestURI = contextPath + servletPath + pathInfo
43+
// [servlet spec]: https://jakarta.ee/specifications/servlet/6.1/jakarta-servlet-spec-6.1#request-path-elements
4044
final String uri = request.getRequestURI();
4145
final String method = request.getMethod();
42-
String query = request.getQueryString();
43-
if (query == null) {
44-
query = "";
45-
}
46-
String path = request.getServletPath();
47-
if (path == null) {
48-
path = "";
49-
}
50-
log.debug("Actuator counting request for {}", uri);
46+
final Optional<String> query = Optional.ofNullable(request.getQueryString());
5147
meterRegistry.counter(
5248
"custom",
5349
"method", method,
54-
"path", path,
55-
"query", query
50+
"query", query.orElseGet(() -> ""),
51+
"uri", uri
5652
).increment();
5753
filterChain.doFilter(request, response);
5854
}

0 commit comments

Comments
 (0)