From 257af0bda77eddeaef578604a4a35d29db3a2944 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 17 Mar 2019 10:29:42 -0600 Subject: [PATCH] moved accepted method types to beginning of url --- .../AbstractMethodInterceptor.java | 3 +- .../RequestMappingMethodInterceptor.java | 29 ++++++++++++------- .../RestMappingMethodInterceptor.java | 5 ++++ .../webflux/v5/AbstractMethodInterceptor.java | 7 +++-- .../v5/RequestMappingMethodInterceptor.java | 29 ++++++++++++------- .../v5/RestMappingMethodInterceptor.java | 5 ++++ 6 files changed, 52 insertions(+), 26 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java index 64748a265d..8c200113d8 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java @@ -44,6 +44,7 @@ import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.RESP */ public abstract class AbstractMethodInterceptor implements InstanceMethodsAroundInterceptor { public abstract String getRequestURL(Method method); + public abstract String getAcceptedMethodTypes(Method method); @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, @@ -67,7 +68,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround if (requestURL == null) { requestURL = getRequestURL(method); pathMappingCache.addPathMapping(method, requestURL); - requestURL = pathMappingCache.findPathMapping(method); + requestURL = getAcceptedMethodTypes(method) + pathMappingCache.findPathMapping(method); } operationName = requestURL; } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java index c45a387868..38f939717a 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RequestMappingMethodInterceptor.java @@ -31,23 +31,30 @@ import java.lang.reflect.Method; public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { @Override public String getRequestURL(Method method) { - StringBuilder requestURL = new StringBuilder(); + String requestURL = ""; RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); + if (methodRequestMapping.value().length > 0) { + requestURL = methodRequestMapping.value()[0]; + } else if (methodRequestMapping.path().length > 0) { + requestURL = methodRequestMapping.path()[0]; + } + return requestURL; + } + + @Override + public String getAcceptedMethodTypes(Method method) { + RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); + StringBuilder methodTypes = new StringBuilder(); if (methodRequestMapping.method().length > 0) { - requestURL.append("{"); + methodTypes.append("{"); for (int i = 0; i < methodRequestMapping.method().length; i++) { - requestURL.append(methodRequestMapping.method()[i].toString()); + methodTypes.append(methodRequestMapping.method()[i].toString()); if (methodRequestMapping.method().length > (i + 1)) { - requestURL.append(","); + methodTypes.append(","); } } - requestURL.append("}"); - } - if (methodRequestMapping.value().length > 0) { - requestURL.append(methodRequestMapping.value()[0]); - } else if (methodRequestMapping.path().length > 0) { - requestURL.append(methodRequestMapping.path()[0]); + methodTypes.append("}"); } - return requestURL.toString(); + return methodTypes.toString(); } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java index 5cea58d0d6..cfadb4e5ff 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/RestMappingMethodInterceptor.java @@ -73,4 +73,9 @@ public class RestMappingMethodInterceptor extends AbstractMethodInterceptor { } return requestURL; } + + @Override + public String getAcceptedMethodTypes(Method method) { + return ""; + } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/AbstractMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/AbstractMethodInterceptor.java index da9dae605f..43baad9ed3 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/AbstractMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/AbstractMethodInterceptor.java @@ -35,10 +35,11 @@ import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.FORW import static org.apache.skywalking.apm.plugin.spring.mvc.commons.Constants.WEBFLUX_REQUEST_KEY; /** - * the abstract method inteceptor + * the abstract method interceptor */ public abstract class AbstractMethodInterceptor implements InstanceMethodsAroundInterceptor { public abstract String getRequestURL(Method method); + public abstract String getAcceptedMethodTypes(Method method); @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, @@ -58,7 +59,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround if (requestURL == null) { requestURL = getRequestURL(method); pathMappingCache.addPathMapping(method, requestURL); - requestURL = pathMappingCache.findPathMapping(method); + requestURL = getAcceptedMethodTypes(method) + pathMappingCache.findPathMapping(method); } HttpRequest request = (HttpRequest)ContextManager.getRuntimeContext().get(WEBFLUX_REQUEST_KEY); @@ -71,7 +72,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround } AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier); - Tags.URL.set(span, request.uri().toString()); + Tags.URL.set(span, request.uri()); Tags.HTTP.METHOD.set(span, request.method().name()); span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); SpanLayer.asHttp(span); diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java index 17d5697e1d..e79372be53 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RequestMappingMethodInterceptor.java @@ -29,23 +29,30 @@ import org.springframework.web.bind.annotation.RequestMapping; public class RequestMappingMethodInterceptor extends AbstractMethodInterceptor { @Override public String getRequestURL(Method method) { - StringBuilder requestURL = new StringBuilder(); + String requestURL = ""; RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); + if (methodRequestMapping.value().length > 0) { + requestURL = methodRequestMapping.value()[0]; + } else if (methodRequestMapping.path().length > 0) { + requestURL = methodRequestMapping.path()[0]; + } + return requestURL; + } + + @Override + public String getAcceptedMethodTypes(Method method) { + RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class); + StringBuilder methodTypes = new StringBuilder(); if (methodRequestMapping.method().length > 0) { - requestURL.append("{"); + methodTypes.append("{"); for (int i = 0; i < methodRequestMapping.method().length; i++) { - requestURL.append(methodRequestMapping.method()[i].toString()); + methodTypes.append(methodRequestMapping.method()[i].toString()); if (methodRequestMapping.method().length > (i + 1)) { - requestURL.append(","); + methodTypes.append(","); } } - requestURL.append("}"); - } - if (methodRequestMapping.value().length > 0) { - requestURL.append(methodRequestMapping.value()[0]); - } else if (methodRequestMapping.path().length > 0) { - requestURL.append(methodRequestMapping.path()[0]); + methodTypes.append("}"); } - return requestURL.toString(); + return methodTypes.toString(); } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RestMappingMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RestMappingMethodInterceptor.java index 064671c272..3526ff4d2f 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RestMappingMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/webflux-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/webflux/v5/RestMappingMethodInterceptor.java @@ -74,4 +74,9 @@ public class RestMappingMethodInterceptor extends AbstractMethodInterceptor { } return requestURL; } + + @Override + public String getAcceptedMethodTypes(Method method) { + return ""; + } } -- GitLab