From 772b4428d16748e596df7f25975bdf3152235043 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 31 Oct 2017 23:58:31 +0800 Subject: [PATCH 1/4] fix occur ClassCastException when return generate key --- .../ConnectionServiceMethodInterceptor.java | 18 +--- .../jdbc/trace/CallableStatementTracing.java | 9 +- .../apm/plugin/jdbc/trace/ConnectionInfo.java | 31 ++---- .../jdbc/trace/PreparedStatementTracing.java | 10 +- .../plugin/jdbc/trace/StatementTracing.java | 10 +- .../apm/plugin/jdbc/ConnectionTracing.java | 9 +- .../connectionurl/parser/URLParserTest.java | 31 +++--- .../CreateCallableStatementInterceptor.java | 54 +++++++++++ .../CreatePreparedStatementInterceptor.java | 54 +++++++++++ .../mysql/CreateStatementInterceptor.java | 54 +++++++++++ .../StatementExecuteMethodsInterceptor.java | 78 +++++++++++++++ ...tractPreparedStatementInstrumentation.java | 69 +++++++++++++ .../mysql/define/CallableInstrumentation.java | 69 +++++++++++++ .../define/ConnectionInstrumentation.java | 15 ++- .../mysql/define/DriverInstrumentation.java | 4 +- ...DBC42PreparedStatementInstrumentation.java | 36 +++++++ .../mysql/define/MultiClassNameMatch.java | 67 +++++++++++++ .../PreparedStatementInstrumentation.java | 38 ++++++++ .../mysql/define/StatementEnhanceInfos.java | 51 ++++++++++ .../define/StatementInstrumentation.java | 83 ++++++++++++++++ .../src/main/resources/skywalking-plugin.def | 4 + ...reateCallableStatementInterceptorTest.java | 66 +++++++++++++ ...reatePreparedStatementInterceptorTest.java | 65 +++++++++++++ .../mysql/CreateStatementInterceptorTest.java | 66 +++++++++++++ ...tatementExecuteMethodsInterceptorTest.java | 96 +++++++++++++++++++ 25 files changed, 983 insertions(+), 104 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/AbstractPreparedStatementInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/JDBC42PreparedStatementInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementEnhanceInfos.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java index 0ae91f465..b3476192a 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java @@ -27,15 +27,11 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.skywalking.apm.util.StringUtil; /** - * {@link ConnectionServiceMethodInterceptor} create an exit span when the client call the following methods in the class - * that extend {@link java.sql.Connection}. - * 1. close - * 2. rollback - * 3. releaseSavepoint - * 4. commit + * {@link ConnectionServiceMethodInterceptor} create an exit span when the client call the following methods in the + * class that extend {@link java.sql.Connection}. 1. close 2. rollback 3. releaseSavepoint 4. commit + * * @author zhangxin */ public class ConnectionServiceMethodInterceptor implements InstanceMethodsAroundInterceptor { @@ -45,13 +41,7 @@ public class ConnectionServiceMethodInterceptor implements InstanceMethodsAround Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { ConnectionInfo connectInfo = (ConnectionInfo)objInst.getSkyWalkingDynamicField(); - String remotePeer; - if (!StringUtil.isEmpty(connectInfo.getHosts())) { - remotePeer = connectInfo.getHosts(); - } else { - remotePeer = connectInfo.getHost() + ":" + connectInfo.getPort(); - } - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method.getName(), remotePeer); + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method.getName(), connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, ""); diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java index d0b25cc94..c0a3fcad4 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/CallableStatementTracing.java @@ -23,7 +23,6 @@ import org.skywalking.apm.agent.core.context.ContextManager; import org.skywalking.apm.agent.core.context.tag.Tags; import org.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.util.StringUtil; /** * {@link CallableStatementTracing} create an exit span when the client call the method in the class that extend {@link @@ -37,13 +36,7 @@ public class CallableStatementTracing { ConnectionInfo connectInfo, String method, String sql, Executable exec) throws SQLException { try { - String remotePeer; - if (!StringUtil.isEmpty(connectInfo.getHosts())) { - remotePeer = connectInfo.getHosts(); - } else { - remotePeer = connectInfo.getHost() + ":" + connectInfo.getPort(); - } - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, remotePeer); + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); SpanLayer.asDB(span); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java index a9ab5e5c4..724afb26d 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/ConnectionInfo.java @@ -31,22 +31,12 @@ public class ConnectionInfo { * DB type, such as mysql, oracle, h2. */ private final String dbType; - /** - * Database host name. - */ - private String host; - /** - * Database port. - */ - private int port; /** * Operation database name. */ private final String databaseName; - /** - * Database hosts. - */ - private String hosts; + + private String databasePeer; /** * Component @@ -55,15 +45,14 @@ public class ConnectionInfo { public ConnectionInfo(OfficialComponent component, String dbType, String host, int port, String databaseName) { this.dbType = dbType; - this.host = host; - this.port = port; + this.databasePeer = host + ":" + port; this.databaseName = databaseName; this.component = component; } public ConnectionInfo(OfficialComponent component, String dbType, String hosts, String databaseName) { this.dbType = dbType; - this.hosts = hosts; + this.databasePeer = hosts; this.databaseName = databaseName; this.component = component; } @@ -72,20 +61,12 @@ public class ConnectionInfo { return dbType; } - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - public String getDatabaseName() { return databaseName; } - public String getHosts() { - return hosts; + public String getDatabasePeer() { + return databasePeer; } public OfficialComponent getComponent() { diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java index 66d0f9f16..900366d71 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/PreparedStatementTracing.java @@ -23,7 +23,6 @@ import org.skywalking.apm.agent.core.context.ContextManager; import org.skywalking.apm.agent.core.context.tag.Tags; import org.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.util.StringUtil; /** * {@link PreparedStatementTracing} create an exit span when the client call the method in the class that extend {@link @@ -37,14 +36,7 @@ public class PreparedStatementTracing { ConnectionInfo connectInfo, String method, String sql, Executable exec) throws SQLException { try { - String remotePeer; - if (!StringUtil.isEmpty(connectInfo.getHosts())) { - remotePeer = connectInfo.getHosts(); - } else { - remotePeer = connectInfo.getHost() + ":" + connectInfo.getPort(); - } - - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/PreparedStatement/" + method, remotePeer); + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/PreparedStatement/" + method, connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, sql); diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/StatementTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/StatementTracing.java index 20e44032b..46ac2da7f 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/StatementTracing.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/trace/StatementTracing.java @@ -23,7 +23,6 @@ import org.skywalking.apm.agent.core.context.ContextManager; import org.skywalking.apm.agent.core.context.tag.Tags; import org.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.skywalking.apm.agent.core.context.trace.SpanLayer; -import org.skywalking.apm.util.StringUtil; /** * {@link PreparedStatementTracing} create an exit span when the client call the method in the class that extend {@link @@ -36,14 +35,7 @@ public class StatementTracing { ConnectionInfo connectInfo, String method, String sql, Executable exec) throws SQLException { try { - String remotePeer; - if (!StringUtil.isEmpty(connectInfo.getHosts())) { - remotePeer = connectInfo.getHosts(); - } else { - remotePeer = connectInfo.getHost() + ":" + connectInfo.getPort(); - } - - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Statement/" + method, remotePeer); + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Statement/" + method, connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, sql); diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/ConnectionTracing.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/ConnectionTracing.java index 8432fd914..45fc7c2de 100755 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/ConnectionTracing.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/ConnectionTracing.java @@ -24,7 +24,6 @@ import org.skywalking.apm.agent.core.context.tag.Tags; import org.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.skywalking.apm.agent.core.context.trace.SpanLayer; import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.skywalking.apm.util.StringUtil; public class ConnectionTracing { @@ -32,13 +31,7 @@ public class ConnectionTracing { ConnectionInfo connectInfo, String method, String sql, Executable exec) throws SQLException { try { - String remotePeer; - if (!StringUtil.isEmpty(connectInfo.getHosts())) { - remotePeer = connectInfo.getHosts(); - } else { - remotePeer = connectInfo.getHost() + ":" + connectInfo.getPort(); - } - AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method, remotePeer); + AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method, connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, sql); diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java index 6d24e76aa..7f15d3392 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java @@ -30,8 +30,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost/test"); assertThat(connectionInfo.getDBType(), is("Mysql")); assertThat(connectionInfo.getDatabaseName(), is("test")); - assertThat(connectionInfo.getHost(), is("primaryhost")); - assertThat(connectionInfo.getPort(), is(3306)); + assertThat(connectionInfo.getDatabasePeer(), is("primaryhost:3306")); } @Test @@ -39,8 +38,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost:3307/test?profileSQL=true"); assertThat(connectionInfo.getDBType(), is("Mysql")); assertThat(connectionInfo.getDatabaseName(), is("test")); - assertThat(connectionInfo.getHost(), is("primaryhost")); - assertThat(connectionInfo.getPort(), is(3307)); + assertThat(connectionInfo.getDatabasePeer(), is("primaryhost:3307")); } @Test @@ -48,7 +46,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost:3307,secondaryhost1,secondaryhost2/test?profileSQL=true"); assertThat(connectionInfo.getDBType(), is("Mysql")); assertThat(connectionInfo.getDatabaseName(), is("test")); - assertThat(connectionInfo.getHosts(), is("primaryhost:3307,secondaryhost1:3306,secondaryhost2:3306,")); + assertThat(connectionInfo.getDatabasePeer(), is("primaryhost:3307,secondaryhost1:3306,secondaryhost2:3306,")); } @Test @@ -56,7 +54,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql:replication://master,slave1,slave2,slave3/test"); assertThat(connectionInfo.getDBType(), is("Mysql")); assertThat(connectionInfo.getDatabaseName(), is("test")); - assertThat(connectionInfo.getHosts(), is("master:3306,slave1:3306,slave2:3306,slave3:3306,")); + assertThat(connectionInfo.getDatabasePeer(), is("master:3306,slave1:3306,slave2:3306,slave3:3306,")); } @Test @@ -64,8 +62,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@localhost:orcl"); assertThat(connectionInfo.getDBType(), is("Oracle")); assertThat(connectionInfo.getDatabaseName(), is("orcl")); - assertThat(connectionInfo.getHost(), is("localhost")); - assertThat(connectionInfo.getPort(), is(1521)); + assertThat(connectionInfo.getDatabasePeer(), is("localhost:1521")); } @Test @@ -73,8 +70,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@localhost:1522:orcl"); assertThat(connectionInfo.getDBType(), is("Oracle")); assertThat(connectionInfo.getDatabaseName(), is("orcl")); - assertThat(connectionInfo.getHost(), is("localhost")); - assertThat(connectionInfo.getPort(), is(1522)); + assertThat(connectionInfo.getDatabasePeer(), is("localhost:1522")); } @Test @@ -82,8 +78,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:scott/tiger@myhost:1521:orcl"); assertThat(connectionInfo.getDBType(), is("Oracle")); assertThat(connectionInfo.getDatabaseName(), is("orcl")); - assertThat(connectionInfo.getHost(), is("myhost")); - assertThat(connectionInfo.getPort(), is(1521)); + assertThat(connectionInfo.getDatabasePeer(), is("myhost:1521")); } @Test @@ -91,8 +86,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:file:/data/sample"); assertThat(connectionInfo.getDBType(), is("H2")); assertThat(connectionInfo.getDatabaseName(), is("/data/sample")); - assertThat(connectionInfo.getHost(), is("localhost")); - assertThat(connectionInfo.getPort(), is(-1)); + assertThat(connectionInfo.getDatabasePeer(), is("localhost:-1")); } @Test @@ -100,8 +94,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:file:C:/data/sample"); assertThat(connectionInfo.getDBType(), is("H2")); assertThat(connectionInfo.getDatabaseName(), is("C:/data/sample")); - assertThat(connectionInfo.getHost(), is("localhost")); - assertThat(connectionInfo.getPort(), is(-1)); + assertThat(connectionInfo.getDatabasePeer(), is("localhost:-1")); } @Test @@ -109,8 +102,7 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:mem:test_mem"); assertThat(connectionInfo.getDBType(), is("H2")); assertThat(connectionInfo.getDatabaseName(), is("test_mem")); - assertThat(connectionInfo.getHost(), is("localhost")); - assertThat(connectionInfo.getPort(), is(-1)); + assertThat(connectionInfo.getDatabasePeer(), is("localhost:-1")); } @Test @@ -118,7 +110,6 @@ public class URLParserTest { ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:tcp://localhost:8084/~/sample"); assertThat(connectionInfo.getDBType(), is("H2")); assertThat(connectionInfo.getDatabaseName(), is("sample")); - assertThat(connectionInfo.getHost(), is("localhost")); - assertThat(connectionInfo.getPort(), is(8084)); + assertThat(connectionInfo.getDatabasePeer(), is("localhost:8084")); } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java new file mode 100644 index 000000000..5aaa176ab --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java @@ -0,0 +1,54 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.skywalking.apm.plugin.jdbc.mysql.define.StatementEnhanceInfos; +import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link CreateStatementInterceptor} intercepts the {@link com.mysql.jdbc.ConnectionImpl#createStatement()} method in + * the {@link com.mysql.jdbc.ConnectionImpl} class. + * + * @author zhangxin + */ +public class CreateCallableStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "CallableStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java new file mode 100644 index 000000000..ca4c7deed --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java @@ -0,0 +1,54 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.skywalking.apm.plugin.jdbc.mysql.define.StatementEnhanceInfos; +import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link CreateStatementInterceptor} intercepts the {@link com.mysql.jdbc.ConnectionImpl#prepareStatement()} method in + * the {@link com.mysql.jdbc.ConnectionImpl} class. + * + * @author zhangxin + */ +public class CreatePreparedStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "PreparedStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java new file mode 100644 index 000000000..564254b5c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java @@ -0,0 +1,54 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.skywalking.apm.plugin.jdbc.mysql.define.StatementEnhanceInfos; +import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link CreateStatementInterceptor} intercepts the {@link com.mysql.jdbc.ConnectionImpl#createStatement()} method in + * the {@link com.mysql.jdbc.ConnectionImpl} class. + * + * @author zhangxin + */ +public class CreateStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), "", "CallableStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java new file mode 100644 index 000000000..d8fbd58cd --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java @@ -0,0 +1,78 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.skywalking.apm.agent.core.context.ContextManager; +import org.skywalking.apm.agent.core.context.tag.Tags; +import org.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.skywalking.apm.plugin.jdbc.mysql.define.StatementEnhanceInfos; +import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link StatementExecuteMethodsInterceptor} create the exit span when the client call the interceptor methods. + * + * @author zhangxin + */ +public class StatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + if (connectInfo != null) { + + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, cacheObject.getSql()); + span.setComponent(connectInfo.getComponent()); + + SpanLayer.asDB(span); + } + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } + + private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { + return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/AbstractPreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/AbstractPreparedStatementInstrumentation.java new file mode 100644 index 000000000..bf73036f9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/AbstractPreparedStatementInstrumentation.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link AbstractPreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in + * the {@link com.mysql.jdbc.JDBC42PreparedStatement} and {@link com.mysql.jdbc.PreparedStatement} class. + * 1. execute
+ * 2. executeQuery
+ * 3. executeUpdate
+ * 4. executeLargeUpdate
+ * 5. addBatch
+ * + * @author zhangxin + */ +public abstract class AbstractPreparedStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String SERVICE_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; + + @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")) + .or(named("addBatch")); + } + + @Override public String getMethodsInterceptor() { + return SERVICE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java new file mode 100644 index 000000000..f0e2fbb6d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; + +/** + * {@link CallableInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the {@link + * com.mysql.jdbc.CallableStatement} by {@link org.skywalking.apm.plugin.jdbc.mysql.CallableStatementInterceptor}. 1. + * execute
2. executeQuery
3. executeUpdate
+ * + * @author zhangxin + */ +public class CallableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "com.mysql.jdbc.CallableStatement"; + private static final String SERVICE_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")); + } + + @Override public String getMethodsInterceptor() { + return SERVICE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byMultiClassMath(ENHANCE_CLASS, "com.mysql.jdbc.cj.CallableStatement"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java index 2a952a55d..a45048cd1 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java @@ -27,21 +27,18 @@ import org.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; import static org.skywalking.apm.plugin.jdbc.define.Constants.CLOSE_METHOD_NAME; import static org.skywalking.apm.plugin.jdbc.define.Constants.COMMIT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_INTERCEPT_CLASS; import static org.skywalking.apm.plugin.jdbc.define.Constants.CREATE_STATEMENT_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_INTERCEPT_CLASS; import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_CALL_METHOD_NAME; -import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_INTERCEPT_CLASS; import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_METHOD_NAME; import static org.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME; import static org.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME; import static org.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; /** - * {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link + * {@link ConnectionInstrumentation} intercepts the following methods that the class which extend {@link * com.mysql.jdbc.ConnectionImpl}.
* * 1. Enhance prepareStatement by org.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor @@ -67,7 +64,7 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_INTERCEPT_CLASS; + return "org.skywalking.apm.plugin.jdbc.mysql.CreatePreparedStatementInterceptor"; } @Override public boolean isOverrideArgs() { @@ -80,7 +77,7 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override public String getMethodsInterceptor() { - return PREPARE_CALL_INTERCEPT_CLASS; + return "org.skywalking.apm.plugin.jdbc.mysql.CreateCallableStatementInterceptor"; } @Override public boolean isOverrideArgs() { @@ -93,7 +90,7 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override public String getMethodsInterceptor() { - return CREATE_STATEMENT_INTERCEPT_CLASS; + return "org.skywalking.apm.plugin.jdbc.mysql.CreateStatementInterceptor"; } @Override public boolean isOverrideArgs() { @@ -118,6 +115,6 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); + return byMultiClassMath(ENHANCE_CLASS, "com.mysql.cj.jdbc.ConnectionImpl"); } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java index daa0413c1..25d6ce62f 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java @@ -21,7 +21,7 @@ package org.skywalking.apm.plugin.jdbc.mysql.define; import org.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; /** * {@link DriverInstrumentation} presents that skywalking intercepts {@link com.mysql.jdbc.Driver}. @@ -31,6 +31,6 @@ import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; public class DriverInstrumentation extends AbstractDriverInstrumentation { @Override protected ClassMatch enhanceClass() { - return byName("com.mysql.jdbc.Driver"); + return byMultiClassMath("com.mysql.jdbc.Driver", "com.mysql.cj.jdbc.Driver"); } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/JDBC42PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/JDBC42PreparedStatementInstrumentation.java new file mode 100644 index 000000000..04f877fba --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/JDBC42PreparedStatementInstrumentation.java @@ -0,0 +1,36 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql.define; + +import org.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link JDBC42PreparedStatementInstrumentation} intercepts {@link com.mysql.jdbc.JDBC42PreparedStatement} class. + * + * @author zhangxin + */ +public class JDBC42PreparedStatementInstrumentation extends AbstractPreparedStatementInstrumentation { + private static final String ENHANCE_CLASS = "com.mysql.jdbc.JDBC42PreparedStatement"; + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java new file mode 100644 index 000000000..839b37875 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java @@ -0,0 +1,67 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql.define; + +import java.util.Arrays; +import java.util.List; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.skywalking.apm.agent.core.plugin.match.IndirectMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * Match multiple classes name with an explicit class name. + * + * @author zhangxin + */ +public class MultiClassNameMatch implements IndirectMatch { + + private List matchClassNames; + + private MultiClassNameMatch(String[] classNames) { + if (classNames == null || classNames.length == 0) { + throw new IllegalArgumentException("match class names is null"); + } + this.matchClassNames = Arrays.asList(classNames); + } + + @Override + public ElementMatcher.Junction buildJunction() { + ElementMatcher.Junction junction = null; + for (String name : matchClassNames) { + if (junction == null) { + junction = named(name); + } else { + junction = junction.or(named(name)); + } + } + return junction; + } + + @Override + public boolean isMatch(TypeDescription typeDescription) { + return matchClassNames.contains(typeDescription.getTypeName()); + } + + public static ClassMatch byMultiClassMath(String... classNames) { + return new MultiClassNameMatch(classNames); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java new file mode 100644 index 000000000..bf0480f2d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java @@ -0,0 +1,38 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql.define; + +import org.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; + +/** + * {@link JDBC42PreparedStatementInstrumentation} intercepts {@link com.mysql.jdbc.PreparedStatement} class. + * + * @author zhangxin + */ +public class PreparedStatementInstrumentation extends AbstractPreparedStatementInstrumentation { + + private static final String ENHANCE_CLASS = "com.mysql.jdbc.PreparedStatement"; + + @Override protected ClassMatch enhanceClass() { + return byMultiClassMath(ENHANCE_CLASS, "com.mysql.cj.jdbc.PreparedStatement"); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementEnhanceInfos.java new file mode 100644 index 000000000..4a6b8fbc4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementEnhanceInfos.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql.define; + +import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link StatementEnhanceInfos} contain the {@link org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo} and + * sql for trace mysql. + * + * @author zhangxin + */ +public class StatementEnhanceInfos { + private ConnectionInfo connectionInfo; + private String statementName; + private String sql; + + public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) { + this.connectionInfo = connectionInfo; + this.sql = sql; + this.statementName = statementName; + } + + public ConnectionInfo getConnectionInfo() { + return connectionInfo; + } + + public String getSql() { + return sql; + } + + public String getStatementName() { + return statementName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java new file mode 100644 index 000000000..0a63878ad --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java @@ -0,0 +1,83 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; + +/** + * {@link JDBC42PreparedStatementInstrumentation} intercepts the following methods in the {@link + * com.mysql.jdbc.JDBC42PreparedStatement} class. + * 1. execute
+ * 2. executeQuery
+ * 3. executeUpdate
+ * 4. executeLargeUpdate
+ * 5. addBatch
+ * 6. executeBatchInternal
+ * 7. executeUpdateInternal
+ * 8. executeQuery
+ * 9. executeBatch
+ * + * @author zhangxin + */ +public class StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String ENHANCE_CLASS = "com.mysql.jdbc.StatementImpl"; + private static final String SERVICE_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")) + .or(named("addBatch")) + .or(named("executeBatchInternal")) + .or(named("executeUpdateInternal")) + .or(named("executeQuery")) + .or(named("executeBatch")); + } + + @Override public String getMethodsInterceptor() { + return SERVICE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byMultiClassMath(ENHANCE_CLASS, "com.mysql.cj.jdbc.StatementImpl"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/resources/skywalking-plugin.def index db4e41ef3..622dc29d0 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,6 @@ mysql=org.skywalking.apm.plugin.jdbc.mysql.define.DriverInstrumentation mysql=org.skywalking.apm.plugin.jdbc.mysql.define.ConnectionInstrumentation +mysql=org.skywalking.apm.plugin.jdbc.mysql.define.CallableInstrumentation +mysql=org.skywalking.apm.plugin.jdbc.mysql.define.PreparedStatementInstrumentation +mysql=org.skywalking.apm.plugin.jdbc.mysql.define.JDBC42PreparedStatementInstrumentation +mysql=org.skywalking.apm.plugin.jdbc.mysql.define.StatementInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java new file mode 100644 index 000000000..2e71c7ad7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class CreateCallableStatementInterceptorTest { + + private CreateCallableStatementInterceptor interceptor; + + @Mock + private EnhancedInstance ret; + + @Mock + private EnhancedInstance objectInstance; + + @Mock + private ConnectionInfo connectionInfo; + + @Before + public void setUp() { + interceptor = new CreateCallableStatementInterceptor(); + + when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo); + } + + @Test + public void testResultIsEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret); + verify(ret, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } + + @Test + public void testResultIsNotEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, new Object()); + verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java new file mode 100644 index 000000000..99c3c45cf --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class CreatePreparedStatementInterceptorTest { + private CreatePreparedStatementInterceptor interceptor; + + @Mock + private EnhancedInstance ret; + + @Mock + private EnhancedInstance objectInstance; + + @Mock + private ConnectionInfo connectionInfo; + + @Before + public void setUp() { + interceptor = new CreatePreparedStatementInterceptor(); + + when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo); + } + + @Test + public void testResultIsEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret); + verify(ret, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } + + @Test + public void testResultIsNotEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, new Object()); + verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java new file mode 100644 index 000000000..19e94a425 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class CreateStatementInterceptorTest { + + private CreateStatementInterceptor interceptor; + + @Mock + private EnhancedInstance ret; + + @Mock + private EnhancedInstance objectInstance; + + @Mock + private ConnectionInfo connectionInfo; + + @Before + public void setUp() { + interceptor = new CreateStatementInterceptor(); + + when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo); + } + + @Test + public void testResultIsEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret); + verify(ret, times(1)).setSkyWalkingDynamicField(Matchers.any()); + } + + @Test + public void testResultIsNotEnhanceInstance() throws Throwable { + interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, new Object()); + verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java new file mode 100644 index 000000000..8c8425c6f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java @@ -0,0 +1,96 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.plugin.jdbc.mysql; + +import java.lang.reflect.Method; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.skywalking.apm.agent.test.helper.SegmentHelper; +import org.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.skywalking.apm.agent.test.tools.SegmentStorage; +import org.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.skywalking.apm.agent.test.tools.SpanAssert; +import org.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.skywalking.apm.network.trace.component.ComponentsDefine; +import org.skywalking.apm.plugin.jdbc.mysql.define.StatementEnhanceInfos; +import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class StatementExecuteMethodsInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private StatementExecuteMethodsInterceptor serviceMethodInterceptor; + + @Mock + private ConnectionInfo connectionInfo; + @Mock + private EnhancedInstance objectInstance; + @Mock + private Method method; + private StatementEnhanceInfos enhanceRequireCacheObject; + + @Before + public void setUp() { + serviceMethodInterceptor = new StatementExecuteMethodsInterceptor(); + + enhanceRequireCacheObject = new StatementEnhanceInfos(connectionInfo, "SELECT * FROM test", "CallableStatement"); + when(objectInstance.getSkyWalkingDynamicField()).thenReturn(enhanceRequireCacheObject); + when(method.getName()).thenReturn("executeQuery"); + when(connectionInfo.getComponent()).thenReturn(ComponentsDefine.H2); + when(connectionInfo.getDBType()).thenReturn("H2"); + when(connectionInfo.getDatabaseName()).thenReturn("test"); + when(connectionInfo.getDatabasePeer()).thenReturn("localhost:3307"); + } + + @Test + public void testCreateDatabaseSpan() throws Throwable { + serviceMethodInterceptor.beforeMethod(objectInstance, method, null, null, null); + serviceMethodInterceptor.afterMethod(objectInstance, method, null, null, null); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment segment = segmentStorage.getTraceSegments().get(0); + assertThat(SegmentHelper.getSpans(segment).size(), is(1)); + AbstractTracingSpan span = SegmentHelper.getSpans(segment).get(0); + SpanAssert.assertLayer(span, SpanLayer.DB); + assertThat(span.getOperationName(), is("H2/JDBI/CallableStatement/")); + SpanAssert.assertTag(span, 0, "sql"); + SpanAssert.assertTag(span, 1, "test"); + SpanAssert.assertTag(span, 2, "SELECT * FROM test"); + } + +} From 13ac43f28b9065eacb25c6b910dea3392f1727a7 Mon Sep 17 00:00:00 2001 From: lytscu Date: Wed, 1 Nov 2017 10:56:50 +0800 Subject: [PATCH 2/4] spring mvc-annotation -3.x not work --- .../spring-plugins/mvc-annotation-3.x-plugin/pom.xml | 4 ++-- .../spring-plugins/mvc-annotation-4.x-plugin/pom.xml | 4 ++-- .../v4/define/AbstractControllerInstrumentation.java | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/pom.xml index 6f6b29a55..8f93ee445 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-3.x-plugin/pom.xml @@ -36,13 +36,13 @@ org.springframework spring-core 3.2.18.RELEASE - compile + provided org.springframework spring-webmvc 3.2.18.RELEASE - compile + provided javax.servlet diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/pom.xml index b0d3e3001..112e71fcc 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/pom.xml @@ -36,13 +36,13 @@ org.springframework spring-core 4.3.10.RELEASE - compile + provided org.springframework spring-webmvc 4.3.8.RELEASE - compile + provided javax.servlet diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java index 3e7670fe7..e8259aec3 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/main/java/org/skywalking/apm/plugin/spring/mvc/v4/define/AbstractControllerInstrumentation.java @@ -35,10 +35,10 @@ import static org.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.by * org.springframework.web.bind.annotation.RequestMapping that class has * org.springframework.stereotype.Controller annotation. * - * org.skywalking.apm.plugin.spring.mvc.ControllerConstructorInterceptor set the controller base path to + * org.skywalking.apm.plugin.spring.mvc.v4.ControllerConstructorInterceptor set the controller base path to * dynamic field before execute constructor. * - * org.skywalking.apm.plugin.spring.mvc.RequestMappingMethodInterceptor get the request path from + * org.skywalking.apm.plugin.spring.mvc.v4.RequestMappingMethodInterceptor get the request path from * dynamic field first, if not found, RequestMappingMethodInterceptor generate request path that * combine the path value of current annotation on current method and the base path and set the new path to the dynamic * filed @@ -57,7 +57,7 @@ public abstract class AbstractControllerInstrumentation extends ClassInstanceMet @Override public String getConstructorInterceptor() { - return "org.skywalking.apm.plugin.spring.mvc.ControllerConstructorInterceptor"; + return "org.skywalking.apm.plugin.spring.mvc.v4.ControllerConstructorInterceptor"; } } }; @@ -74,7 +74,7 @@ public abstract class AbstractControllerInstrumentation extends ClassInstanceMet @Override public String getMethodsInterceptor() { - return "org.skywalking.apm.plugin.spring.mvc.RequestMappingMethodInterceptor"; + return "org.skywalking.apm.plugin.spring.mvc.v4.RequestMappingMethodInterceptor"; } @Override @@ -94,7 +94,7 @@ public abstract class AbstractControllerInstrumentation extends ClassInstanceMet @Override public String getMethodsInterceptor() { - return "org.skywalking.apm.plugin.spring.mvc.RestMappingMethodInterceptor"; + return "org.skywalking.apm.plugin.spring.mvc.v4.RestMappingMethodInterceptor"; } @Override From 1d1c81f4b5b27b7c9a73b2727c5ef123e5527f4c Mon Sep 17 00:00:00 2001 From: lytscu Date: Wed, 1 Nov 2017 11:21:26 +0800 Subject: [PATCH 3/4] fix test cases fails --- .../spring/mvc/v4/define/ControllerInstrumentationTest.java | 6 +++--- .../mvc/v4/define/RestControllerInstrumentationTest.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java index 8c9f30828..1d245bb9c 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/ControllerInstrumentationTest.java @@ -52,8 +52,8 @@ public class ControllerInstrumentationTest { public void testGetInstanceMethodsInterceptPoints() throws Throwable { InstanceMethodsInterceptPoint[] methodPoints = controllerInstrumentation.getInstanceMethodsInterceptPoints(); assertThat(methodPoints.length, is(2)); - assertThat(methodPoints[0].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.RequestMappingMethodInterceptor")); - assertThat(methodPoints[1].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.RestMappingMethodInterceptor")); + assertThat(methodPoints[0].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.v4.RequestMappingMethodInterceptor")); + assertThat(methodPoints[1].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.v4.RestMappingMethodInterceptor")); Assert.assertFalse(methodPoints[0].isOverrideArgs()); Assert.assertFalse(methodPoints[1].isOverrideArgs()); @@ -70,7 +70,7 @@ public class ControllerInstrumentationTest { ConstructorInterceptPoint cip = cips[0]; Assert.assertNotNull(cip); - Assert.assertEquals(cip.getConstructorInterceptor(), "org.skywalking.apm.plugin.spring.mvc.ControllerConstructorInterceptor"); + Assert.assertEquals(cip.getConstructorInterceptor(), "org.skywalking.apm.plugin.spring.mvc.v4.ControllerConstructorInterceptor"); Assert.assertTrue(cip.getConstructorMatcher().equals(ElementMatchers.any())); } } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java index 97bf085f2..c67fa6978 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-4.x-plugin/src/test/java/org/skywalking/apm/plugin/spring/mvc/v4/define/RestControllerInstrumentationTest.java @@ -50,8 +50,8 @@ public class RestControllerInstrumentationTest { public void testGetInstanceMethodsInterceptPoints() throws Throwable { InstanceMethodsInterceptPoint[] methodPoints = restControllerInstrumentation.getInstanceMethodsInterceptPoints(); assertThat(methodPoints.length, is(2)); - assertThat(methodPoints[0].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.RequestMappingMethodInterceptor")); - assertThat(methodPoints[1].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.RestMappingMethodInterceptor")); + assertThat(methodPoints[0].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.v4.RequestMappingMethodInterceptor")); + assertThat(methodPoints[1].getMethodsInterceptor(), is("org.skywalking.apm.plugin.spring.mvc.v4.RestMappingMethodInterceptor")); Assert.assertFalse(methodPoints[0].isOverrideArgs()); Assert.assertFalse(methodPoints[1].isOverrideArgs()); From 9946a71ddf7450073ae12473bad321acd09ddddc Mon Sep 17 00:00:00 2001 From: ascrutae Date: Wed, 1 Nov 2017 17:47:51 +0800 Subject: [PATCH 4/4] change mysql plugin module name --- .../ConnectionServiceMethodInterceptor.java | 7 +++- ...DBC42PreparedStatementInstrumentation.java | 36 ------------------ .../PreparedStatementInstrumentation.java | 38 ------------------- .../src/main/resources/skywalking-plugin.def | 6 --- .../pom.xml | 6 +-- .../CreateCallableStatementInterceptor.java | 0 .../CreatePreparedStatementInterceptor.java | 0 .../mysql/CreateStatementInterceptor.java | 0 .../StatementExecuteMethodsInterceptor.java | 7 ++++ .../mysql/define/CallableInstrumentation.java | 10 +++-- .../define/ConnectionInstrumentation.java | 4 +- .../mysql/define/DriverInstrumentation.java | 4 +- .../mysql/define/MultiClassNameMatch.java | 4 +- .../PreparedStatementInstrumentation.java} | 16 ++++++-- .../mysql/define/StatementEnhanceInfos.java | 0 .../define/StatementInstrumentation.java | 11 +++--- .../src/main/resources/skywalking-plugin.def | 5 +++ ...reateCallableStatementInterceptorTest.java | 0 ...reatePreparedStatementInterceptorTest.java | 0 .../mysql/CreateStatementInterceptorTest.java | 0 ...tatementExecuteMethodsInterceptorTest.java | 0 apm-sniffer/apm-sdk-plugin/pom.xml | 2 +- 22 files changed, 52 insertions(+), 104 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/JDBC42PreparedStatementInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java delete mode 100644 apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/resources/skywalking-plugin.def rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/pom.xml (95%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java (88%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java (91%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java (97%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java (91%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java (94%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/AbstractPreparedStatementInstrumentation.java => mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java} (70%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementEnhanceInfos.java (100%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java (86%) create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{mysql-2.x-plugin => mysql-5.x-plugin}/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java (100%) diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java index b3476192a..712934b39 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/ConnectionServiceMethodInterceptor.java @@ -29,8 +29,11 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; /** - * {@link ConnectionServiceMethodInterceptor} create an exit span when the client call the following methods in the - * class that extend {@link java.sql.Connection}. 1. close 2. rollback 3. releaseSavepoint 4. commit + * {@link ConnectionServiceMethodInterceptor} create an exit span when the following methods execute: + * 1. close + * 2. rollback + * 3. releaseSavepoint + * 4. commit * * @author zhangxin */ diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/JDBC42PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/JDBC42PreparedStatementInstrumentation.java deleted file mode 100644 index 04f877fba..000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/JDBC42PreparedStatementInstrumentation.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2017, OpenSkywalking Organization All rights reserved. - * - * Licensed 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. - * - * Project repository: https://github.com/OpenSkywalking/skywalking - */ - -package org.skywalking.apm.plugin.jdbc.mysql.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - -/** - * {@link JDBC42PreparedStatementInstrumentation} intercepts {@link com.mysql.jdbc.JDBC42PreparedStatement} class. - * - * @author zhangxin - */ -public class JDBC42PreparedStatementInstrumentation extends AbstractPreparedStatementInstrumentation { - private static final String ENHANCE_CLASS = "com.mysql.jdbc.JDBC42PreparedStatement"; - - @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); - } -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java deleted file mode 100644 index bf0480f2d..000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2017, OpenSkywalking Organization All rights reserved. - * - * Licensed 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. - * - * Project repository: https://github.com/OpenSkywalking/skywalking - */ - -package org.skywalking.apm.plugin.jdbc.mysql.define; - -import org.skywalking.apm.agent.core.plugin.match.ClassMatch; - -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; - -/** - * {@link JDBC42PreparedStatementInstrumentation} intercepts {@link com.mysql.jdbc.PreparedStatement} class. - * - * @author zhangxin - */ -public class PreparedStatementInstrumentation extends AbstractPreparedStatementInstrumentation { - - private static final String ENHANCE_CLASS = "com.mysql.jdbc.PreparedStatement"; - - @Override protected ClassMatch enhanceClass() { - return byMultiClassMath(ENHANCE_CLASS, "com.mysql.cj.jdbc.PreparedStatement"); - } - -} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/resources/skywalking-plugin.def deleted file mode 100644 index 622dc29d0..000000000 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/resources/skywalking-plugin.def +++ /dev/null @@ -1,6 +0,0 @@ -mysql=org.skywalking.apm.plugin.jdbc.mysql.define.DriverInstrumentation -mysql=org.skywalking.apm.plugin.jdbc.mysql.define.ConnectionInstrumentation -mysql=org.skywalking.apm.plugin.jdbc.mysql.define.CallableInstrumentation -mysql=org.skywalking.apm.plugin.jdbc.mysql.define.PreparedStatementInstrumentation -mysql=org.skywalking.apm.plugin.jdbc.mysql.define.JDBC42PreparedStatementInstrumentation -mysql=org.skywalking.apm.plugin.jdbc.mysql.define.StatementInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/pom.xml similarity index 95% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/pom.xml rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/pom.xml index efcbfa22f..eb232bb10 100755 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/pom.xml @@ -25,10 +25,10 @@ 4.0.0 - apm-mysql-2.x-plugin + apm-mysql-5.x-plugin jar - mysql-2.x-plugin + mysql-5.x-plugin http://maven.apache.org @@ -45,7 +45,7 @@ mysql mysql-connector-java - [2.0.14,6.0.6] + [5.1.22,6.0.6] provided diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java similarity index 88% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java index d8fbd58cd..779ae38b0 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptor.java @@ -41,6 +41,13 @@ public class StatementExecuteMethodsInterceptor implements InstanceMethodsAround MethodInterceptResult result) throws Throwable { StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + /** + * To protected the code occur NullPointException. because mysql execute system sql when constructor method in + * {@link com.mysql.jdbc.ConnectionImpl} class executed. but the interceptor set the connection Info after + * the constructor method executed. + * + * @see org.skywalking.apm.plugin.jdbc.JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object) + */ if (connectInfo != null) { AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java similarity index 91% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java index f0e2fbb6d..4d3152241 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java @@ -26,12 +26,14 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMet import org.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; /** * {@link CallableInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the {@link - * com.mysql.jdbc.CallableStatement} by {@link org.skywalking.apm.plugin.jdbc.mysql.CallableStatementInterceptor}. 1. - * execute
2. executeQuery
3. executeUpdate
+ * com.mysql.jdbc.CallableStatement} by {@link org.skywalking.apm.plugin.jdbc.mysql.CallableStatementInterceptor}: + * 1. execute
+ * 2. executeQuery
+ * 3. executeUpdate
* * @author zhangxin */ @@ -64,6 +66,6 @@ public class CallableInstrumentation extends ClassInstanceMethodsEnhancePluginDe } @Override protected ClassMatch enhanceClass() { - return byMultiClassMath(ENHANCE_CLASS, "com.mysql.jdbc.cj.CallableStatement"); + return byMultiClassMatch(ENHANCE_CLASS, "com.mysql.jdbc.cj.CallableStatement"); } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java similarity index 97% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java index a45048cd1..3ddded5bb 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/ConnectionInstrumentation.java @@ -35,7 +35,7 @@ import static org.skywalking.apm.plugin.jdbc.define.Constants.PREPARE_STATEMENT_ import static org.skywalking.apm.plugin.jdbc.define.Constants.RELEASE_SAVE_POINT_METHOD_NAME; import static org.skywalking.apm.plugin.jdbc.define.Constants.ROLLBACK_METHOD_NAME; import static org.skywalking.apm.plugin.jdbc.define.Constants.SERVICE_METHOD_INTERCEPT_CLASS; -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; /** * {@link ConnectionInstrumentation} intercepts the following methods that the class which extend {@link @@ -115,6 +115,6 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override protected ClassMatch enhanceClass() { - return byMultiClassMath(ENHANCE_CLASS, "com.mysql.cj.jdbc.ConnectionImpl"); + return byMultiClassMatch(ENHANCE_CLASS, "com.mysql.cj.jdbc.ConnectionImpl"); } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java similarity index 91% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java index 25d6ce62f..d8d1a659c 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java @@ -21,7 +21,7 @@ package org.skywalking.apm.plugin.jdbc.mysql.define; import org.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; /** * {@link DriverInstrumentation} presents that skywalking intercepts {@link com.mysql.jdbc.Driver}. @@ -31,6 +31,6 @@ import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.by public class DriverInstrumentation extends AbstractDriverInstrumentation { @Override protected ClassMatch enhanceClass() { - return byMultiClassMath("com.mysql.jdbc.Driver", "com.mysql.cj.jdbc.Driver"); + return byMultiClassMatch("com.mysql.jdbc.Driver", "com.mysql.cj.jdbc.Driver"); } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java similarity index 94% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java index 839b37875..0dbb7eb4a 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java @@ -28,7 +28,7 @@ import org.skywalking.apm.agent.core.plugin.match.IndirectMatch; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * Match multiple classes name with an explicit class name. + * Match class with a given set of classes. * * @author zhangxin */ @@ -61,7 +61,7 @@ public class MultiClassNameMatch implements IndirectMatch { return matchClassNames.contains(typeDescription.getTypeName()); } - public static ClassMatch byMultiClassMath(String... classNames) { + public static ClassMatch byMultiClassMatch(String... classNames) { return new MultiClassNameMatch(classNames); } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/AbstractPreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java similarity index 70% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/AbstractPreparedStatementInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java index bf73036f9..ba83c888e 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/AbstractPreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java @@ -23,12 +23,15 @@ import net.bytebuddy.matcher.ElementMatcher; import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; /** - * {@link AbstractPreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in - * the {@link com.mysql.jdbc.JDBC42PreparedStatement} and {@link com.mysql.jdbc.PreparedStatement} class. + * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the + * {@link com.mysql.jdbc.JDBC42PreparedStatement}, {@link com.mysql.jdbc.PreparedStatement} and {@link + * com.mysql.cj.jdbc.PreparedStatement} class: * 1. execute
* 2. executeQuery
* 3. executeUpdate
@@ -37,9 +40,12 @@ import static net.bytebuddy.matcher.ElementMatchers.named; * * @author zhangxin */ -public abstract class AbstractPreparedStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { +public class PreparedStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; private static final String SERVICE_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; + public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; + public static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[0]; @@ -66,4 +72,8 @@ public abstract class AbstractPreparedStatementInstrumentation extends ClassInst } }; } + + @Override protected ClassMatch enhanceClass() { + return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, MYSQL6_PREPARED_STATEMENT_CLASS_NAME, JDBC42_PREPARED_STATEMENT_CLASS_NAME); + } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementEnhanceInfos.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementEnhanceInfos.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementEnhanceInfos.java diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java similarity index 86% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java index 0a63878ad..bd87bbc14 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java @@ -26,11 +26,11 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMet import org.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMath; +import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; /** - * {@link JDBC42PreparedStatementInstrumentation} intercepts the following methods in the {@link - * com.mysql.jdbc.JDBC42PreparedStatement} class. + * {@link StatementInstrumentation} intercepts the following methods in the {@link + * com.mysql.jdbc.StatementImpl} and {@link com.mysql.cj.jdbc.StatementImpl}class. * 1. execute
* 2. executeQuery
* 3. executeUpdate
@@ -44,8 +44,9 @@ import static org.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.by * @author zhangxin */ public class StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String ENHANCE_CLASS = "com.mysql.jdbc.StatementImpl"; + private static final String STATEMENT_CLASS_NAME = "com.mysql.jdbc.StatementImpl"; private static final String SERVICE_METHOD_INTERCEPTOR = "org.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; + public static final String MYSQL6_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.StatementImpl"; @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[0]; @@ -78,6 +79,6 @@ public class StatementInstrumentation extends ClassInstanceMethodsEnhancePluginD } @Override protected ClassMatch enhanceClass() { - return byMultiClassMath(ENHANCE_CLASS, "com.mysql.cj.jdbc.StatementImpl"); + return byMultiClassMatch(STATEMENT_CLASS_NAME, MYSQL6_STATEMENT_CLASS_NAME); } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..f4f6b4c6e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,5 @@ +mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.DriverInstrumentation +mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.ConnectionInstrumentation +mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.CallableInstrumentation +mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.PreparedStatementInstrumentation +mysql-5.x=org.skywalking.apm.plugin.jdbc.mysql.define.StatementInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateCallableStatementInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreatePreparedStatementInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/CreateStatementInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/mysql-2.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/skywalking/apm/plugin/jdbc/mysql/StatementExecuteMethodsInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 187cddb8f..bae33b837 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -48,7 +48,7 @@ sharding-jdbc-1.5.x-plugin xmemcached-2.x-plugin grpc-1.x-plugin - mysql-2.x-plugin + mysql-5.x-plugin h2-1.x-plugin postgresql-8.x-plugin oracle-10.x-plugin