You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2018/11/24 10:34:39 UTC
[incubator-skywalking] branch master updated: Fix the components of
Spring resttemplate is incorrect (#1956)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 7a9721a Fix the components of Spring resttemplate is incorrect (#1956)
7a9721a is described below
commit 7a9721a65aeeaf36f49b4df300cea463f4862daa
Author: Xin,Zhang <zh...@apache.org>
AuthorDate: Sat Nov 24 18:34:33 2018 +0800
Fix the components of Spring resttemplate is incorrect (#1956)
* Fix the components of Spring resttemplate is incorrect
* Fix check style
* Fix the version is incorrect
* Fix checkstyle
---
.../concurrent-util-4.x-plugin/pom.xml | 5 ++
.../concurrent/FailureCallbackInterceptor.java | 23 +++-----
.../concurrent/SuccessCallbackInterceptor.java | 21 +++----
apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml | 1 +
.../spring-plugins/resttemplate-4.x-plugin/pom.xml | 6 ++
.../async/ResponseCallBackInterceptor.java | 1 -
.../resttemplate/async/RestExecuteInterceptor.java | 9 ++-
.../resttemplate/async/RestRequestInterceptor.java | 3 +-
.../pom.xml | 25 ++-------
.../plugin/spring/commons/EnhanceCacheObjects.java | 64 ++++++++++++++++++++++
10 files changed, 104 insertions(+), 54 deletions(-)
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/pom.xml
index ff9326d..ebf2fc0 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/pom.xml
@@ -41,5 +41,10 @@
<version>${spring-core.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.skywalking</groupId>
+ <artifactId>spring-commons</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java
index 234224b..a174eff 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/FailureCallbackInterceptor.java
@@ -16,42 +16,35 @@
*
*/
-
package org.apache.skywalking.apm.plugin.spring.concurrent;
import java.lang.reflect.Method;
-import java.net.URI;
-import org.apache.skywalking.apm.agent.core.context.tag.Tags;
-import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
-import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
-import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import org.apache.skywalking.apm.plugin.spring.commons.EnhanceCacheObjects;
public class FailureCallbackInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
- Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
+ EnhanceCacheObjects cacheValues = (EnhanceCacheObjects)objInst.getSkyWalkingDynamicField();
if (cacheValues == null) {
return;
}
- URI uri = (URI)cacheValues[0];
- AbstractSpan span = ContextManager.createLocalSpan("future/failureCallback:" + uri.getPath());
- span.errorOccurred().log((Throwable)allArguments[0]).setComponent(ComponentsDefine.SPRING_REST_TEMPLATE).setLayer(SpanLayer.HTTP);
- Tags.URL.set(span, uri.getPath());
- ContextManager.continued((ContextSnapshot)cacheValues[2]);
+ AbstractSpan span = ContextManager.createLocalSpan("future/failureCallback:" + cacheValues.getOperationName());
+ span.errorOccurred().log((Throwable)allArguments[0]).setComponent(cacheValues.getComponent()).setLayer(cacheValues.getSpanLayer());
+ ContextManager.continued(cacheValues.getContextSnapshot());
}
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
- Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
+ EnhanceCacheObjects cacheValues = (EnhanceCacheObjects)objInst.getSkyWalkingDynamicField();
if (cacheValues == null) {
return ret;
}
@@ -61,7 +54,7 @@ public class FailureCallbackInterceptor implements InstanceMethodsAroundIntercep
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
- Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
+ EnhanceCacheObjects cacheValues = (EnhanceCacheObjects)objInst.getSkyWalkingDynamicField();
if (cacheValues == null) {
return;
}
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java
index dcacaab..e44ccf6 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/concurrent-util-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/concurrent/SuccessCallbackInterceptor.java
@@ -16,42 +16,35 @@
*
*/
-
package org.apache.skywalking.apm.plugin.spring.concurrent;
import java.lang.reflect.Method;
-import java.net.URI;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
-import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
-import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
-import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
-import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import org.apache.skywalking.apm.plugin.spring.commons.EnhanceCacheObjects;
public class SuccessCallbackInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
- Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
+ EnhanceCacheObjects cacheValues = (EnhanceCacheObjects)objInst.getSkyWalkingDynamicField();
if (cacheValues == null) {
return;
}
- URI uri = (URI)cacheValues[0];
- AbstractSpan span = ContextManager.createLocalSpan("future/successCallback:" + uri.getPath());
- span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE).setLayer(SpanLayer.HTTP);
- Tags.URL.set(span, uri.getPath());
- ContextManager.continued((ContextSnapshot)cacheValues[2]);
+ AbstractSpan span = ContextManager.createLocalSpan("future/successCallback:" + cacheValues.getOperationName());
+ span.setComponent(cacheValues.getComponent()).setLayer(cacheValues.getSpanLayer());
+ ContextManager.continued(cacheValues.getContextSnapshot());
}
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
- Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
+ EnhanceCacheObjects cacheValues = (EnhanceCacheObjects)objInst.getSkyWalkingDynamicField();
if (cacheValues == null) {
return ret;
}
@@ -61,7 +54,7 @@ public class SuccessCallbackInterceptor implements InstanceMethodsAroundIntercep
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
- Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
+ EnhanceCacheObjects cacheValues = (EnhanceCacheObjects)objInst.getSkyWalkingDynamicField();
if (cacheValues == null) {
return;
}
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml
index b49c68a..b83eea8 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml
@@ -35,6 +35,7 @@
<module>mvc-annotation-3.x-plugin</module>
<module>core-patch</module>
<module>mvc-annotation-commons</module>
+ <module>spring-commons</module>
</modules>
<packaging>pom</packaging>
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/pom.xml
index a62b10a..cc92ae2 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/pom.xml
@@ -41,5 +41,11 @@
<version>${spring-web.version}</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.skywalking</groupId>
+ <artifactId>spring-commons</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java
index f967a5f..bdba4ef 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/ResponseCallBackInterceptor.java
@@ -16,7 +16,6 @@
*
*/
-
package org.apache.skywalking.apm.plugin.spring.resttemplate.async;
import java.lang.reflect.Method;
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java
index f614896..9b80b6a 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestExecuteInterceptor.java
@@ -21,14 +21,16 @@ package org.apache.skywalking.apm.plugin.spring.resttemplate.async;
import java.lang.reflect.Method;
import java.net.URI;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
-import org.apache.skywalking.apm.agent.core.context.ContextManager;
-import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import org.apache.skywalking.apm.plugin.spring.commons.EnhanceCacheObjects;
import org.springframework.http.HttpMethod;
public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor {
@@ -59,7 +61,8 @@ public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor
Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
cacheValues[2] = ContextManager.capture();
if (ret != null) {
- ((EnhancedInstance)ret).setSkyWalkingDynamicField(cacheValues);
+ URI uri = (URI)cacheValues[0];
+ ((EnhancedInstance)ret).setSkyWalkingDynamicField(new EnhanceCacheObjects(uri.getPath(), ComponentsDefine.SPRING_REST_TEMPLATE, SpanLayer.HTTP, (ContextSnapshot)cacheValues[2]));
}
ContextManager.stopSpan();
return ret;
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java
index ba75bb4..fc44524 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/resttemplate/async/RestRequestInterceptor.java
@@ -16,13 +16,12 @@
*
*/
-
package org.apache.skywalking.apm.plugin.spring.resttemplate.async;
import java.lang.reflect.Method;
+import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
-import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.springframework.http.client.AsyncClientHttpRequest;
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-commons/pom.xml
similarity index 57%
copy from apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/pom.xml
copy to apm-sniffer/apm-sdk-plugin/spring-plugins/spring-commons/pom.xml
index a62b10a..8604539 100644
--- a/apm-sniffer/apm-sdk-plugin/spring-plugins/resttemplate-4.x-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-commons/pom.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
@@ -15,8 +16,9 @@
~ limitations under the License.
~
-->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-plugins</artifactId>
<groupId>org.apache.skywalking</groupId>
@@ -24,22 +26,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>apm-resttemplate-4.3.x-plugin</artifactId>
- <packaging>jar</packaging>
-
- <name>resttemplate-4.3.x-plugin</name>
- <url>http://maven.apache.org</url>
+ <artifactId>spring-commons</artifactId>
- <properties>
- <spring-web.version>4.3.10.RELEASE</spring-web.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- <version>${spring-web.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-</project>
+</project>
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/commons/EnhanceCacheObjects.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/commons/EnhanceCacheObjects.java
new file mode 100644
index 0000000..0acf909
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/commons/EnhanceCacheObjects.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.spring.commons;
+
+import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
+import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
+import org.apache.skywalking.apm.network.trace.component.OfficialComponent;
+
+public class EnhanceCacheObjects {
+ private OfficialComponent component;
+ private SpanLayer spanLayer;
+
+ private String operationName;
+ private ContextSnapshot contextSnapshot;
+
+ public EnhanceCacheObjects(String operationName, OfficialComponent component, SpanLayer spanLayer,
+ ContextSnapshot snapshot) {
+ this.component = component;
+ this.spanLayer = spanLayer;
+ this.operationName = operationName;
+ contextSnapshot = snapshot;
+ }
+
+ public EnhanceCacheObjects(String operationName, OfficialComponent component,
+ ContextSnapshot snapshot) {
+ this(operationName, component, null, snapshot);
+ }
+
+ public EnhanceCacheObjects(String operationName, ContextSnapshot snapshot) {
+ this(operationName, null, snapshot);
+ }
+
+ public OfficialComponent getComponent() {
+ return component;
+ }
+
+ public SpanLayer getSpanLayer() {
+ return spanLayer;
+ }
+
+ public String getOperationName() {
+ return operationName;
+ }
+
+ public ContextSnapshot getContextSnapshot() {
+ return contextSnapshot;
+ }
+}