From a24efcf5e9107a8ebc6e7ddcb5e3c8cdf29a0d5e Mon Sep 17 00:00:00 2001
From: xiaoyu <549477611@qq.com>
Date: Sun, 14 Jun 2020 18:48:07 +0800
Subject: [PATCH] ShardingSphere plugins conflict among themselves. (#4921)
* Fix shardingSphere plugin test fail if have some same ENHANCE_CLASS define.
* support 4.1.0 and 4.1.1
* support 4.1.0 and 4.1.1
---
.github/workflows/plugins-test.2.yaml | 4 ++
CHANGES.md | 2 +-
.../sharding-sphere-4.1.0-plugin/pom.xml | 2 +-
.../v41/ExecuteInterceptor.java | 7 ++-
.../v41/JDBCRootInvokeInterceptor.java | 5 +-
.../v41/ProxyRootInvokeInterceptor.java | 5 +-
...stractShardingSphere41Instrumentation.java | 29 +++++++++++
.../v41/define/ExecuteInstrumentation.java | 3 +-
.../define/JDBCRootInvokeInstrumentation.java | 3 +-
.../ProxyRootInvokeInstrumentation.java | 3 +-
.../v41/threadlocal/ContextThreadLocal.java | 48 -------------------
...ractShardingSphereV4R3Instrumentation.java | 29 +++++++++++
.../v4rc3/define/ExecuteInstrumentation.java | 3 +-
.../define/JDBCRootInvokeInstrumentation.java | 3 +-
.../ProxyRootInvokeInstrumentation.java | 3 +-
...stractShardingSphereV4Instrumentation.java | 29 +++++++++++
.../v4/define/ExecuteInstrumentation.java | 3 +-
.../define/JDBCRootInvokeInstrumentation.java | 3 +-
.../ProxyRootInvokeInstrumentation.java | 3 +-
.../java-agent/Supported-list.md | 2 +-
.../shardingsphere-4.x-scenario/pom.xml | 8 ++--
.../utility/config/DataSourceUtil.java | 3 +-
.../support-version.list | 4 +-
23 files changed, 119 insertions(+), 85 deletions(-)
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/AbstractShardingSphere41Instrumentation.java
delete mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/threadlocal/ContextThreadLocal.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/AbstractShardingSphereV4R3Instrumentation.java
create mode 100644 apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4/define/AbstractShardingSphereV4Instrumentation.java
diff --git a/.github/workflows/plugins-test.2.yaml b/.github/workflows/plugins-test.2.yaml
index 76098daed..75a0a30dd 100644
--- a/.github/workflows/plugins-test.2.yaml
+++ b/.github/workflows/plugins-test.2.yaml
@@ -42,6 +42,10 @@ jobs:
- { name: 'resttemplate-4.x-scenario', title: 'RestTemplate 4.0.0.RELEASE-4.3.26.RELEASE (57)' }
- { name: 'servicecomb-0.x-scenario', title: 'ServiceComb 0.x (5)' }
- { name: 'servicecomb-1.x-scenario', title: 'ServiceComb 1.x (5)' }
+ - { name: 'shardingsphere-3.x-scenario', title: 'ShardingSphere 3.0.0 (1)' }
+ - { name: 'shardingsphere-4.x-RC1-RC2-scenario', title: 'ShardingSphere 4.0.0-RC1-4.0.0-RC2 (2)' }
+ - { name: 'shardingsphere-4.x-RC3-scenario', title: 'ShardingSphere 4.0.0-RC3 (1)' }
+ - { name: 'shardingsphere-4.x-scenario', title: 'ShardingSphere 4.1.0-4.1.1 (2)' }
- { name: 'sofarpc-scenario', title: 'SofaRPC 5.4.0-5.6.2 (23)' }
- { name: 'solrj-7.x-scenario', title: 'SolrJ 7.x (12)' }
- { name: 'spring-3.0.x-scenario', title: 'Spring 3.0.x (8)' }
diff --git a/CHANGES.md b/CHANGES.md
index fa785d7db..956fa3d11 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -12,7 +12,7 @@ Release Notes.
* Support Prometheus network protocol. Metrics in Prometheus format could be transferred into SkyWalking.
* Python agent provided.
* All inventory caches have been removed.
-* Apache ShardingSphere(4.0.0, 4.1.1) agent plugin provided.
+* Apache ShardingSphere(4.1.0, 4.1.1) agent plugin provided.
#### Java Agent
* Add MariaDB plugin.
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/pom.xml
index 30dbcc184..7e48e0207 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/pom.xml
@@ -32,7 +32,7 @@
UTF-8
- [4.0.0,4.1.1]
+ 4.1.0
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ExecuteInterceptor.java
index 3381446ae..72fa54b58 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ExecuteInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ExecuteInterceptor.java
@@ -20,13 +20,14 @@ package org.apache.skywalking.apm.plugin.shardingsphere.v41;
import java.lang.reflect.Method;
import java.util.Map;
+
+import org.apache.shardingsphere.underlying.executor.engine.ExecutorDataMap;
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.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.shardingsphere.v41.threadlocal.ContextThreadLocal;
/**
* {@link ExecuteInterceptor} enhances. {@link org.apache.shardingsphere.sharding.execute.sql.execute.SQLExecuteCallback}
@@ -38,7 +39,7 @@ public class ExecuteInterceptor implements InstanceMethodsAroundInterceptor {
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
MethodInterceptResult result) {
ContextManager.createLocalSpan("/ShardingSphere/executeSQL/").setComponent(ComponentsDefine.SHARDING_SPHERE);
- ContextSnapshot contextSnapshot = (ContextSnapshot) ContextThreadLocal.getValue()
+ ContextSnapshot contextSnapshot = (ContextSnapshot) ExecutorDataMap.getValue()
.get(Constant.CONTEXT_SNAPSHOT);
if (null == contextSnapshot) {
contextSnapshot = (ContextSnapshot) ((Map) allArguments[2]).get(Constant.CONTEXT_SNAPSHOT);
@@ -52,7 +53,6 @@ public class ExecuteInterceptor implements InstanceMethodsAroundInterceptor {
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class>[] argumentsTypes,
Object ret) {
ContextManager.stopSpan();
- ContextThreadLocal.remove();
return ret;
}
@@ -60,6 +60,5 @@ public class ExecuteInterceptor implements InstanceMethodsAroundInterceptor {
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class>[] argumentsTypes, Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
- ContextThreadLocal.remove();
}
}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/JDBCRootInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/JDBCRootInvokeInterceptor.java
index b7ed611f7..d468d976f 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/JDBCRootInvokeInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/JDBCRootInvokeInterceptor.java
@@ -19,12 +19,13 @@
package org.apache.skywalking.apm.plugin.shardingsphere.v41;
import java.lang.reflect.Method;
+
+import org.apache.shardingsphere.underlying.executor.engine.ExecutorDataMap;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
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.shardingsphere.v41.threadlocal.ContextThreadLocal;
/**
* {@link JDBCRootInvokeInterceptor} enhances {@link org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor},
@@ -37,7 +38,7 @@ public class JDBCRootInvokeInterceptor implements InstanceMethodsAroundIntercept
MethodInterceptResult result) {
ContextManager.createLocalSpan("/ShardingSphere/JDBCRootInvoke/")
.setComponent(ComponentsDefine.SHARDING_SPHERE);
- ContextThreadLocal.getValue().put(Constant.CONTEXT_SNAPSHOT, ContextManager.capture());
+ ExecutorDataMap.getValue().put(Constant.CONTEXT_SNAPSHOT, ContextManager.capture());
}
@Override
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ProxyRootInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ProxyRootInvokeInterceptor.java
index 2dc29fdf2..35e30e8ab 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ProxyRootInvokeInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/ProxyRootInvokeInterceptor.java
@@ -19,12 +19,13 @@
package org.apache.skywalking.apm.plugin.shardingsphere.v41;
import java.lang.reflect.Method;
+
+import org.apache.shardingsphere.underlying.executor.engine.ExecutorDataMap;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
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.shardingsphere.v41.threadlocal.ContextThreadLocal;
/**
* ProxyRootInvokeInterceptor enhances. skywalking intercepts org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask
@@ -37,7 +38,7 @@ public class ProxyRootInvokeInterceptor implements InstanceMethodsAroundIntercep
MethodInterceptResult result) {
ContextManager.createLocalSpan("/ShardingSphere/ProxyRootInvoke/")
.setComponent(ComponentsDefine.SHARDING_SPHERE);
- ContextThreadLocal.getValue().put(Constant.CONTEXT_SNAPSHOT, ContextManager.capture());
+ ExecutorDataMap.getValue().put(Constant.CONTEXT_SNAPSHOT, ContextManager.capture());
}
@Override
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/AbstractShardingSphere41Instrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/AbstractShardingSphere41Instrumentation.java
new file mode 100644
index 000000000..69b8439de
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/AbstractShardingSphere41Instrumentation.java
@@ -0,0 +1,29 @@
+/*
+ * 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.shardingsphere.v41.define;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+
+public abstract class AbstractShardingSphere41Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+ public static final String WITHNESS_CLASSES = "org.apache.shardingsphere.sql.parser.SQLParserEngine";
+
+ @Override
+ protected final String[] witnessClasses() {
+ return new String[] {WITHNESS_CLASSES};
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ExecuteInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ExecuteInstrumentation.java
index 61f3990ff..4771806c0 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ExecuteInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ExecuteInstrumentation.java
@@ -22,7 +22,6 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
@@ -31,7 +30,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link ExecuteInstrumentation} presents that skywalking intercepts. {@link org.apache.shardingsphere.sharding.execute.sql.execute.SQLExecuteCallback}.
*/
-public class ExecuteInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+public class ExecuteInstrumentation extends AbstractShardingSphere41Instrumentation {
private static final String ENHANCE_CLASS = "org.apache.shardingsphere.sharding.execute.sql.execute.SQLExecuteCallback";
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/JDBCRootInvokeInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/JDBCRootInvokeInstrumentation.java
index 6305e0aed..a92283fdf 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/JDBCRootInvokeInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/JDBCRootInvokeInstrumentation.java
@@ -22,7 +22,6 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
@@ -31,7 +30,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link JDBCRootInvokeInstrumentation} presents that skywalking intercepts. {@link org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor}.
*/
-public class JDBCRootInvokeInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+public class JDBCRootInvokeInstrumentation extends AbstractShardingSphere41Instrumentation {
private static final String ENHANCE_CLASS = "org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor";
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ProxyRootInvokeInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ProxyRootInvokeInstrumentation.java
index 6aa51ae55..8427ae838 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ProxyRootInvokeInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/define/ProxyRootInvokeInstrumentation.java
@@ -22,7 +22,6 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
@@ -31,7 +30,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* ProxyRootInvokeInstrumentation presents that skywalking intercepts. skywalking intercepts org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.
*/
-public class ProxyRootInvokeInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+public class ProxyRootInvokeInstrumentation extends AbstractShardingSphere41Instrumentation {
private static final String ENHANCE_CLASS = "org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask";
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/threadlocal/ContextThreadLocal.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/threadlocal/ContextThreadLocal.java
deleted file mode 100644
index 12e4e1db6..000000000
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.1.0-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v41/threadlocal/ContextThreadLocal.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.shardingsphere.v41.threadlocal;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-/**
- * Context thread local for skywalking.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ContextThreadLocal {
-
- private static ThreadLocal