From d8d7af75edec09abc3bee7bfb732950dff55462a Mon Sep 17 00:00:00 2001 From: daming Date: Sat, 15 Jun 2019 20:09:33 +0800 Subject: [PATCH 01/11] remove imported classes unless JDK & ByteBuddy --- .../apm/plugin/motan/define/MotanConsumerInstrumentation.java | 3 +-- .../mysql/v8/define/ConnectionImplCreateInstrumentation.java | 3 +-- .../define/TransportClientHandlerInstrumentation.java | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java index 6d953a835ffe..cc40d74b747e 100644 --- a/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/motan-plugin/src/main/java/org/apache/skywalking/apm/plugin/motan/define/MotanConsumerInstrumentation.java @@ -18,7 +18,6 @@ package org.apache.skywalking.apm.plugin.motan.define; -import com.weibo.api.motan.rpc.Request; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; @@ -41,7 +40,7 @@ public class MotanConsumerInstrumentation extends ClassInstanceMethodsEnhancePlu */ private static final String CONSTRUCTOR_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.motan.MotanConsumerInterceptor"; /** - * Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. + * Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(com.weibo.api.motan.rpc.Request)}. */ private static final String PROVIDER_INVOKE_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.motan.MotanConsumerInterceptor"; diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/ConnectionImplCreateInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/ConnectionImplCreateInstrumentation.java index ab5a839208b3..c016f871508d 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/ConnectionImplCreateInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/ConnectionImplCreateInstrumentation.java @@ -19,7 +19,6 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define; -import com.mysql.cj.conf.HostInfo; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint; @@ -31,7 +30,7 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** - * interceptor the method {@link com.mysql.cj.jdbc.ConnectionImpl#getInstance(HostInfo)} + * interceptor the method {@link com.mysql.cj.jdbc.ConnectionImpl#getInstance(com.mysql.cj.conf.HostInfo)} * instead of {@link com.mysql.cj.jdbc.Driver#connect(String, Properties)} * @author: dingshaocheng */ diff --git a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/TransportClientHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/TransportClientHandlerInstrumentation.java index 2f43f95b1cf1..c8bfab42289a 100644 --- a/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/TransportClientHandlerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/define/TransportClientHandlerInstrumentation.java @@ -18,7 +18,6 @@ package org.apache.skywalking.apm.plugin.servicecomb.define; -import io.servicecomb.core.handler.impl.TransportClientHandler; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; @@ -30,7 +29,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link TransportClientHandlerInstrumentation} represents that skywalking intercept {@link TransportClientHandler} by + * {@link TransportClientHandlerInstrumentation} represents that skywalking intercept {@link io.servicecomb.core.handler.impl.TransportClientHandler} by * using linkTransportClientHandlerInterceptor * * @author lytscu From 4cb84ede7b2dac626fe9858d93abe0e3e7dd6ecc Mon Sep 17 00:00:00 2001 From: daming Date: Sun, 16 Jun 2019 01:00:05 +0800 Subject: [PATCH 02/11] import classes checker for instrumentation --- Jenkinsfile | 10 +++++++++- PluginImportedCheck.sh | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 PluginImportedCheck.sh diff --git a/Jenkinsfile b/Jenkinsfile index 6eaad7b07843..124576cdce7d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,7 +56,15 @@ pipeline { sh 'ls' sh 'git status' } - } + } + + stage('Check 3rd-party classes imported') { + steps { + sh './PluginImportedCheck.sh apm-sdk-plugin' + sh './PluginImportedCheck.sh apm-toolkit-activation' + sh './PluginImportedCheck.sh optional-plugins' + } + } stage('Test & Report') { steps { diff --git a/PluginImportedCheck.sh b/PluginImportedCheck.sh new file mode 100644 index 000000000000..92f1e1370ef1 --- /dev/null +++ b/PluginImportedCheck.sh @@ -0,0 +1,10 @@ +plugin_dir=$1 +for dir in `ls "./apm-sniffer/$plugin_dir/"`; do + for f in `find ./apm-sniffer/$plugin_dir/$dir -name *Instrumentation.java `; do + NUM=`head -400 $f | grep import |grep -v net.bytebuddy. | grep -v org.apache.skywalking. |grep -v java.| wc -l`; + if [ $NUM -gt 0 ] ; then + echo "Plugin: $dir, never import any class unless JDK and ByteBuddy!"; + exit 1; + fi + done +done From 1e14aa4caaa0f7d6b11b39372140690111d48f7d Mon Sep 17 00:00:00 2001 From: dmsolr Date: Sun, 16 Jun 2019 12:15:02 +0800 Subject: [PATCH 03/11] rename Jenkins stage name & add license header in checker script --- Jenkinsfile | 2 +- PluginImportedCheck.sh | 10 ------- .../check/agent/plugin/PluginImportedCheck.sh | 29 +++++++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) delete mode 100644 PluginImportedCheck.sh create mode 100644 tools/check/agent/plugin/PluginImportedCheck.sh diff --git a/Jenkinsfile b/Jenkinsfile index 124576cdce7d..f5b44f502cbb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,7 +58,7 @@ pipeline { } } - stage('Check 3rd-party classes imported') { + stage('Check agent plugin instrumentation imports') { steps { sh './PluginImportedCheck.sh apm-sdk-plugin' sh './PluginImportedCheck.sh apm-toolkit-activation' diff --git a/PluginImportedCheck.sh b/PluginImportedCheck.sh deleted file mode 100644 index 92f1e1370ef1..000000000000 --- a/PluginImportedCheck.sh +++ /dev/null @@ -1,10 +0,0 @@ -plugin_dir=$1 -for dir in `ls "./apm-sniffer/$plugin_dir/"`; do - for f in `find ./apm-sniffer/$plugin_dir/$dir -name *Instrumentation.java `; do - NUM=`head -400 $f | grep import |grep -v net.bytebuddy. | grep -v org.apache.skywalking. |grep -v java.| wc -l`; - if [ $NUM -gt 0 ] ; then - echo "Plugin: $dir, never import any class unless JDK and ByteBuddy!"; - exit 1; - fi - done -done diff --git a/tools/check/agent/plugin/PluginImportedCheck.sh b/tools/check/agent/plugin/PluginImportedCheck.sh new file mode 100644 index 000000000000..57b9840470e0 --- /dev/null +++ b/tools/check/agent/plugin/PluginImportedCheck.sh @@ -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. +# ---------------------------------------------------------------------------- + +plugin_dir=$1 +for dir in `ls "./apm-sniffer/$plugin_dir/"`; do + for f in `find ./apm-sniffer/$plugin_dir/$dir -name *Instrumentation.java `; do + NUM=`head -400 $f | grep ^import |grep -v net.bytebuddy. | grep -v org.apache.skywalking. |grep -v java.| wc -l`; + if [ $NUM -gt 0 ] ; then + echo "Plugin: $dir, never import any class unless JDK and ByteBuddy!"; + exit 1; + fi + done +done From a1dfba2d66f7fc66ae2fac41e6e5b04d3271d1dc Mon Sep 17 00:00:00 2001 From: dmsolr Date: Sun, 16 Jun 2019 12:21:32 +0800 Subject: [PATCH 04/11] grant shell to execute right. --- tools/check/agent/plugin/PluginImportedCheck.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tools/check/agent/plugin/PluginImportedCheck.sh diff --git a/tools/check/agent/plugin/PluginImportedCheck.sh b/tools/check/agent/plugin/PluginImportedCheck.sh old mode 100644 new mode 100755 From 723fb5bcb1c7c128b673ea1cf28cb8e65b0fa292 Mon Sep 17 00:00:00 2001 From: dmsolr Date: Sun, 16 Jun 2019 12:24:50 +0800 Subject: [PATCH 05/11] add header --- tools/check/agent/plugin/PluginImportedCheck.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/check/agent/plugin/PluginImportedCheck.sh b/tools/check/agent/plugin/PluginImportedCheck.sh index 57b9840470e0..24601def4060 100755 --- a/tools/check/agent/plugin/PluginImportedCheck.sh +++ b/tools/check/agent/plugin/PluginImportedCheck.sh @@ -1,3 +1,4 @@ +#!/bin/sh # ---------------------------------------------------------------------------- # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file From 1ab237324b95c754486b73dd38f86d967a2fd665 Mon Sep 17 00:00:00 2001 From: dmsolr Date: Sun, 16 Jun 2019 12:55:27 +0800 Subject: [PATCH 06/11] PluginImportedCheck.sh is moved --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f5b44f502cbb..06c86a1c1c71 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,9 +60,9 @@ pipeline { stage('Check agent plugin instrumentation imports') { steps { - sh './PluginImportedCheck.sh apm-sdk-plugin' - sh './PluginImportedCheck.sh apm-toolkit-activation' - sh './PluginImportedCheck.sh optional-plugins' + sh './tools/check/agent/plugin/PluginImportedCheck.sh apm-sdk-plugin' + sh './tools/check/agent/plugin/PluginImportedCheck.sh apm-toolkit-activation' + sh './tools/check/agent/plugin/PluginImportedCheck.sh optional-plugins' } } From a0c6b9d28638e3ce7dc8cc80dff7e19c72d315bd Mon Sep 17 00:00:00 2001 From: dmsolr Date: Sun, 16 Jun 2019 13:02:13 +0800 Subject: [PATCH 07/11] modify the error message --- tools/check/agent/plugin/PluginImportedCheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/check/agent/plugin/PluginImportedCheck.sh b/tools/check/agent/plugin/PluginImportedCheck.sh index 24601def4060..bbef6508d3f2 100755 --- a/tools/check/agent/plugin/PluginImportedCheck.sh +++ b/tools/check/agent/plugin/PluginImportedCheck.sh @@ -23,7 +23,7 @@ for dir in `ls "./apm-sniffer/$plugin_dir/"`; do for f in `find ./apm-sniffer/$plugin_dir/$dir -name *Instrumentation.java `; do NUM=`head -400 $f | grep ^import |grep -v net.bytebuddy. | grep -v org.apache.skywalking. |grep -v java.| wc -l`; if [ $NUM -gt 0 ] ; then - echo "Plugin: $dir, never import any class unless JDK and ByteBuddy!"; + echo "Plugin: $dir, only allow to import JDK and ByteBuddy classes."; exit 1; fi done From 29158beb6249125d5725178519f2159a700b6323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Sun, 16 Jun 2019 13:35:43 +0800 Subject: [PATCH 08/11] Update PluginImportedCheck.sh --- tools/check/agent/plugin/PluginImportedCheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/check/agent/plugin/PluginImportedCheck.sh b/tools/check/agent/plugin/PluginImportedCheck.sh index bbef6508d3f2..7611dfafc491 100755 --- a/tools/check/agent/plugin/PluginImportedCheck.sh +++ b/tools/check/agent/plugin/PluginImportedCheck.sh @@ -23,7 +23,7 @@ for dir in `ls "./apm-sniffer/$plugin_dir/"`; do for f in `find ./apm-sniffer/$plugin_dir/$dir -name *Instrumentation.java `; do NUM=`head -400 $f | grep ^import |grep -v net.bytebuddy. | grep -v org.apache.skywalking. |grep -v java.| wc -l`; if [ $NUM -gt 0 ] ; then - echo "Plugin: $dir, only allow to import JDK and ByteBuddy classes."; + echo "Plugin: $dir, only allow to import JDK and ByteBuddy classes in Instrumentation definition."; exit 1; fi done From 613cd193415ea663433f0faab6e7b1dda834b0df Mon Sep 17 00:00:00 2001 From: dmsolr Date: Sun, 16 Jun 2019 14:45:38 +0800 Subject: [PATCH 09/11] fix bad cases --- tools/check/agent/plugin/PluginImportedCheck.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/check/agent/plugin/PluginImportedCheck.sh b/tools/check/agent/plugin/PluginImportedCheck.sh index 7611dfafc491..04054edfd616 100755 --- a/tools/check/agent/plugin/PluginImportedCheck.sh +++ b/tools/check/agent/plugin/PluginImportedCheck.sh @@ -20,10 +20,12 @@ plugin_dir=$1 for dir in `ls "./apm-sniffer/$plugin_dir/"`; do + echo "Scanning $dir" for f in `find ./apm-sniffer/$plugin_dir/$dir -name *Instrumentation.java `; do - NUM=`head -400 $f | grep ^import |grep -v net.bytebuddy. | grep -v org.apache.skywalking. |grep -v java.| wc -l`; + NUM=`head -400 $f | grep ^import |grep -Ev "^import\s+(static\s+)*net.bytebuddy\\." \ + | grep -Ev "^import\s+(static\s+)*org.apache.skywalking\\." |grep -Ev "^import\s+(static\s+)*java(x)*\\." | wc -l` if [ $NUM -gt 0 ] ; then - echo "Plugin: $dir, only allow to import JDK and ByteBuddy classes in Instrumentation definition."; + echo "Plugin: $dir($f), only allow to import JDK and ByteBuddy classes in Instrumentation definition."; exit 1; fi done From 164aa9374985c9bf3286f3594492ff1f6b3cfa4f Mon Sep 17 00:00:00 2001 From: dmsolr Date: Sun, 16 Jun 2019 21:27:19 +0800 Subject: [PATCH 10/11] javax.* is not allowed. --- tools/check/agent/plugin/PluginImportedCheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/check/agent/plugin/PluginImportedCheck.sh b/tools/check/agent/plugin/PluginImportedCheck.sh index 04054edfd616..ceae494b7c10 100755 --- a/tools/check/agent/plugin/PluginImportedCheck.sh +++ b/tools/check/agent/plugin/PluginImportedCheck.sh @@ -23,7 +23,7 @@ for dir in `ls "./apm-sniffer/$plugin_dir/"`; do echo "Scanning $dir" for f in `find ./apm-sniffer/$plugin_dir/$dir -name *Instrumentation.java `; do NUM=`head -400 $f | grep ^import |grep -Ev "^import\s+(static\s+)*net.bytebuddy\\." \ - | grep -Ev "^import\s+(static\s+)*org.apache.skywalking\\." |grep -Ev "^import\s+(static\s+)*java(x)*\\." | wc -l` + | grep -Ev "^import\s+(static\s+)*org.apache.skywalking\\." |grep -Ev "^import\s+(static\s+)*java*\\." | wc -l` if [ $NUM -gt 0 ] ; then echo "Plugin: $dir($f), only allow to import JDK and ByteBuddy classes in Instrumentation definition."; exit 1; From 32312aa1a017045a7c9b41c3f57598a21f56c64d Mon Sep 17 00:00:00 2001 From: dmsolr Date: Sun, 16 Jun 2019 21:33:27 +0800 Subject: [PATCH 11/11] javax.* is not allowed. --- tools/check/agent/plugin/PluginImportedCheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/check/agent/plugin/PluginImportedCheck.sh b/tools/check/agent/plugin/PluginImportedCheck.sh index ceae494b7c10..508449171399 100755 --- a/tools/check/agent/plugin/PluginImportedCheck.sh +++ b/tools/check/agent/plugin/PluginImportedCheck.sh @@ -23,7 +23,7 @@ for dir in `ls "./apm-sniffer/$plugin_dir/"`; do echo "Scanning $dir" for f in `find ./apm-sniffer/$plugin_dir/$dir -name *Instrumentation.java `; do NUM=`head -400 $f | grep ^import |grep -Ev "^import\s+(static\s+)*net.bytebuddy\\." \ - | grep -Ev "^import\s+(static\s+)*org.apache.skywalking\\." |grep -Ev "^import\s+(static\s+)*java*\\." | wc -l` + | grep -Ev "^import\s+(static\s+)*org.apache.skywalking\\." |grep -Ev "^import\s+(static\s+)*java\\." | wc -l` if [ $NUM -gt 0 ] ; then echo "Plugin: $dir($f), only allow to import JDK and ByteBuddy classes in Instrumentation definition."; exit 1;