From 331c7a1c565c96f140565d6914b71368e8e6d2a2 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 20 Nov 2017 13:18:48 +0000 Subject: [PATCH] Make handler Object available to WebMvcTagsProvider.httpRequestTags Closes gh-11088 --- .../metrics/web/servlet/DefaultWebMvcTagsProvider.java | 3 ++- .../boot/actuate/metrics/web/servlet/WebMvcMetrics.java | 9 ++++++--- .../actuate/metrics/web/servlet/WebMvcTagsProvider.java | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/DefaultWebMvcTagsProvider.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/DefaultWebMvcTagsProvider.java index 9d1263a192..e5d317739d 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/DefaultWebMvcTagsProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/DefaultWebMvcTagsProvider.java @@ -45,12 +45,13 @@ public class DefaultWebMvcTagsProvider implements WebMvcTagsProvider { /** * Supplies default tags to the Web MVC server programming model. * @param request The HTTP request. + * @param handler the Spring MVC handler for the request * @param response The HTTP response. * @param ex The current exception, if any * @return A set of tags added to every Spring MVC HTTP request. */ @Override - public Iterable httpRequestTags(HttpServletRequest request, + public Iterable httpRequestTags(HttpServletRequest request, Object handler, HttpServletResponse response, Throwable ex) { return Arrays.asList(WebMvcTags.method(request), WebMvcTags.uri(request, response), WebMvcTags.exception(ex), diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetrics.java index 14d52041b2..f63ea9198a 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetrics.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetrics.java @@ -45,6 +45,7 @@ import org.springframework.util.ObjectUtils; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.mvc.ParameterizableViewController; import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; /** @@ -144,16 +145,18 @@ public class WebMvcMetrics { Throwable thrown) { // record Timer values timed(handler).forEach((config) -> { - Timer.Builder builder = getTimerBuilder(request, response, thrown, config); + Timer.Builder builder = getTimerBuilder(request, handler, response, thrown, + config); long amount = endTime - startTime; builder.register(this.registry).record(amount, TimeUnit.NANOSECONDS); }); } - private Timer.Builder getTimerBuilder(HttpServletRequest request, + private Timer.Builder getTimerBuilder(HttpServletRequest request, Object handler, HttpServletResponse response, Throwable thrown, TimerConfig config) { Timer.Builder builder = Timer.builder(config.getName()) - .tags(this.tagsProvider.httpRequestTags(request, response, thrown)) + .tags(this.tagsProvider.httpRequestTags(request, handler, response, + thrown)) .tags(config.getExtraTags()).description("Timer of servlet request") .publishPercentileHistogram(config.isHistogram()); if (config.getPercentiles().length > 0) { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsProvider.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsProvider.java index a4d612057a..3b2d22ceec 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTagsProvider.java @@ -41,13 +41,14 @@ public interface WebMvcTagsProvider { /** * Provides tags to be associated with metrics for the given {@code request} and - * {@code response} exchange. + * {@code response} exchange. The request was handled by the given {@code handler}. * @param request the request + * @param handler the handler * @param response the response * @param ex the current exception, if any * @return tags to associate with metrics for the request and response exchange */ - Iterable httpRequestTags(HttpServletRequest request, + Iterable httpRequestTags(HttpServletRequest request, Object handler, HttpServletResponse response, Throwable ex); }