From 06b809acc23a2324f8f9d832285385e5d358991a Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Mon, 10 Jun 2019 23:00:20 +0800 Subject: [PATCH 01/24] Add config to control tracing sql parameters resolve #2587 --- .../apm/agent/core/conf/Config.java | 8 +++++ .../jdbc/define/StatementEnhanceInfos.java | 14 +++++++++ .../PreparedStatementInstrumentation.java | 29 ++++++++++++------- .../apm/plugin/jdbc/mysql/Constants.java | 4 +++ ...redStatementExecuteMethodsInterceptor.java | 25 +++++++++++++++- .../setup/service-agent/java-agent/README.md | 3 +- 6 files changed, 71 insertions(+), 12 deletions(-) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index a1e4f81dccc3..a1ddbf2991fb 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -205,5 +205,13 @@ public static class SolrJ { */ public static boolean TRACE_OPS_PARAMS = false; } + + public static class MySQL { + /** + * If set to true, the parameters of the sql (typically {@link java.sql.PreparedStatement}) + * would be collected. + */ + public static boolean TRACE_SQL_PARAMETERS = false; + } } } diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java index c75a131b3658..d618e6a4cc51 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java @@ -21,6 +21,10 @@ import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + /** * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and * sql for trace mysql. @@ -31,11 +35,13 @@ public class StatementEnhanceInfos { private ConnectionInfo connectionInfo; private String statementName; private String sql; + private Map parametersKeyedByIndex; public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) { this.connectionInfo = connectionInfo; this.sql = sql; this.statementName = statementName; + this.parametersKeyedByIndex = new TreeMap(); } public ConnectionInfo getConnectionInfo() { @@ -49,4 +55,12 @@ public String getSql() { public String getStatementName() { return statementName; } + + public void setParameter(final int index, final Object parameter) { + parametersKeyedByIndex.put(index, parameter); + } + + public Map getParameters() { + return parametersKeyedByIndex; + } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java index 77670ea053ea..0a2ca92fe3f3 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java @@ -21,6 +21,7 @@ import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; @@ -31,13 +32,13 @@ /** * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the - * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and + * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and * com.mysql.cj.jdbc.PreparedStatement class: - * 1. execute - * 2. executeQuery - * 3. executeUpdate - * 4. executeLargeUpdate - * 5. addBatch + * 1. execute + * 2. executeQuery + * 3. executeUpdate + * 4. executeLargeUpdate + * 5. addBatch * * @author zhangxin */ @@ -55,10 +56,18 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("execute") - .or(named("executeQuery")) - .or(named("executeUpdate")) - .or(named("executeLargeUpdate")); + ElementMatcher.Junction matcher = named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")); + if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { + // TODO: more setter + matcher = matcher + .or(named("setString")) + .or(named("setInt")) + .or(named("setLong")); + } + return matcher; } @Override public String getMethodsInterceptor() { diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java index a22c79b32e58..80dcb147c526 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java @@ -18,6 +18,8 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql; +import org.apache.skywalking.apm.agent.core.context.tag.StringTag; + /** * @author: dingshaocheng */ @@ -29,4 +31,6 @@ public class Constants { public static final String SET_CATALOG_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.SetCatalogInterceptor"; public static final String STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; public static final String DRIVER_CONNECT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.DriverConnectInterceptor"; + + public static final StringTag SQL_PARAMETERS = new StringTag("db.sql.parameters"); } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java index 5af6e98831f4..84004b6585d8 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java @@ -18,6 +18,8 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql; +import com.google.common.base.Joiner; +import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; @@ -29,6 +31,9 @@ import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; import java.lang.reflect.Method; +import java.util.Map; + +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETERS; public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { @@ -38,6 +43,16 @@ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] MethodInterceptResult result) throws Throwable { StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + + final String methodName = method.getName(); + final boolean traceSqlParameters = Config.Plugin.MySQL.TRACE_SQL_PARAMETERS; + + if (traceSqlParameters && methodName.startsWith("set")) { + final int index = (Integer) allArguments[0]; + final Object parameter = allArguments[1]; + cacheObject.setParameter(index, parameter); + } + /** * For avoid NPE. In this particular case, Execute sql inside the {@link com.mysql.jdbc.ConnectionImpl} constructor, * before the interceptor sets the connectionInfo. @@ -46,12 +61,20 @@ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] */ if (connectInfo != null) { - AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, methodName, 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()); + if (traceSqlParameters) { + final Map parametersKeyedByIndex = cacheObject.getParameters(); + if (!parametersKeyedByIndex.isEmpty()) { + final String parameters = Joiner.on(",").join(parametersKeyedByIndex.values()); + SQL_PARAMETERS.set(span, parameters); + } + } + SpanLayer.asDB(span); } } diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md index 9b727d5d2a24..4f81cdd9ba2e 100644 --- a/docs/en/setup/service-agent/java-agent/README.md +++ b/docs/en/setup/service-agent/java-agent/README.md @@ -84,9 +84,10 @@ property key | Description | Default | `plugin.toolit.use_qualified_name_as_operation_name`|If true, the fully qualified method name will be used as the operation name instead of the given operation name, default is false.|`false`| `plugin.solrj.trace_statement`|If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false.|`false`| `plugin.solrj.trace_ops_params`|If true, trace all the operation parameters in Solr request, default is false.|`false`| +`plugin.mysql.trace_sql_parameters`|If set to true, the parameters of the sql (typically `java.sql.PreparedStatement`) would be collected.|`false`| ## Optional Plugins -Java agent plugins are all pluggable. Optional plugins could be provided in `optional-plugins` folder under agent or 3rd party repositores. +Java agent plugins are all pluggable. Optional plugins could be provided in `optional-plugins` folder under agent or 3rd party repositories. For using these plugins, you need to put the target plugin jar file into `/plugins`. Now, we have the following known optional plugins. From 7f373ea51c96ec03be88cf35fb14a8142879b6ea Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Mon, 10 Jun 2019 23:12:27 +0800 Subject: [PATCH 02/24] Fix codestyle --- .../jdbc/define/StatementEnhanceInfos.java | 1 - .../PreparedStatementInstrumentation.java | 27 ++++---- .../apm/plugin/jdbc/mysql/Constants.java | 66 +++++++++++++++++++ ...redStatementExecuteMethodsInterceptor.java | 27 +++++++- 4 files changed, 106 insertions(+), 15 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java index d618e6a4cc51..835eeb21f0a8 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java @@ -21,7 +21,6 @@ import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import java.util.HashMap; import java.util.Map; import java.util.TreeMap; diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java index 0a2ca92fe3f3..0922e1c9f598 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java @@ -29,6 +29,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; /** * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the @@ -56,18 +58,19 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - ElementMatcher.Junction matcher = named("execute") - .or(named("executeQuery")) - .or(named("executeUpdate")) - .or(named("executeLargeUpdate")); - if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { - // TODO: more setter - matcher = matcher - .or(named("setString")) - .or(named("setInt")) - .or(named("setLong")); - } - return matcher; + ElementMatcher.Junction matcher = named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")); + if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { + for (String setter : PS_SETTERS) { + matcher = matcher.or(named(setter)); + } + for (String setter : PS_IGNORED_SETTERS) { + matcher = matcher.or(named(setter)); + } + } + return matcher; } @Override public String getMethodsInterceptor() { diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java index 80dcb147c526..e882093cf6a9 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java @@ -18,8 +18,18 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql; +import com.google.common.collect.Sets; import org.apache.skywalking.apm.agent.core.context.tag.StringTag; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + /** * @author: dingshaocheng */ @@ -33,4 +43,60 @@ public class Constants { public static final String DRIVER_CONNECT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.DriverConnectInterceptor"; public static final StringTag SQL_PARAMETERS = new StringTag("db.sql.parameters"); + public static final String SQL_PARAMETER_PLACE_HOLDER = "?"; + public static final Set PS_SETTERS = Sets.newHashSet( + "setArray", + "setBigDecimal", + "setBoolean", + "setByte", + "setDate", + "setDouble", + "setFloat", + "setInt", + "setLong", + "setNString", + "setNull", + "setObject", + "setRowId", + "setShort", + "setString", + "setTime", + "setTimestamp", + "setURL" + ); + public static final Set> DISPLAYABLE_TYPES = new HashSet>(Arrays.asList( + BigDecimal.class, + Boolean.class, + boolean.class, + Byte.class, + byte.class, + Date.class, + Double.class, + double.class, + Float.class, + float.class, + Integer.class, + int.class, + Long.class, + long.class, + String.class, + Short.class, + short.class, + Time.class, + Timestamp.class, + URL.class + )); + public static final Set PS_IGNORED_SETTERS = Sets.newHashSet( + "setAsciiStream", + "setBinaryStream", + "setBlob", + "setBytes", + "setCharacterStream", + "setClob", + "setNCharacterStream", + "setNClob", + "setRef", + "setSQLXML", + "setUnicodeStream" + ); } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java index 84004b6585d8..28531f380d2f 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java @@ -33,7 +33,11 @@ import java.lang.reflect.Method; import java.util.Map; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.DISPLAYABLE_TYPES; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETERS; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETER_PLACE_HOLDER; public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { @@ -47,9 +51,9 @@ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] final String methodName = method.getName(); final boolean traceSqlParameters = Config.Plugin.MySQL.TRACE_SQL_PARAMETERS; - if (traceSqlParameters && methodName.startsWith("set")) { + if (traceSqlParameters && (PS_SETTERS.contains(methodName) || PS_IGNORED_SETTERS.contains(methodName))) { final int index = (Integer) allArguments[0]; - final Object parameter = allArguments[1]; + final Object parameter = getDisplayedParameter(method, argumentsTypes, allArguments); cacheObject.setParameter(index, parameter); } @@ -101,4 +105,23 @@ public final Object afterMethod(EnhancedInstance objInst, Method method, Object[ private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; } + + private Object getDisplayedParameter(final Method method, final Class[] argumentTypes, final Object[] allArguments) { + final String methodName = method.getName(); + if ("setNull".equals(methodName)) { + return "null"; + } + if ("setObject".equals(methodName)) { + final Object parameter = allArguments[0]; + final Class parameterType = argumentTypes[1]; + + if (DISPLAYABLE_TYPES.contains(parameterType)) { + return parameter; + } + } + if (PS_SETTERS.contains(methodName)) { + return allArguments[1]; + } + return SQL_PARAMETER_PLACE_HOLDER; + } } From 0f2529a5b8427b9ef0861d30acc2baa1fab459c5 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Wed, 12 Jun 2019 11:59:00 +0800 Subject: [PATCH 03/24] Trigger CI From c51b90828637444ee6639bf3993e342f45646d68 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 00:24:34 +0800 Subject: [PATCH 04/24] Remove dependencies --- .gitmodules | 9 +- .../common/AtomicRangeInteger.java | 12 +- .../common/AtomicRangeIntegerTest.java | 154 ++++++++++++ apm-dist/release-docs/LICENSE | 5 +- apm-dist/release-docs/NOTICE | 25 +- .../jdbc/JDBCPrepareStatementInterceptor.java | 9 +- .../apm/plugin/jdbc/define/Constants.java | 1 + .../jdbc/define/StatementEnhanceInfos.java | 29 ++- .../apm/plugin/jdbc/mysql/Constants.java | 11 +- ...redStatementExecuteMethodsInterceptor.java | 47 ++-- .../apm/plugin/ArbitrarySetTest.java | 238 ++++++++++++++++++ apm-sniffer/config/agent.config | 2 + docs/en/setup/backend/backend-alarm.md | 38 ++- pom.xml | 14 +- 14 files changed, 528 insertions(+), 66 deletions(-) create mode 100644 apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java diff --git a/.gitmodules b/.gitmodules index 72f71a2c2c31..4a4d5c3ae69e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,12 @@ [submodule "apm-protocol/apm-network/src/main/proto"] path = apm-protocol/apm-network/src/main/proto - url = https://github.com/apache/skywalking-data-collect-protocol.git + url = file:///data/developer/git/java/skywalking/apm-protocol/apm-network/src/main/proto + #url = https://github.com/apache/skywalking-data-collect-protocol.git [submodule "oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol"] path = oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol - url = https://github.com/apache/skywalking-query-protocol.git + url = file:///data/developer/git/java/skywalking/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol + #url = https://github.com/apache/skywalking-query-protocol.git [submodule "skywalking-ui"] path = skywalking-ui - url = https://github.com/apache/skywalking-rocketbot-ui.git + #url = https://github.com/apache/skywalking-rocketbot-ui.git + url = file:///data/developer/git/java/skywalking/skywalking-ui diff --git a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java index 6074303521c0..ba3667d5f143 100644 --- a/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java +++ b/apm-commons/apm-datacarrier/src/main/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeInteger.java @@ -38,15 +38,15 @@ public AtomicRangeInteger(int startValue, int maxValue) { } public final int getAndIncrement() { - int current; int next; do { - current = this.value.get(); - next = current >= this.endValue ? this.startValue : current + 1; - } - while (!this.value.compareAndSet(current, next)); + next = this.value.incrementAndGet(); + if (next > endValue && this.value.compareAndSet(next, startValue)) { + return endValue; + } + } while (next > endValue); - return current; + return next - 1; } public final int get() { diff --git a/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java index 30fd2113adbe..fb53f3147415 100644 --- a/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java +++ b/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/common/AtomicRangeIntegerTest.java @@ -21,11 +21,67 @@ import org.junit.Assert; import org.junit.Test; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; +import java.io.Serializable; +import java.util.concurrent.atomic.AtomicInteger; /** * Created by xin on 2017/7/14. */ public class AtomicRangeIntegerTest { + + static class AtomicRangeIntegerOri extends Number implements Serializable { + private static final long serialVersionUID = -4099792402691141643L; + private AtomicInteger value; + private int startValue; + private int endValue; + + public AtomicRangeIntegerOri(int startValue, int maxValue) { + this.value = new AtomicInteger(startValue); + this.startValue = startValue; + this.endValue = maxValue - 1; + } + + public final int getAndIncrement() { + int current; + int next; + do { + current = this.value.get(); + next = current >= this.endValue ? this.startValue : current + 1; + } + while (!this.value.compareAndSet(current, next)); + + return current; + } + + public final int get() { + return this.value.get(); + } + + public int intValue() { + return this.value.intValue(); + } + + public long longValue() { + return this.value.longValue(); + } + + public float floatValue() { + return this.value.floatValue(); + } + + public double doubleValue() { + return this.value.doubleValue(); + } + } + + private static AtomicRangeInteger ATOMIC_NEW = new AtomicRangeInteger(0, 100); + private static AtomicRangeIntegerOri ATOMIC_ORI = new AtomicRangeIntegerOri(0, 100); + @Test public void testGetAndIncrement() { AtomicRangeInteger atomicI = new AtomicRangeInteger(0, 10); @@ -39,4 +95,102 @@ public void testGetAndIncrement() { Assert.assertEquals(1, (int)atomicI.floatValue()); Assert.assertEquals(1, (int)atomicI.doubleValue()); } + + @Test + @Benchmark + public void testOriGetAndIncrementPerformance() { + ATOMIC_ORI.getAndIncrement(); + } + + @Test + @Benchmark + public void testNewGetAndIncrementPerformance() { + ATOMIC_NEW.getAndIncrement(); + } + + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder() + .include(AtomicRangeIntegerTest.class.getSimpleName()) + .forks(1) + .warmupIterations(3) + .threads(128) + .syncIterations(false) + .output("/tmp/jmh.log") + .measurementIterations(5) + .build(); + + new Runner(opt).run(); + } + + /** + * # JMH version: 1.21 + * # VM version: JDK 1.8.0_111, Java HotSpot(TM) 64-Bit Server VM, 25.111-b14 + * # VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre/bin/java + * # VM options: -Dfile.encoding=UTF-8 + * # Warmup: 3 iterations, 10 s each + * # Measurement: 5 iterations, 10 s each + * # Timeout: 10 min per iteration + * # Threads: 128 threads, ***WARNING: Synchronize iterations are disabled!*** + * # Benchmark mode: Throughput, ops/time + * # Benchmark: org.apache.skywalking.apm.commons.datacarrier.common.AtomicRangeIntegerTest.testNewGetAndIncrementPerformance + * + * # Run progress: 0.00% complete, ETA 00:02:40 + * # Fork: 1 of 1 + * # Warmup Iteration 1: 41358475.014 ops/s + * # Warmup Iteration 2: 40973232.064 ops/s + * # Warmup Iteration 3: 41310422.853 ops/s + * Iteration 1: 41557782.370 ops/s + * Iteration 2: 42723032.686 ops/s + * Iteration 3: 41957321.407 ops/s + * Iteration 4: 40708422.580 ops/s + * Iteration 5: 40424870.574 ops/s + * + * + * Result "org.apache.skywalking.apm.commons.datacarrier.common.AtomicRangeIntegerTest.testNewGetAndIncrementPerformance": + * 41474285.923 ±(99.9%) 3595500.827 ops/s [Average] + * (min, avg, max) = (40424870.574, 41474285.923, 42723032.686), stdev = 933740.147 + * CI (99.9%): [37878785.096, 45069786.751] (assumes normal distribution) + * + * + * # JMH version: 1.21 + * # VM version: JDK 1.8.0_111, Java HotSpot(TM) 64-Bit Server VM, 25.111-b14 + * # VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre/bin/java + * # VM options: -Dfile.encoding=UTF-8 + * # Warmup: 3 iterations, 10 s each + * # Measurement: 5 iterations, 10 s each + * # Timeout: 10 min per iteration + * # Threads: 128 threads, ***WARNING: Synchronize iterations are disabled!*** + * # Benchmark mode: Throughput, ops/time + * # Benchmark: org.apache.skywalking.apm.commons.datacarrier.common.AtomicRangeIntegerTest.testOriGetAndIncrementPerformance + * + * # Run progress: 50.00% complete, ETA 00:01:25 + * # Fork: 1 of 1 + * # Warmup Iteration 1: 14169937.124 ops/s + * # Warmup Iteration 2: 14087015.239 ops/s + * # Warmup Iteration 3: 13955313.979 ops/s + * Iteration 1: 13984516.590 ops/s + * Iteration 2: 13913174.492 ops/s + * Iteration 3: 13824113.805 ops/s + * Iteration 4: 14886990.831 ops/s + * Iteration 5: 14388283.816 ops/s + * + * + * Result "org.apache.skywalking.apm.commons.datacarrier.common.AtomicRangeIntegerTest.testOriGetAndIncrementPerformance": + * 14199415.907 ±(99.9%) 1697559.657 ops/s [Average] + * (min, avg, max) = (13824113.805, 14199415.907, 14886990.831), stdev = 440850.852 + * CI (99.9%): [12501856.250, 15896975.564] (assumes normal distribution) + * + * + * # Run complete. Total time: 00:02:51 + * + * REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on + * why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial + * experiments, perform baseline and negative tests that provide experimental control, make sure + * the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts. + * Do not assume the numbers tell you what you want them to tell. + * + * Benchmark Mode Cnt Score Error Units + * AtomicRangeIntegerTest.testNewGetAndIncrementPerformance thrpt 5 41474285.923 ± 3595500.827 ops/s + * AtomicRangeIntegerTest.testOriGetAndIncrementPerformance thrpt 5 14199415.907 ± 1697559.657 ops/s + */ } diff --git a/apm-dist/release-docs/LICENSE b/apm-dist/release-docs/LICENSE index f8c1911e610f..5b58eea329bf 100644 --- a/apm-dist/release-docs/LICENSE +++ b/apm-dist/release-docs/LICENSE @@ -250,6 +250,7 @@ The text of each license is the standard Apache 2.0 license. Eclipse (Jetty) 3.3.6: https://www.eclipse.org/jetty/ , Apache 2.0 and Eclipse Public License 1.0 SnakeYAML 1.18: http://www.snakeyaml.org , Apache 2.0 Joda-Time 2.9.9: http://www.joda.org/joda-time/ , Apache 2.0 + Joda-Convert 1.2: http://www.joda.org/joda-convert/ , Apache 2.0 Spring Framework 4.3.14.RELEASE: https://github.com/spring-projects/spring-framework, Apache 2.0 Spring Boot 1.5.10: https://spring.io/, Apache 2.0 Spring Cloud Config 1.4.1: https://github.com/spring-cloud/spring-cloud-config, Apache-2.0 @@ -267,6 +268,7 @@ The text of each license is the standard Apache 2.0 license. Apache: commons-collections 3.2.2: https://github.com/apache/commons-collections, Apache 2.0 Apache: commons-configuration 1.8: https://github.com/apache/commons-configuration, Apache 2.0 Apache: commons-io 2.4: https://github.com/apache/commons-io, Apache 2.0 + Apache: commons-compress 1.18: https://github.com/apache/commons-compress, Apache 2.0 Apache: tomcat 8.5.27: https://github.com/apache/tomcat/tree/trunk, Apache 2.0 netty 5.5.0: https://github.com/netty/netty/blob/4.1/LICENSE.txt, Apache 2.0 annotations 13.0: http://www.jetbrains.org, Apache 2.0 @@ -302,7 +304,7 @@ The text of each license is the standard Apache 2.0 license. HikariCP 3.1.0: https://github.com/brettwooldridge/HikariCP, Apache 2.0 zipkin 2.9.1: https://github.com/openzipkin/zipkin, Apache 2.0 sharding-jdbc-core 2.0.3: https://github.com/sharding-sphere/sharding-sphere, Apache 2.0 - kubernetes-client 2.0.0: https://github.com/kubernetes-client/java, Apache 2.0 + kubernetes-client 4.0.0: https://github.com/kubernetes-client/java, Apache 2.0 proto files from istio/istio: https://github.com/istio/istio Apache 2.0 proto files from istio/api: https://github.com/istio/api Apache 2.0 consul-client 1.2.6: https://github.com/rickfast/consul-client, Apache 2.0 @@ -315,6 +317,7 @@ The text of each license is the standard Apache 2.0 license. proto files from prometheus/client_model: https://github.com/prometheus/client_model Apache 2.0 proto files from lyft/protoc-gen-validate: https://github.com/lyft/protoc-gen-validate Apache 2.0 proto files from gogo/googleapis: https://github.com/gogo/googleapis Apache 2.0 + sundrio 0.9.2: https://github.com/sundrio/sundrio Apache 2.0 ======================================================================== MIT licenses diff --git a/apm-dist/release-docs/NOTICE b/apm-dist/release-docs/NOTICE index 60a4f4552ff6..3f18b860e13c 100644 --- a/apm-dist/release-docs/NOTICE +++ b/apm-dist/release-docs/NOTICE @@ -216,6 +216,29 @@ Joda.org (http://www.joda.org/). ======================================================================== +Joda Convert +Copyright 2010-present Stephen Colebourne + +This product includes software developed by +Joda.org (https://www.joda.org/). + + +Joda-Convert includes code from Google Guava, which is licensed as follows: + +Copyright (C) 2011 The Guava Authors + +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 + +https://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. + +======================================================================== + netty NOTICE ======================================================================== @@ -868,4 +891,4 @@ Also, please refer to each LICENSE..txt file, which is located in the 'license' directory of the distribution file, for the license terms of the components that this product depends on. ------- \ No newline at end of file +------ diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java index 12372d1e2862..a68df0f25c06 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java @@ -19,14 +19,15 @@ package org.apache.skywalking.apm.plugin.jdbc; -import java.lang.reflect.Method; -import java.sql.Connection; -import java.sql.PreparedStatement; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; -import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; + +import java.lang.reflect.Method; +import java.sql.Connection; +import java.sql.PreparedStatement; /** * {@link JDBCPrepareStatementInterceptor} return {@link SWPreparedStatement} instance that wrapper the real diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java index 895a5cacae68..a14c8cedef53 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java @@ -42,4 +42,5 @@ public class Constants { public static final String RELEASE_SAVE_POINT_METHOD_NAME = "releaseSavepoint"; + public static final Object PARAMETER_PLACEHOLDER = new Object(); } diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java index 835eeb21f0a8..c6643e3d3ed1 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java @@ -21,8 +21,9 @@ import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import java.util.Map; -import java.util.TreeMap; +import java.util.Arrays; + +import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PARAMETER_PLACEHOLDER; /** * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and @@ -34,13 +35,12 @@ public class StatementEnhanceInfos { private ConnectionInfo connectionInfo; private String statementName; private String sql; - private Map parametersKeyedByIndex; + private Object[] parameters; public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) { this.connectionInfo = connectionInfo; this.sql = sql; this.statementName = statementName; - this.parametersKeyedByIndex = new TreeMap(); } public ConnectionInfo getConnectionInfo() { @@ -55,11 +55,24 @@ public String getStatementName() { return statementName; } - public void setParameter(final int index, final Object parameter) { - parametersKeyedByIndex.put(index, parameter); + public void setParameter(int index, final Object parameter) { + index--; // start from 1 + if (parameters == null) { + parameters = new Object[20]; + Arrays.fill(parameters, PARAMETER_PLACEHOLDER); + } + int length = parameters.length; + if (index >= length) { + int newSize = Math.max(index + 1, length * 2); + Object[] newParameters = new Object[newSize]; + System.arraycopy(parameters, 0, newParameters, 0, length); + Arrays.fill(newParameters, length, newSize, PARAMETER_PLACEHOLDER); + parameters = newParameters; + } + parameters[index] = parameter; } - public Map getParameters() { - return parametersKeyedByIndex; + public Object[] getParameters() { + return parameters; } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java index e882093cf6a9..067c06c3ea40 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java @@ -18,7 +18,6 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql; -import com.google.common.collect.Sets; import org.apache.skywalking.apm.agent.core.context.tag.StringTag; import java.math.BigDecimal; @@ -43,8 +42,8 @@ public class Constants { public static final String DRIVER_CONNECT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.DriverConnectInterceptor"; public static final StringTag SQL_PARAMETERS = new StringTag("db.sql.parameters"); - public static final String SQL_PARAMETER_PLACE_HOLDER = "?"; - public static final Set PS_SETTERS = Sets.newHashSet( + public static final String SQL_PARAMETER_PLACEHOLDER = "?"; + public static final Set PS_SETTERS = new HashSet(Arrays.asList( "setArray", "setBigDecimal", "setBoolean", @@ -63,7 +62,7 @@ public class Constants { "setTime", "setTimestamp", "setURL" - ); + )); public static final Set> DISPLAYABLE_TYPES = new HashSet>(Arrays.asList( BigDecimal.class, Boolean.class, @@ -86,7 +85,7 @@ public class Constants { Timestamp.class, URL.class )); - public static final Set PS_IGNORED_SETTERS = Sets.newHashSet( + public static final Set PS_IGNORED_SETTERS = new HashSet(Arrays.asList( "setAsciiStream", "setBinaryStream", "setBlob", @@ -98,5 +97,5 @@ public class Constants { "setRef", "setSQLXML", "setUnicodeStream" - ); + )); } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java index df494c8fafaa..e2d0b6c5b71d 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java @@ -18,8 +18,6 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql; -import com.google.common.base.Ascii; -import com.google.gson.Gson; import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; @@ -32,17 +30,15 @@ import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; import java.lang.reflect.Method; -import java.util.Map; +import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PARAMETER_PLACEHOLDER; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.DISPLAYABLE_TYPES; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETER_PLACE_HOLDER; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETER_PLACEHOLDER; public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { - private final Gson gson = new Gson(); - @Override public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, @@ -51,9 +47,8 @@ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); final String methodName = method.getName(); - final boolean traceSqlParameters = Config.Plugin.MySQL.TRACE_SQL_PARAMETERS; - if (traceSqlParameters && (PS_SETTERS.contains(methodName) || PS_IGNORED_SETTERS.contains(methodName))) { + if (PS_SETTERS.contains(methodName) || PS_IGNORED_SETTERS.contains(methodName)) { final int index = (Integer) allArguments[0]; final Object parameter = getDisplayedParameter(method, argumentsTypes, allArguments); cacheObject.setParameter(index, parameter); @@ -73,15 +68,15 @@ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] Tags.DB_STATEMENT.set(span, cacheObject.getSql()); span.setComponent(connectInfo.getComponent()); - if (traceSqlParameters) { - final Map parametersKeyedByIndex = cacheObject.getParameters(); - if (!parametersKeyedByIndex.isEmpty()) { - String parameters = gson.toJson(parametersKeyedByIndex.values()); + if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { + final Object[] parameters = cacheObject.getParameters(); + if (parameters != null && parameters.length > 0) { + String parameterString = buildParameterString(parameters); int sqlParametersMaxLength = Config.Plugin.MySQL.SQL_PARAMETERS_MAX_LENGTH; - if (sqlParametersMaxLength > 0) { - parameters = Ascii.truncate(parameters, sqlParametersMaxLength, "..."); + if (sqlParametersMaxLength > 0 && parameterString.length() > sqlParametersMaxLength) { + parameterString = parameterString.substring(0, sqlParametersMaxLength) + "..."; } - SQL_PARAMETERS.set(span, parameters); + SQL_PARAMETERS.set(span, parameterString); } } @@ -126,10 +121,26 @@ private Object getDisplayedParameter(final Method method, final Class[] argum if (DISPLAYABLE_TYPES.contains(parameterType)) { return parameter; } - } - if (PS_SETTERS.contains(methodName)) { + } else if (PS_SETTERS.contains(methodName)) { return allArguments[1]; } - return SQL_PARAMETER_PLACE_HOLDER; + return SQL_PARAMETER_PLACEHOLDER; + } + + private String buildParameterString(Object[] parameters) { + String parameterString = "["; + boolean first = true; + for (Object parameter : parameters) { + if (parameter == PARAMETER_PLACEHOLDER) { + break; + } + if (!first) { + parameterString += ","; + } + parameterString += parameter; + first = false; + } + parameterString += "]"; + return parameterString; } } diff --git a/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java new file mode 100644 index 000000000000..682042827542 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java @@ -0,0 +1,238 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; +import java.util.concurrent.TimeUnit; + +/** + * # JMH version: 1.21 + * # VM version: JDK 10.0.1, Java HotSpot(TM) 64-Bit Server VM, 10.0.1+10 + * # VM invoker: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java + * # VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50729:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 + * # Warmup: 4 iterations, 10 s each + * # Measurement: 5 iterations, 10 s each + * # Timeout: 10 min per iteration + * # Threads: 1 thread, will synchronize iterations + * # Benchmark mode: Throughput, ops/time + * # Benchmark: org.apache.skywalking.apm.plugin.ArbitrarySetTest.array + *

+ * # Run progress: 0.00% complete, ETA 00:09:00 + * # Fork: 1 of 2 + * # Warmup Iteration 1: 1227.556 ops/ms + * # Warmup Iteration 2: 1710.387 ops/ms + * # Warmup Iteration 3: 1692.754 ops/ms + * # Warmup Iteration 4: 1779.140 ops/ms + * Iteration 1: 1833.746 ops/ms + * Iteration 2: 1862.485 ops/ms + * Iteration 3: 1827.150 ops/ms + * Iteration 4: 1693.042 ops/ms + * Iteration 5: 1643.173 ops/ms + *

+ * # Run progress: 16.67% complete, ETA 00:07:39 + * # Fork: 2 of 2 + * # Warmup Iteration 1: 1455.851 ops/ms + * # Warmup Iteration 2: 1629.368 ops/ms + * # Warmup Iteration 3: 1729.879 ops/ms + * # Warmup Iteration 4: 1790.962 ops/ms + * Iteration 1: 1681.082 ops/ms + * Iteration 2: 1557.253 ops/ms + * Iteration 3: 1510.295 ops/ms + * Iteration 4: 1559.166 ops/ms + * Iteration 5: 1615.465 ops/ms + *

+ *

+ * Result "org.apache.skywalking.apm.plugin.ArbitrarySetTest.array": + * 1678.286 ±(99.9%) 190.386 ops/ms [Average] + * (min, avg, max) = (1510.295, 1678.286, 1862.485), stdev = 125.929 + * CI (99.9%): [1487.900, 1868.672] (assumes normal distribution) + *

+ *

+ * # JMH version: 1.21 + * # VM version: JDK 10.0.1, Java HotSpot(TM) 64-Bit Server VM, 10.0.1+10 + * # VM invoker: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java + * # VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50729:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 + * # Warmup: 4 iterations, 10 s each + * # Measurement: 5 iterations, 10 s each + * # Timeout: 10 min per iteration + * # Threads: 1 thread, will synchronize iterations + * # Benchmark mode: Throughput, ops/time + * # Benchmark: org.apache.skywalking.apm.plugin.ArbitrarySetTest.arrayList + *

+ * # Run progress: 33.33% complete, ETA 00:06:05 + * # Fork: 1 of 2 + * # Warmup Iteration 1: 575.365 ops/ms + * # Warmup Iteration 2: 627.217 ops/ms + * # Warmup Iteration 3: 611.638 ops/ms + * # Warmup Iteration 4: 584.694 ops/ms + * Iteration 1: 593.597 ops/ms + * Iteration 2: 582.952 ops/ms + * Iteration 3: 586.201 ops/ms + * Iteration 4: 668.791 ops/ms + * Iteration 5: 668.208 ops/ms + *

+ * # Run progress: 50.00% complete, ETA 00:04:34 + * # Fork: 2 of 2 + * # Warmup Iteration 1: 567.132 ops/ms + * # Warmup Iteration 2: 619.129 ops/ms + * # Warmup Iteration 3: 719.696 ops/ms + * # Warmup Iteration 4: 734.769 ops/ms + * Iteration 1: 731.429 ops/ms + * Iteration 2: 684.019 ops/ms + * Iteration 3: 645.475 ops/ms + * Iteration 4: 634.259 ops/ms + * Iteration 5: 681.604 ops/ms + *

+ *

+ * Result "org.apache.skywalking.apm.plugin.ArbitrarySetTest.arrayList": + * 647.654 ±(99.9%) 73.776 ops/ms [Average] + * (min, avg, max) = (582.952, 647.654, 731.429), stdev = 48.799 + * CI (99.9%): [573.877, 721.430] (assumes normal distribution) + *

+ *

+ * # JMH version: 1.21 + * # VM version: JDK 10.0.1, Java HotSpot(TM) 64-Bit Server VM, 10.0.1+10 + * # VM invoker: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java + * # VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50729:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 + * # Warmup: 4 iterations, 10 s each + * # Measurement: 5 iterations, 10 s each + * # Timeout: 10 min per iteration + * # Threads: 1 thread, will synchronize iterations + * # Benchmark mode: Throughput, ops/time + * # Benchmark: org.apache.skywalking.apm.plugin.ArbitrarySetTest.treeMap + *

+ * # Run progress: 66.67% complete, ETA 00:03:02 + * # Fork: 1 of 2 + * # Warmup Iteration 1: 149.772 ops/ms + * # Warmup Iteration 2: 164.658 ops/ms + * # Warmup Iteration 3: 181.832 ops/ms + * # Warmup Iteration 4: 181.535 ops/ms + * Iteration 1: 178.571 ops/ms + * Iteration 2: 135.320 ops/ms + * Iteration 3: 152.644 ops/ms + * Iteration 4: 166.896 ops/ms + * Iteration 5: 167.542 ops/ms + *

+ * # Run progress: 83.33% complete, ETA 00:01:31 + * # Fork: 2 of 2 + * # Warmup Iteration 1: 171.791 ops/ms + * # Warmup Iteration 2: 178.640 ops/ms + * # Warmup Iteration 3: 167.416 ops/ms + * # Warmup Iteration 4: 171.610 ops/ms + * Iteration 1: 179.966 ops/ms + * Iteration 2: 187.318 ops/ms + * Iteration 3: 183.934 ops/ms + * Iteration 4: 181.388 ops/ms + * Iteration 5: 186.286 ops/ms + *

+ *

+ * Result "org.apache.skywalking.apm.plugin.ArbitrarySetTest.treeMap": + * 171.986 ±(99.9%) 25.408 ops/ms [Average] + * (min, avg, max) = (135.320, 171.986, 187.318), stdev = 16.806 + * CI (99.9%): [146.578, 197.394] (assumes normal distribution) + *

+ *

+ * # Run complete. Total time: 00:09:07 + *

+ * REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on + * why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial + * experiments, perform baseline and negative tests that provide experimental control, make sure + * the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts. + * Do not assume the numbers tell you what you want them to tell. + *

+ * Benchmark Mode Cnt Score Error Units + * ArbitrarySetTest.array thrpt 10 1678.286 ± 190.386 ops/ms + * ArbitrarySetTest.arrayList thrpt 10 647.654 ± 73.776 ops/ms + * ArbitrarySetTest.treeMap thrpt 10 171.986 ± 25.408 ops/ms + * + * @author kezhenxu94 + */ +@BenchmarkMode(Mode.Throughput) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Thread) +@Fork(2) +@Warmup(iterations = 4) +@Measurement(iterations = 5) +public class ArbitrarySetTest { + private static final Object PLACEHOLDER = new Object(); + + @Benchmark + public void arrayList() { + ArrayList list = new ArrayList(Collections.nCopies(20, PLACEHOLDER)); + for (int i = 0; i < 100; i++) { + int oldSize = list.size(); + if (i >= oldSize) { + int newSize = Math.max(oldSize * 2, i); + ArrayList newList = new ArrayList(newSize); + newList.addAll(list); + newList.addAll(oldSize, Collections.nCopies(newSize - oldSize, PLACEHOLDER)); + list = newList; + } + list.set(i, i); + } + } + + @Benchmark + public void array() { + Object[] array = new Object[20]; + Arrays.fill(array, PLACEHOLDER); + for (int i = 1; i <= 100; i++) { + int length = array.length; + if (i >= length) { + Object[] newArray = new Object[Math.max(i, length * 2)]; + System.arraycopy(array, 0, newArray, 0, length); + array = newArray; + } + array[i] = i; + } + } + + @Benchmark + public void treeMap() { + final Map treeMap = new TreeMap(); + for (int i = 0; i < 100; i++) { + treeMap.put(i, i); + } + } + + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.MICROSECONDS) + public static void main(String[] args) throws RunnerException { + Options options = new OptionsBuilder().include(ArbitrarySetTest.class.getSimpleName()).build(); + new Runner(options).run(); + } +} diff --git a/apm-sniffer/config/agent.config b/apm-sniffer/config/agent.config index 327d9ef0f77a..a2f8c310b546 100644 --- a/apm-sniffer/config/agent.config +++ b/apm-sniffer/config/agent.config @@ -43,3 +43,5 @@ collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800} # Logging level logging.level=${SW_LOGGING_LEVEL:DEBUG} + +plugin.mysql.trace_sql_parameters=true diff --git a/docs/en/setup/backend/backend-alarm.md b/docs/en/setup/backend/backend-alarm.md index 053429d2cf61..7fc6459db055 100644 --- a/docs/en/setup/backend/backend-alarm.md +++ b/docs/en/setup/backend/backend-alarm.md @@ -1,8 +1,8 @@ # Alarm Alarm core is driven a collection of rules, which are defined in `config/alarm-settings.yml`. There are two parts in alarm rule definition. -1. Alarm rules. They define how metrics alarm should be triggered, what conditions should be considered. -1. Webhooks. The list of web service endpoint, which should be called after the alarm is triggered. +1. [Alarm rules](#rules). They define how metrics alarm should be triggered, what conditions should be considered. +1. [Webhooks](#webhook). The list of web service endpoint, which should be called after the alarm is triggered. ## Rules Alarm rule is constituted by following keys @@ -49,18 +49,44 @@ rules: count: 4 ``` -## Default alarm rules +### Default alarm rules We provided a default `alarm-setting.yml` in our distribution only for convenience, which including following rules 1. Service average response time over 1s in last 3 minutes. 1. Service success rate lower than 80% in last 2 minutes. 1. Service 90% response time is lower than 1000ms in last 3 minutes 1. Service Instance average response time over 1s in last 2 minutes. 1. Endpoint average response time over 1s in last 2 minutes. - - -## List of all potential metrics name +### List of all potential metrics name The metrics names are defined in official [OAL scripts](../../guides/backend-oal-scripts.md), right now metrics from **Service**, **Service Instance**, **Endpoint** scopes could be used in Alarm, we will extend in further versions. Submit issue or pull request if you want to support any other scope in alarm. + +## Webhook +Webhook requires the peer is a web container. The alarm message will send through HTTP post by `application/json` content type. The JSON format is based on `Listoap-server - - ui - - true - - - apm-webapp - - dist @@ -301,10 +292,6 @@ maven-failsafe-plugin ${maven-failsafe-plugin.version} - - maven-surefire-plugin - ${maven-surefire-plugin.version} - maven-jar-plugin ${maven-jar-plugin.version} @@ -323,6 +310,7 @@ org.apache.maven.plugins maven-surefire-plugin + ${maven-surefire-plugin.version} IT*.class From 94d01cc42c4341e8e224e8d48ebf8f79ed7b9dec Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 19:19:44 +0800 Subject: [PATCH 05/24] Revert unexpected changes --- .gitmodules | 9 +++------ .../skywalking/apm/agent/core/conf/Config.java | 12 ------------ .../plugin/jdbc/JDBCPrepareStatementInterceptor.java | 9 ++++----- pom.xml | 9 +++++++++ 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/.gitmodules b/.gitmodules index 4a4d5c3ae69e..72f71a2c2c31 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,9 @@ [submodule "apm-protocol/apm-network/src/main/proto"] path = apm-protocol/apm-network/src/main/proto - url = file:///data/developer/git/java/skywalking/apm-protocol/apm-network/src/main/proto - #url = https://github.com/apache/skywalking-data-collect-protocol.git + url = https://github.com/apache/skywalking-data-collect-protocol.git [submodule "oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol"] path = oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol - url = file:///data/developer/git/java/skywalking/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol - #url = https://github.com/apache/skywalking-query-protocol.git + url = https://github.com/apache/skywalking-query-protocol.git [submodule "skywalking-ui"] path = skywalking-ui - #url = https://github.com/apache/skywalking-rocketbot-ui.git - url = file:///data/developer/git/java/skywalking/skywalking-ui + url = https://github.com/apache/skywalking-rocketbot-ui.git diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 31f38e6bee9c..59bfee804bd7 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -194,18 +194,6 @@ public static class Toolkit { public static boolean USE_QUALIFIED_NAME_AS_OPERATION_NAME = false; } - public static class SolrJ { - /** - * If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false. - */ - public static boolean TRACE_STATEMENT = false; - - /** - * If true, trace all the operation parameters in Solr request, default is false. - */ - public static boolean TRACE_OPS_PARAMS = false; - } - public static class MySQL { /** * If set to true, the parameters of the sql (typically {@link java.sql.PreparedStatement}) diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java index a68df0f25c06..f5348ed62107 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java @@ -19,16 +19,15 @@ package org.apache.skywalking.apm.plugin.jdbc; +import java.lang.reflect.Method; +import java.sql.Connection; +import java.sql.PreparedStatement; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; -import java.lang.reflect.Method; -import java.sql.Connection; -import java.sql.PreparedStatement; - /** * {@link JDBCPrepareStatementInterceptor} return {@link SWPreparedStatement} instance that wrapper the real * PreparedStatement instance when the client call prepareStatement method. @@ -38,7 +37,7 @@ public class JDBCPrepareStatementInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { + MethodInterceptResult result) throws Throwable { } diff --git a/pom.xml b/pom.xml index 98e6f52eed44..84bbade75b5a 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,15 @@ oap-server + + ui + + true + + + apm-webapp + + dist From c2fb8287900ec9e03432ea3f3f361597a7f429a0 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 19:20:35 +0800 Subject: [PATCH 06/24] Revert unexpected changes --- apm-sniffer/config/agent.config | 2 -- 1 file changed, 2 deletions(-) diff --git a/apm-sniffer/config/agent.config b/apm-sniffer/config/agent.config index a2f8c310b546..327d9ef0f77a 100644 --- a/apm-sniffer/config/agent.config +++ b/apm-sniffer/config/agent.config @@ -43,5 +43,3 @@ collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800} # Logging level logging.level=${SW_LOGGING_LEVEL:DEBUG} - -plugin.mysql.trace_sql_parameters=true From 34c35cdbae990978e24ed232acae9b702ba1d6d6 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 19:21:56 +0800 Subject: [PATCH 07/24] Revert unexpected changes --- .../apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java index f5348ed62107..cf50647a3036 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java @@ -37,7 +37,7 @@ public class JDBCPrepareStatementInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { + MethodInterceptResult result) throws Throwable { } From 78541b979a9417aee9b84c8180ba4033ae4ea9ec Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 21:46:16 +0800 Subject: [PATCH 08/24] Add LinkedList test --- .../apm/plugin/ArbitrarySetTest.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java index 682042827542..184ac55ddeba 100644 --- a/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java +++ b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedList; import java.util.Map; import java.util.TreeMap; import java.util.concurrent.TimeUnit; @@ -197,10 +198,20 @@ public void arrayList() { int oldSize = list.size(); if (i >= oldSize) { int newSize = Math.max(oldSize * 2, i); - ArrayList newList = new ArrayList(newSize); - newList.addAll(list); - newList.addAll(oldSize, Collections.nCopies(newSize - oldSize, PLACEHOLDER)); - list = newList; + list.addAll(oldSize, Collections.nCopies(newSize - oldSize, PLACEHOLDER)); + } + list.set(i, i); + } + } + + @Benchmark + public void linkedList() { + LinkedList list = new LinkedList(Collections.nCopies(20, PLACEHOLDER)); + for (int i = 0; i < 100; i++) { + int oldSize = list.size(); + if (i >= oldSize) { + int newSize = Math.max(oldSize * 2, i); + list.addAll(oldSize, Collections.nCopies(newSize - oldSize, PLACEHOLDER)); } list.set(i, i); } From cd72731b5c5250696bfd858faed52767077b59e6 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 21:55:05 +0800 Subject: [PATCH 09/24] Trigger multiple Job From c37d04f9030adc27953036de555f480fc851f485 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 21:56:11 +0800 Subject: [PATCH 10/24] Trigger multiple Job From 62ca76b0869a350d7eba8f823d47cbbd8729fd01 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 21:57:05 +0800 Subject: [PATCH 11/24] Trigger multiple Job From 6ab0978789b6d86b557dd6d8513d3297567231f0 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 22:02:42 +0800 Subject: [PATCH 12/24] Update benchmark result --- .../apm/plugin/ArbitrarySetTest.java | 143 +----------------- 1 file changed, 5 insertions(+), 138 deletions(-) diff --git a/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java index 184ac55ddeba..8974d4e1f3f2 100644 --- a/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java +++ b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java @@ -41,144 +41,11 @@ import java.util.concurrent.TimeUnit; /** - * # JMH version: 1.21 - * # VM version: JDK 10.0.1, Java HotSpot(TM) 64-Bit Server VM, 10.0.1+10 - * # VM invoker: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java - * # VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50729:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 - * # Warmup: 4 iterations, 10 s each - * # Measurement: 5 iterations, 10 s each - * # Timeout: 10 min per iteration - * # Threads: 1 thread, will synchronize iterations - * # Benchmark mode: Throughput, ops/time - * # Benchmark: org.apache.skywalking.apm.plugin.ArbitrarySetTest.array - *

- * # Run progress: 0.00% complete, ETA 00:09:00 - * # Fork: 1 of 2 - * # Warmup Iteration 1: 1227.556 ops/ms - * # Warmup Iteration 2: 1710.387 ops/ms - * # Warmup Iteration 3: 1692.754 ops/ms - * # Warmup Iteration 4: 1779.140 ops/ms - * Iteration 1: 1833.746 ops/ms - * Iteration 2: 1862.485 ops/ms - * Iteration 3: 1827.150 ops/ms - * Iteration 4: 1693.042 ops/ms - * Iteration 5: 1643.173 ops/ms - *

- * # Run progress: 16.67% complete, ETA 00:07:39 - * # Fork: 2 of 2 - * # Warmup Iteration 1: 1455.851 ops/ms - * # Warmup Iteration 2: 1629.368 ops/ms - * # Warmup Iteration 3: 1729.879 ops/ms - * # Warmup Iteration 4: 1790.962 ops/ms - * Iteration 1: 1681.082 ops/ms - * Iteration 2: 1557.253 ops/ms - * Iteration 3: 1510.295 ops/ms - * Iteration 4: 1559.166 ops/ms - * Iteration 5: 1615.465 ops/ms - *

- *

- * Result "org.apache.skywalking.apm.plugin.ArbitrarySetTest.array": - * 1678.286 ±(99.9%) 190.386 ops/ms [Average] - * (min, avg, max) = (1510.295, 1678.286, 1862.485), stdev = 125.929 - * CI (99.9%): [1487.900, 1868.672] (assumes normal distribution) - *

- *

- * # JMH version: 1.21 - * # VM version: JDK 10.0.1, Java HotSpot(TM) 64-Bit Server VM, 10.0.1+10 - * # VM invoker: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java - * # VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50729:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 - * # Warmup: 4 iterations, 10 s each - * # Measurement: 5 iterations, 10 s each - * # Timeout: 10 min per iteration - * # Threads: 1 thread, will synchronize iterations - * # Benchmark mode: Throughput, ops/time - * # Benchmark: org.apache.skywalking.apm.plugin.ArbitrarySetTest.arrayList - *

- * # Run progress: 33.33% complete, ETA 00:06:05 - * # Fork: 1 of 2 - * # Warmup Iteration 1: 575.365 ops/ms - * # Warmup Iteration 2: 627.217 ops/ms - * # Warmup Iteration 3: 611.638 ops/ms - * # Warmup Iteration 4: 584.694 ops/ms - * Iteration 1: 593.597 ops/ms - * Iteration 2: 582.952 ops/ms - * Iteration 3: 586.201 ops/ms - * Iteration 4: 668.791 ops/ms - * Iteration 5: 668.208 ops/ms - *

- * # Run progress: 50.00% complete, ETA 00:04:34 - * # Fork: 2 of 2 - * # Warmup Iteration 1: 567.132 ops/ms - * # Warmup Iteration 2: 619.129 ops/ms - * # Warmup Iteration 3: 719.696 ops/ms - * # Warmup Iteration 4: 734.769 ops/ms - * Iteration 1: 731.429 ops/ms - * Iteration 2: 684.019 ops/ms - * Iteration 3: 645.475 ops/ms - * Iteration 4: 634.259 ops/ms - * Iteration 5: 681.604 ops/ms - *

- *

- * Result "org.apache.skywalking.apm.plugin.ArbitrarySetTest.arrayList": - * 647.654 ±(99.9%) 73.776 ops/ms [Average] - * (min, avg, max) = (582.952, 647.654, 731.429), stdev = 48.799 - * CI (99.9%): [573.877, 721.430] (assumes normal distribution) - *

- *

- * # JMH version: 1.21 - * # VM version: JDK 10.0.1, Java HotSpot(TM) 64-Bit Server VM, 10.0.1+10 - * # VM invoker: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java - * # VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50729:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 - * # Warmup: 4 iterations, 10 s each - * # Measurement: 5 iterations, 10 s each - * # Timeout: 10 min per iteration - * # Threads: 1 thread, will synchronize iterations - * # Benchmark mode: Throughput, ops/time - * # Benchmark: org.apache.skywalking.apm.plugin.ArbitrarySetTest.treeMap - *

- * # Run progress: 66.67% complete, ETA 00:03:02 - * # Fork: 1 of 2 - * # Warmup Iteration 1: 149.772 ops/ms - * # Warmup Iteration 2: 164.658 ops/ms - * # Warmup Iteration 3: 181.832 ops/ms - * # Warmup Iteration 4: 181.535 ops/ms - * Iteration 1: 178.571 ops/ms - * Iteration 2: 135.320 ops/ms - * Iteration 3: 152.644 ops/ms - * Iteration 4: 166.896 ops/ms - * Iteration 5: 167.542 ops/ms - *

- * # Run progress: 83.33% complete, ETA 00:01:31 - * # Fork: 2 of 2 - * # Warmup Iteration 1: 171.791 ops/ms - * # Warmup Iteration 2: 178.640 ops/ms - * # Warmup Iteration 3: 167.416 ops/ms - * # Warmup Iteration 4: 171.610 ops/ms - * Iteration 1: 179.966 ops/ms - * Iteration 2: 187.318 ops/ms - * Iteration 3: 183.934 ops/ms - * Iteration 4: 181.388 ops/ms - * Iteration 5: 186.286 ops/ms - *

- *

- * Result "org.apache.skywalking.apm.plugin.ArbitrarySetTest.treeMap": - * 171.986 ±(99.9%) 25.408 ops/ms [Average] - * (min, avg, max) = (135.320, 171.986, 187.318), stdev = 16.806 - * CI (99.9%): [146.578, 197.394] (assumes normal distribution) - *

- *

- * # Run complete. Total time: 00:09:07 - *

- * REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on - * why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial - * experiments, perform baseline and negative tests that provide experimental control, make sure - * the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts. - * Do not assume the numbers tell you what you want them to tell. - *

- * Benchmark Mode Cnt Score Error Units - * ArbitrarySetTest.array thrpt 10 1678.286 ± 190.386 ops/ms - * ArbitrarySetTest.arrayList thrpt 10 647.654 ± 73.776 ops/ms - * ArbitrarySetTest.treeMap thrpt 10 171.986 ± 25.408 ops/ms + * Benchmark Mode Cnt Score Error Units + * ArbitrarySetTest.array thrpt 10 2360.500 ± 138.279 ops/ms + * ArbitrarySetTest.arrayList thrpt 10 1080.005 ± 225.897 ops/ms + * ArbitrarySetTest.linkedList thrpt 10 188.007 ± 11.739 ops/ms + * ArbitrarySetTest.treeMap thrpt 10 214.384 ± 27.816 ops/ms * * @author kezhenxu94 */ From 0d8bd0eda378eb14079d65147ec84b21f77b7d26 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sat, 15 Jun 2019 22:26:21 +0800 Subject: [PATCH 13/24] Update test --- .../org/apache/skywalking/apm/plugin/ArbitrarySetTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java index 8974d4e1f3f2..36a585a2ae18 100644 --- a/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java +++ b/apm-sniffer/apm-test-tools/src/test/java/org/apache/skywalking/apm/plugin/ArbitrarySetTest.java @@ -91,8 +91,10 @@ public void array() { for (int i = 1; i <= 100; i++) { int length = array.length; if (i >= length) { - Object[] newArray = new Object[Math.max(i, length * 2)]; + int newSize = Math.max(i, length * 2); + Object[] newArray = new Object[newSize]; System.arraycopy(array, 0, newArray, 0, length); + Arrays.fill(newArray, length, newSize, PLACEHOLDER); array = newArray; } array[i] = i; From 46a7beefbf5cb07a3e06f1fca4248cc64b64db37 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sun, 16 Jun 2019 01:06:04 +0800 Subject: [PATCH 14/24] Improve performance --- .../jdbc/define/StatementEnhanceInfos.java | 6 ++ .../PreparedStatementInstrumentation.java | 14 +-- ...reparedStatementSetterInstrumentation.java | 86 +++++++++++++++ .../PreparedStatementInstrumentation.java | 14 +-- ...reparedStatementSetterInstrumentation.java | 85 +++++++++++++++ .../PreparedStatementInstrumentation.java | 14 +-- ...reparedStatementSetterInstrumentation.java | 85 +++++++++++++++ .../apm/plugin/jdbc/mysql/Constants.java | 1 + ...redStatementExecuteMethodsInterceptor.java | 18 +--- ...aredStatementSetterMethodsInterceptor.java | 100 ++++++++++++++++++ 10 files changed, 370 insertions(+), 53 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java index c6643e3d3ed1..c08d1bc162aa 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java @@ -36,6 +36,7 @@ public class StatementEnhanceInfos { private String statementName; private String sql; private Object[] parameters; + private int maxIndex = 0; public StatementEnhanceInfos(ConnectionInfo connectionInfo, String sql, String statementName) { this.connectionInfo = connectionInfo; @@ -56,6 +57,7 @@ public String getStatementName() { } public void setParameter(int index, final Object parameter) { + maxIndex = maxIndex > index ? maxIndex : index; index--; // start from 1 if (parameters == null) { parameters = new Object[20]; @@ -75,4 +77,8 @@ public void setParameter(int index, final Object parameter) { public Object[] getParameters() { return parameters; } + + public int getMaxIndex() { + return maxIndex; + } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java index 0922e1c9f598..ef16a75a29f1 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java @@ -21,7 +21,6 @@ import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; @@ -29,8 +28,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; /** * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the @@ -58,19 +55,10 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - ElementMatcher.Junction matcher = named("execute") + return named("execute") .or(named("executeQuery")) .or(named("executeUpdate")) .or(named("executeLargeUpdate")); - if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { - for (String setter : PS_SETTERS) { - matcher = matcher.or(named(setter)); - } - for (String setter : PS_IGNORED_SETTERS) { - matcher = matcher.or(named(setter)); - } - } - return matcher; } @Override public String getMethodsInterceptor() { diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java new file mode 100644 index 000000000000..3b9048e3ea29 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.mysql.Constants; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.none; +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementSetterInstrumentation extends AbstractMysqlInstrumentation { + + private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR; + public static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; + public static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + ElementMatcher.Junction matcher = none(); + if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { + for (String setter : PS_SETTERS) { + matcher = matcher.or(named(setter)); + } + for (String setter : PS_IGNORED_SETTERS) { + matcher = matcher.or(named(setter)); + } + } + return matcher; + } + + @Override + public String getMethodsInterceptor() { + return SERVICE_METHOD_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byMultiClassMatch(MYSQL_PREPARED_STATEMENT_CLASS_NAME, JDBC42_PREPARED_STATEMENT_CLASS_NAME); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java index b5dee7721780..c27eff28acf7 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java @@ -21,15 +21,12 @@ import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; /** * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the @@ -56,19 +53,10 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - ElementMatcher.Junction matcher = named("execute") + return named("execute") .or(named("executeQuery")) .or(named("executeUpdate")) .or(named("executeLargeUpdate")); - if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { - for (String setter : PS_SETTERS) { - matcher = matcher.or(named(setter)); - } - for (String setter : PS_IGNORED_SETTERS) { - matcher = matcher.or(named(setter)); - } - } - return matcher; } @Override public String getMethodsInterceptor() { diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java new file mode 100644 index 000000000000..6acce48584de --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.mysql.Constants; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.none; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementSetterInstrumentation extends AbstractMysqlInstrumentation { + + private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR; + public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + ElementMatcher.Junction matcher = none(); + if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { + for (String setter : PS_SETTERS) { + matcher = matcher.or(named(setter)); + } + for (String setter : PS_IGNORED_SETTERS) { + matcher = matcher.or(named(setter)); + } + } + return matcher; + } + + @Override + public String getMethodsInterceptor() { + return SERVICE_METHOD_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java index 0cb191eda6da..183c45d290e8 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java @@ -21,7 +21,6 @@ import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; @@ -29,8 +28,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentation { @@ -47,19 +44,10 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - ElementMatcher.Junction matcher = named("execute") + return named("execute") .or(named("executeQuery")) .or(named("executeUpdate")) .or(named("executeLargeUpdate")); - if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { - for (String setter : PS_SETTERS) { - matcher = matcher.or(named(setter)); - } - for (String setter : PS_IGNORED_SETTERS) { - matcher = matcher.or(named(setter)); - } - } - return matcher; } @Override public String getMethodsInterceptor() { diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java new file mode 100644 index 000000000000..23bf2ae8218f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.mysql.Constants; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.none; +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementSetterInstrumentation extends AbstractMysqlInstrumentation { + + private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ClientPreparedStatement"; + private static final String PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement"; + private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + ElementMatcher.Junction matcher = none(); + if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { + for (String setter : PS_SETTERS) { + matcher = matcher.or(named(setter)); + } + for (String setter : PS_IGNORED_SETTERS) { + matcher = matcher.or(named(setter)); + } + } + return matcher; + } + + @Override + public String getMethodsInterceptor() { + return SERVICE_METHOD_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java index 067c06c3ea40..311bc589582d 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java @@ -37,6 +37,7 @@ public class Constants { public static final String CREATE_PREPARED_STATEMENT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.CreatePreparedStatementInterceptor"; public static final String CREATE_STATEMENT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.CreateStatementInterceptor"; public static final String PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.PreparedStatementExecuteMethodsInterceptor"; + public static final String PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.PreparedStatementSetterMethodsInterceptor"; public static final String SET_CATALOG_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.SetCatalogInterceptor"; public static final String STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; public static final String DRIVER_CONNECT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.DriverConnectInterceptor"; diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java index e2d0b6c5b71d..a90a97a890ff 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java @@ -39,30 +39,22 @@ import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETER_PLACEHOLDER; public class PreparedStatementExecuteMethodsInterceptor 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(); - - final String methodName = method.getName(); - - if (PS_SETTERS.contains(methodName) || PS_IGNORED_SETTERS.contains(methodName)) { - final int index = (Integer) allArguments[0]; - final Object parameter = getDisplayedParameter(method, argumentsTypes, allArguments); - cacheObject.setParameter(index, parameter); - } - /** * For avoid NPE. In this particular case, Execute sql inside the {@link com.mysql.jdbc.ConnectionImpl} constructor, * before the interceptor sets the connectionInfo. * * @see JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object) */ - if (connectInfo != null && !PS_SETTERS.contains(methodName) && !PS_IGNORED_SETTERS.contains(methodName)) { + if (connectInfo != null) { - AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, methodName, cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + 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()); @@ -89,9 +81,7 @@ public final Object afterMethod(EnhancedInstance objInst, Method method, Object[ Class[] argumentsTypes, Object ret) throws Throwable { StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); - ConnectionInfo connectionInfo = cacheObject.getConnectionInfo(); - String methodName = method.getName(); - if (connectionInfo != null && !PS_SETTERS.contains(methodName) && !PS_IGNORED_SETTERS.contains(methodName)) { + if (cacheObject.getConnectionInfo() != null) { ContextManager.stopSpan(); } return ret; diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java new file mode 100644 index 000000000000..952c8f6438e3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc.mysql; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +import java.lang.reflect.Method; + +import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PARAMETER_PLACEHOLDER; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.DISPLAYABLE_TYPES; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; +import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETER_PLACEHOLDER; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementSetterMethodsInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + final StatementEnhanceInfos statementEnhanceInfos = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); + final int index = (Integer) allArguments[0]; + final Object parameter = getDisplayedParameter(method, argumentsTypes, allArguments); + statementEnhanceInfos.setParameter(index, parameter); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, + Method method, + Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override + public final void handleMethodException(EnhancedInstance objInst, + Method method, + Object[] allArguments, + Class[] argumentsTypes, + Throwable t) { + } + + private Object getDisplayedParameter(final Method method, final Class[] argumentTypes, final Object[] allArguments) { + final String methodName = method.getName(); + if ("setNull".equals(methodName)) { + return "null"; + } + if ("setObject".equals(methodName)) { + final Object parameter = allArguments[0]; + final Class parameterType = argumentTypes[1]; + + if (DISPLAYABLE_TYPES.contains(parameterType)) { + return parameter; + } + } else if (PS_SETTERS.contains(methodName)) { + return allArguments[1]; + } + return SQL_PARAMETER_PLACEHOLDER; + } + + private String buildParameterString(Object[] parameters, int maxIndex) { + String parameterString = "["; + boolean first = true; + for (int i = 0; i < maxIndex; i++) { + Object parameter = parameters[i]; + if (parameter == PARAMETER_PLACEHOLDER) { + break; + } + if (!first) { + parameterString += ","; + } + parameterString += parameter; + first = false; + } + parameterString += "]"; + return parameterString; + } +} From b8e312c0c94811e164a7f2d1dc93d5385a99bd72 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sun, 16 Jun 2019 01:08:47 +0800 Subject: [PATCH 15/24] Remove duplicated codes --- ...redStatementExecuteMethodsInterceptor.java | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java index a90a97a890ff..9c25123d6a9b 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java @@ -32,11 +32,7 @@ import java.lang.reflect.Method; import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PARAMETER_PLACEHOLDER; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.DISPLAYABLE_TYPES; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETER_PLACEHOLDER; public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { @@ -99,24 +95,6 @@ private String buildOperationName(ConnectionInfo connectionInfo, String methodNa return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; } - private Object getDisplayedParameter(final Method method, final Class[] argumentTypes, final Object[] allArguments) { - final String methodName = method.getName(); - if ("setNull".equals(methodName)) { - return "null"; - } - if ("setObject".equals(methodName)) { - final Object parameter = allArguments[0]; - final Class parameterType = argumentTypes[1]; - - if (DISPLAYABLE_TYPES.contains(parameterType)) { - return parameter; - } - } else if (PS_SETTERS.contains(methodName)) { - return allArguments[1]; - } - return SQL_PARAMETER_PLACEHOLDER; - } - private String buildParameterString(Object[] parameters) { String parameterString = "["; boolean first = true; From 83242965eb1eacb88a7216010cbb3e485a80294f Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sun, 16 Jun 2019 01:14:06 +0800 Subject: [PATCH 16/24] More defence --- .../jdbc/define/StatementEnhanceInfos.java | 6 ++---- ...redStatementExecuteMethodsInterceptor.java | 12 +++++------ ...aredStatementSetterMethodsInterceptor.java | 20 ------------------- 3 files changed, 7 insertions(+), 31 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java index c08d1bc162aa..3a9d24648a7f 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java @@ -23,8 +23,6 @@ import java.util.Arrays; -import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PARAMETER_PLACEHOLDER; - /** * {@link StatementEnhanceInfos} contain the {@link ConnectionInfo} and * sql for trace mysql. @@ -61,14 +59,14 @@ public void setParameter(int index, final Object parameter) { index--; // start from 1 if (parameters == null) { parameters = new Object[20]; - Arrays.fill(parameters, PARAMETER_PLACEHOLDER); + Arrays.fill(parameters, null); } int length = parameters.length; if (index >= length) { int newSize = Math.max(index + 1, length * 2); Object[] newParameters = new Object[newSize]; System.arraycopy(parameters, 0, newParameters, 0, length); - Arrays.fill(newParameters, length, newSize, PARAMETER_PLACEHOLDER); + Arrays.fill(newParameters, length, newSize, null); parameters = newParameters; } parameters[index] = parameter; diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java index 9c25123d6a9b..732816c07d08 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java @@ -31,7 +31,6 @@ import java.lang.reflect.Method; -import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PARAMETER_PLACEHOLDER; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETERS; public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { @@ -59,7 +58,8 @@ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { final Object[] parameters = cacheObject.getParameters(); if (parameters != null && parameters.length > 0) { - String parameterString = buildParameterString(parameters); + int maxIndex = cacheObject.getMaxIndex(); + String parameterString = buildParameterString(parameters, maxIndex); int sqlParametersMaxLength = Config.Plugin.MySQL.SQL_PARAMETERS_MAX_LENGTH; if (sqlParametersMaxLength > 0 && parameterString.length() > sqlParametersMaxLength) { parameterString = parameterString.substring(0, sqlParametersMaxLength) + "..."; @@ -95,13 +95,11 @@ private String buildOperationName(ConnectionInfo connectionInfo, String methodNa return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; } - private String buildParameterString(Object[] parameters) { + private String buildParameterString(Object[] parameters, int maxIndex) { String parameterString = "["; boolean first = true; - for (Object parameter : parameters) { - if (parameter == PARAMETER_PLACEHOLDER) { - break; - } + for (int i = 0; i < maxIndex; i++) { + Object parameter = parameters[i]; if (!first) { parameterString += ","; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java index 952c8f6438e3..d222826a72d2 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java @@ -22,11 +22,9 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; -import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; import java.lang.reflect.Method; -import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PARAMETER_PLACEHOLDER; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.DISPLAYABLE_TYPES; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETER_PLACEHOLDER; @@ -79,22 +77,4 @@ private Object getDisplayedParameter(final Method method, final Class[] argum } return SQL_PARAMETER_PLACEHOLDER; } - - private String buildParameterString(Object[] parameters, int maxIndex) { - String parameterString = "["; - boolean first = true; - for (int i = 0; i < maxIndex; i++) { - Object parameter = parameters[i]; - if (parameter == PARAMETER_PLACEHOLDER) { - break; - } - if (!first) { - parameterString += ","; - } - parameterString += parameter; - first = false; - } - parameterString += "]"; - return parameterString; - } } From 3bef7607b721b53b1c9756787e5669dec5acb55f Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sun, 16 Jun 2019 07:27:18 +0800 Subject: [PATCH 17/24] Revert some unexpected changes --- .../plugin/jdbc/JDBCPrepareStatementInterceptor.java | 2 +- .../skywalking/apm/plugin/jdbc/define/Constants.java | 1 - .../v5/define/PreparedStatementInstrumentation.java | 12 ++++++------ .../v6/define/PreparedStatementInstrumentation.java | 12 ++++++------ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java index cf50647a3036..12372d1e2862 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPrepareStatementInterceptor.java @@ -23,10 +23,10 @@ import java.sql.Connection; import java.sql.PreparedStatement; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; /** * {@link JDBCPrepareStatementInterceptor} return {@link SWPreparedStatement} instance that wrapper the real diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java index a14c8cedef53..895a5cacae68 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java @@ -42,5 +42,4 @@ public class Constants { public static final String RELEASE_SAVE_POINT_METHOD_NAME = "releaseSavepoint"; - public static final Object PARAMETER_PLACEHOLDER = new Object(); } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java index ef16a75a29f1..77670ea053ea 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java @@ -31,13 +31,13 @@ /** * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the - * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and + * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and * com.mysql.cj.jdbc.PreparedStatement class: - * 1. execute - * 2. executeQuery - * 3. executeUpdate - * 4. executeLargeUpdate - * 5. addBatch + * 1. execute + * 2. executeQuery + * 3. executeUpdate + * 4. executeLargeUpdate + * 5. addBatch * * @author zhangxin */ diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java index c27eff28acf7..89feca9332e7 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java @@ -30,13 +30,13 @@ /** * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the - * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and + * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and * com.mysql.cj.jdbc.PreparedStatement class: - * 1. execute - * 2. executeQuery - * 3. executeUpdate - * 4. executeLargeUpdate - * 5. addBatch + * 1. execute + * 2. executeQuery + * 3. executeUpdate + * 4. executeLargeUpdate + * 5. addBatch * * @author zhangxin */ From 9c6f1e25985ee56b14b3591ae429f449ab8baa95 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sun, 16 Jun 2019 07:36:55 +0800 Subject: [PATCH 18/24] Add instrumentation declaration --- .../apm/plugin/jdbc/define/StatementEnhanceInfos.java | 3 ++- .../mysql-5.x-plugin/src/main/resources/skywalking-plugin.def | 1 + .../mysql-6.x-plugin/src/main/resources/skywalking-plugin.def | 1 + .../mysql-8.x-plugin/src/main/resources/skywalking-plugin.def | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java index 3a9d24648a7f..3ec22a4692c2 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/StatementEnhanceInfos.java @@ -58,7 +58,8 @@ public void setParameter(int index, final Object parameter) { maxIndex = maxIndex > index ? maxIndex : index; index--; // start from 1 if (parameters == null) { - parameters = new Object[20]; + final int initialSize = Math.max(20, maxIndex); + parameters = new Object[initialSize]; Arrays.fill(parameters, null); } int length = parameters.length; 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 index a8350c951ad3..de5152b836fa 100644 --- 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 @@ -21,3 +21,4 @@ mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatemen mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.StatementInstrumentation mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.CacheIpsInstrumentation mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.ConnectionImplCreateInstrumentation +mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatementSetterInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def index 087d2af2bf81..bde76d1d5fc0 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def @@ -21,3 +21,4 @@ mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatemen mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.StatementInstrumentation mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.CacheIpsInstrumentation mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.ConnectionImplCreateInstrumentation +mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatementSetterInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def index 5a3c552fce31..c108da060801 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def @@ -19,3 +19,4 @@ mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.ConnectionInstru mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.CallableInstrumentation mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementInstrumentation mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.StatementInstrumentation +mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementSetterInstrumentation From 438a48a4df52d9b727bacf13ea274d4311a97e0a Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sun, 16 Jun 2019 22:08:40 +0800 Subject: [PATCH 19/24] Revert unexpected chagnes --- ...edStatementIgnorableSetterInterceptor.java | 58 ++++++++++++++++ ...llSetterInstanceMethodsInterceptPoint.java | 46 +++++++++++++ ...reparedStatementNullSetterInterceptor.java | 57 +++++++++++++++ ...ntSetterInstanceMethodsInterceptPoint.java | 69 +++++++++++++++++++ ...BCPreparedStatementSetterInterceptor.java} | 28 +------- .../apm/plugin/jdbc/define/Constants.java | 40 +++++++++++ ...StatementIgnoredSetterInstrumentation.java | 54 +++++++++++++++ ...redStatementNullSetterInstrumentation.java | 54 +++++++++++++++ ...reparedStatementSetterInstrumentation.java | 40 ++--------- .../src/main/resources/skywalking-plugin.def | 2 + ...StatementIgnoredSetterInstrumentation.java | 53 ++++++++++++++ ...redStatementNullSetterInstrumentation.java | 54 +++++++++++++++ ...reparedStatementSetterInstrumentation.java | 36 +--------- .../src/main/resources/skywalking-plugin.def | 2 + ...StatementIgnoredSetterInstrumentation.java | 54 +++++++++++++++ ...redStatementNullSetterInstrumentation.java | 53 ++++++++++++++ ...reparedStatementSetterInstrumentation.java | 36 +--------- .../src/main/resources/skywalking-plugin.def | 2 + .../apm/plugin/jdbc/mysql/Constants.java | 57 --------------- 19 files changed, 609 insertions(+), 186 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementIgnorableSetterInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInstanceMethodsInterceptPoint.java rename apm-sniffer/apm-sdk-plugin/{mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java => jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java} (67%) create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementIgnorableSetterInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementIgnorableSetterInterceptor.java new file mode 100644 index 000000000000..9294ad67f5a3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementIgnorableSetterInterceptor.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.Constants; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; + +import java.lang.reflect.Method; + +/** + * @author kezhenxu94 + */ +public class JDBCPreparedStatementIgnorableSetterInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + final StatementEnhanceInfos statementEnhanceInfos = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); + final int index = (Integer) allArguments[0]; + statementEnhanceInfos.setParameter(index, Constants.SQL_PARAMETER_PLACEHOLDER); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, + Method method, + Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override + public final void handleMethodException(EnhancedInstance objInst, + Method method, + Object[] allArguments, + Class[] argumentsTypes, + Throwable t) { + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint.java new file mode 100644 index 000000000000..04e619e39946 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.define.Constants; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * @author kezhenxu94 + */ +public final class JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint implements InstanceMethodsInterceptPoint { + @Override + public ElementMatcher getMethodsMatcher() { + return named("setNull"); + } + + @Override + public String getMethodsInterceptor() { + return Constants.PREPARED_STATEMENT_NULL_SETTER_METHODS_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInterceptor.java new file mode 100644 index 000000000000..fe721f63f75c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementNullSetterInterceptor.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; + +import java.lang.reflect.Method; + +/** + * @author kezhenxu94 + */ +public class JDBCPreparedStatementNullSetterInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + final StatementEnhanceInfos statementEnhanceInfos = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); + final int index = (Integer) allArguments[0]; + statementEnhanceInfos.setParameter(index, "NULL"); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, + Method method, + Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override + public final void handleMethodException(EnhancedInstance objInst, + Method method, + Object[] allArguments, + Class[] argumentsTypes, + Throwable t) { + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInstanceMethodsInterceptPoint.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInstanceMethodsInterceptPoint.java new file mode 100644 index 000000000000..646fa6b04648 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInstanceMethodsInterceptPoint.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.define.Constants; + +import java.util.Set; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.none; +import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PS_IGNORABLE_SETTERS; +import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PS_SETTERS; + +/** + * @author kezhenxu94 + */ +public class JDBCPreparedStatementSetterInstanceMethodsInterceptPoint implements InstanceMethodsInterceptPoint { + private final boolean ignorable; + + public JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(boolean ignorable) { + this.ignorable = ignorable; + } + + @Override + public ElementMatcher getMethodsMatcher() { + ElementMatcher.Junction matcher = none(); + + if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { + final Set setters = ignorable ? PS_IGNORABLE_SETTERS : PS_SETTERS; + for (String setter : setters) { + matcher = matcher.or(named(setter)); + } + } + + return matcher; + } + + @Override + public String getMethodsInterceptor() { + return ignorable + ? Constants.PREPARED_STATEMENT_IGNORABLE_SETTER_METHODS_INTERCEPTOR + : Constants.PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java similarity index 67% rename from apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java index d222826a72d2..4a9dc847902e 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementSetterMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.jdbc.mysql; +package org.apache.skywalking.apm.plugin.jdbc; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; @@ -25,21 +25,17 @@ import java.lang.reflect.Method; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.DISPLAYABLE_TYPES; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETER_PLACEHOLDER; - /** * @author kezhenxu94 */ -public class PreparedStatementSetterMethodsInterceptor implements InstanceMethodsAroundInterceptor { +public class JDBCPreparedStatementSetterInterceptor implements InstanceMethodsAroundInterceptor { @Override public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { final StatementEnhanceInfos statementEnhanceInfos = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); final int index = (Integer) allArguments[0]; - final Object parameter = getDisplayedParameter(method, argumentsTypes, allArguments); + final Object parameter = allArguments[0]; statementEnhanceInfos.setParameter(index, parameter); } @@ -59,22 +55,4 @@ public final void handleMethodException(EnhancedInstance objInst, Class[] argumentsTypes, Throwable t) { } - - private Object getDisplayedParameter(final Method method, final Class[] argumentTypes, final Object[] allArguments) { - final String methodName = method.getName(); - if ("setNull".equals(methodName)) { - return "null"; - } - if ("setObject".equals(methodName)) { - final Object parameter = allArguments[0]; - final Class parameterType = argumentTypes[1]; - - if (DISPLAYABLE_TYPES.contains(parameterType)) { - return parameter; - } - } else if (PS_SETTERS.contains(methodName)) { - return allArguments[1]; - } - return SQL_PARAMETER_PLACEHOLDER; - } } diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java index 895a5cacae68..03902cf2e14c 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/define/Constants.java @@ -19,6 +19,10 @@ package org.apache.skywalking.apm.plugin.jdbc.define; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + public class Constants { public static final String CREATE_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.JDBCStatementInterceptor"; @@ -41,5 +45,41 @@ public class Constants { public static final String CLOSE_METHOD_NAME = "close"; public static final String RELEASE_SAVE_POINT_METHOD_NAME = "releaseSavepoint"; + public static final String SQL_PARAMETER_PLACEHOLDER = "?"; + public static final Set PS_SETTERS = new HashSet(Arrays.asList( + "setArray", + "setBigDecimal", + "setBoolean", + "setByte", + "setDate", + "setDouble", + "setFloat", + "setInt", + "setLong", + "setNString", + "setObject", + "setRowId", + "setShort", + "setString", + "setTime", + "setTimestamp", + "setURL" + )); + public static final Set PS_IGNORABLE_SETTERS = new HashSet(Arrays.asList( + "setAsciiStream", + "setBinaryStream", + "setBlob", + "setBytes", + "setCharacterStream", + "setClob", + "setNCharacterStream", + "setNClob", + "setRef", + "setSQLXML", + "setUnicodeStream" + )); + public static final String PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInterceptor"; + public static final String PREPARED_STATEMENT_NULL_SETTER_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInterceptor"; + public static final String PREPARED_STATEMENT_IGNORABLE_SETTER_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementIgnorableSetterInterceptor"; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java new file mode 100644 index 000000000000..020f5c726611 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; + +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementIgnoredSetterInstrumentation extends AbstractMysqlInstrumentation { + + private static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; + private static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(true) + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byMultiClassMatch(MYSQL_PREPARED_STATEMENT_CLASS_NAME, JDBC42_PREPARED_STATEMENT_CLASS_NAME); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java new file mode 100644 index 000000000000..92637fbb1213 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; + +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementNullSetterInstrumentation extends AbstractMysqlInstrumentation { + + private static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; + private static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint() + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byMultiClassMatch(MYSQL_PREPARED_STATEMENT_CLASS_NAME, JDBC42_PREPARED_STATEMENT_CLASS_NAME); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java index 3b9048e3ea29..29e514fc9b6e 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java @@ -19,28 +19,20 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.plugin.jdbc.mysql.Constants; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.none; import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; /** * @author kezhenxu94 */ public class PreparedStatementSetterInstrumentation extends AbstractMysqlInstrumentation { - private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR; - public static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; - public static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; + private static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; + private static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @@ -50,31 +42,7 @@ protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - ElementMatcher.Junction matcher = none(); - if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { - for (String setter : PS_SETTERS) { - matcher = matcher.or(named(setter)); - } - for (String setter : PS_IGNORED_SETTERS) { - matcher = matcher.or(named(setter)); - } - } - return matcher; - } - - @Override - public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } + new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(false) }; } 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 index de5152b836fa..57fea2cc38b0 100644 --- 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 @@ -21,4 +21,6 @@ mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatemen mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.StatementInstrumentation mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.CacheIpsInstrumentation mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.ConnectionImplCreateInstrumentation +mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatementIgnoredSetterInstrumentation mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatementSetterInstrumentation +mysql-5.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define.PreparedStatementNullSetterInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java new file mode 100644 index 000000000000..4c5df72e5e11 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; + +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementIgnoredSetterInstrumentation extends AbstractMysqlInstrumentation { + + public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(true) + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java new file mode 100644 index 000000000000..a80351f3f68a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; + +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementNullSetterInstrumentation extends AbstractMysqlInstrumentation { + + public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint() + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java index 6acce48584de..713e59fd0625 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java @@ -19,26 +19,18 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.plugin.jdbc.mysql.Constants; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.none; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; /** * @author kezhenxu94 */ public class PreparedStatementSetterInstrumentation extends AbstractMysqlInstrumentation { - private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR; public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; @Override @@ -49,31 +41,7 @@ protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - ElementMatcher.Junction matcher = none(); - if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { - for (String setter : PS_SETTERS) { - matcher = matcher.or(named(setter)); - } - for (String setter : PS_IGNORED_SETTERS) { - matcher = matcher.or(named(setter)); - } - } - return matcher; - } - - @Override - public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } + new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(false) }; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def index bde76d1d5fc0..c5af17ea9cec 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/resources/skywalking-plugin.def @@ -22,3 +22,5 @@ mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.StatementInstrum mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.CacheIpsInstrumentation mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.ConnectionImplCreateInstrumentation mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatementSetterInstrumentation +mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatementIgnoredSetterInstrumentation +mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatementNullSetterInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java new file mode 100644 index 000000000000..54a5aa85bad6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; + +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementIgnoredSetterInstrumentation extends AbstractMysqlInstrumentation { + + private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ClientPreparedStatement"; + private static final String PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement"; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(true) + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java new file mode 100644 index 000000000000..cbf2c9878fc0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; + +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * @author kezhenxu94 + */ +public class PreparedStatementNullSetterInstrumentation extends AbstractMysqlInstrumentation { + + public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; + + @Override + protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint() + }; + } + + @Override + protected ClassMatch enhanceClass() { + return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java index 23bf2ae8218f..5e59bdd3e986 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java @@ -19,19 +19,12 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.plugin.jdbc.mysql.Constants; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.none; import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_IGNORED_SETTERS; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.PS_SETTERS; /** * @author kezhenxu94 @@ -40,7 +33,6 @@ public class PreparedStatementSetterInstrumentation extends AbstractMysqlInstrum private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ClientPreparedStatement"; private static final String PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement"; - private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR; @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @@ -50,31 +42,7 @@ protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - ElementMatcher.Junction matcher = none(); - if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { - for (String setter : PS_SETTERS) { - matcher = matcher.or(named(setter)); - } - for (String setter : PS_IGNORED_SETTERS) { - matcher = matcher.or(named(setter)); - } - } - return matcher; - } - - @Override - public String getMethodsInterceptor() { - return SERVICE_METHOD_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - } + new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(false) }; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def index c108da060801..11db6da6e97a 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/resources/skywalking-plugin.def @@ -20,3 +20,5 @@ mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.CallableInstrume mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementInstrumentation mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.StatementInstrumentation mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementSetterInstrumentation +mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementNullSetterInstrumentation +mysql-8.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define.PreparedStatementIgnoredSetterInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java index 311bc589582d..4ff45b0340e7 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java @@ -37,66 +37,9 @@ public class Constants { public static final String CREATE_PREPARED_STATEMENT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.CreatePreparedStatementInterceptor"; public static final String CREATE_STATEMENT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.CreateStatementInterceptor"; public static final String PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.PreparedStatementExecuteMethodsInterceptor"; - public static final String PREPARED_STATEMENT_SETTER_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.PreparedStatementSetterMethodsInterceptor"; public static final String SET_CATALOG_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.SetCatalogInterceptor"; public static final String STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor"; public static final String DRIVER_CONNECT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.DriverConnectInterceptor"; public static final StringTag SQL_PARAMETERS = new StringTag("db.sql.parameters"); - public static final String SQL_PARAMETER_PLACEHOLDER = "?"; - public static final Set PS_SETTERS = new HashSet(Arrays.asList( - "setArray", - "setBigDecimal", - "setBoolean", - "setByte", - "setDate", - "setDouble", - "setFloat", - "setInt", - "setLong", - "setNString", - "setNull", - "setObject", - "setRowId", - "setShort", - "setString", - "setTime", - "setTimestamp", - "setURL" - )); - public static final Set> DISPLAYABLE_TYPES = new HashSet>(Arrays.asList( - BigDecimal.class, - Boolean.class, - boolean.class, - Byte.class, - byte.class, - Date.class, - Double.class, - double.class, - Float.class, - float.class, - Integer.class, - int.class, - Long.class, - long.class, - String.class, - Short.class, - short.class, - Time.class, - Timestamp.class, - URL.class - )); - public static final Set PS_IGNORED_SETTERS = new HashSet(Arrays.asList( - "setAsciiStream", - "setBinaryStream", - "setBlob", - "setBytes", - "setCharacterStream", - "setClob", - "setNCharacterStream", - "setNClob", - "setRef", - "setSQLXML", - "setUnicodeStream" - )); } From e608d467de4d6dc59c91d4a11b90a31ce0995462 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sun, 16 Jun 2019 22:16:35 +0800 Subject: [PATCH 20/24] Revert removed docs --- docs/en/setup/service-agent/java-agent/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md index 17875e137fe8..609bf6f1283d 100644 --- a/docs/en/setup/service-agent/java-agent/README.md +++ b/docs/en/setup/service-agent/java-agent/README.md @@ -82,8 +82,6 @@ property key | Description | Default | `plugin.elasticsearch.trace_dsl`|If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false.|`false`| `plugin.springmvc.use_qualified_name_as_endpoint_name`|If true, the fully qualified method name will be used as the endpoint name instead of the request URL, default is false.|`false`| `plugin.toolit.use_qualified_name_as_operation_name`|If true, the fully qualified method name will be used as the operation name instead of the given operation name, default is false.|`false`| -`plugin.solrj.trace_statement`|If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false.|`false`| -`plugin.solrj.trace_ops_params`|If true, trace all the operation parameters in Solr request, default is false.|`false`| `plugin.mysql.trace_sql_parameters`|If set to true, the parameters of the sql (typically `java.sql.PreparedStatement`) would be collected.|`false`| `plugin.mysql.sql_parameters_max_length`|If set to positive number, the `db.sql.parameters` would be truncated to this length, otherwise it would be completely saved, which may cause performance problem.|`512`| From ac32aef021b728849a3022c87c0efd59ec2c190a Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sun, 16 Jun 2019 22:30:37 +0800 Subject: [PATCH 21/24] Fix checkstyle --- .../PreparedStatementNullSetterInstrumentation.java | 1 - .../skywalking/apm/plugin/jdbc/mysql/Constants.java | 9 --------- 2 files changed, 10 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java index a80351f3f68a..e22eae548e91 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java @@ -24,7 +24,6 @@ import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; -import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java index 4ff45b0340e7..80dcb147c526 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/Constants.java @@ -20,15 +20,6 @@ import org.apache.skywalking.apm.agent.core.context.tag.StringTag; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Date; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - /** * @author: dingshaocheng */ From 5c7128446904a3fbe0d86ce4fa2da63065701dc7 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Sun, 16 Jun 2019 23:26:53 +0800 Subject: [PATCH 22/24] Rename some classes --- .../plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java | 2 +- ...oint.java => PSSetterDefinitionOfJDBCInstrumentation.java} | 4 ++-- .../define/PreparedStatementIgnoredSetterInstrumentation.java | 4 ++-- .../v5/define/PreparedStatementSetterInstrumentation.java | 4 ++-- .../define/PreparedStatementIgnoredSetterInstrumentation.java | 4 ++-- .../v6/define/PreparedStatementSetterInstrumentation.java | 4 ++-- .../define/PreparedStatementIgnoredSetterInstrumentation.java | 4 ++-- .../v8/define/PreparedStatementSetterInstrumentation.java | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) rename apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/{JDBCPreparedStatementSetterInstanceMethodsInterceptPoint.java => PSSetterDefinitionOfJDBCInstrumentation.java} (92%) diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java index 4a9dc847902e..2fce63283c71 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInterceptor.java @@ -35,7 +35,7 @@ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] MethodInterceptResult result) throws Throwable { final StatementEnhanceInfos statementEnhanceInfos = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); final int index = (Integer) allArguments[0]; - final Object parameter = allArguments[0]; + final Object parameter = allArguments[1]; statementEnhanceInfos.setParameter(index, parameter); } diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInstanceMethodsInterceptPoint.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java similarity index 92% rename from apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInstanceMethodsInterceptPoint.java rename to apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java index 646fa6b04648..fb7a4c060b07 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPreparedStatementSetterInstanceMethodsInterceptPoint.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java @@ -34,10 +34,10 @@ /** * @author kezhenxu94 */ -public class JDBCPreparedStatementSetterInstanceMethodsInterceptPoint implements InstanceMethodsInterceptPoint { +public class PSSetterDefinitionOfJDBCInstrumentation implements InstanceMethodsInterceptPoint { private final boolean ignorable; - public JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(boolean ignorable) { + public PSSetterDefinitionOfJDBCInstrumentation(boolean ignorable) { this.ignorable = ignorable; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java index 020f5c726611..3bf51bf38937 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java @@ -22,7 +22,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; @@ -42,7 +42,7 @@ protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(true) + new PSSetterDefinitionOfJDBCInstrumentation(true) }; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java index 29e514fc9b6e..88609f8211b4 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java @@ -22,7 +22,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; @@ -42,7 +42,7 @@ protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(false) + new PSSetterDefinitionOfJDBCInstrumentation(false) }; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java index 4c5df72e5e11..feb60912401f 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java @@ -22,7 +22,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; @@ -41,7 +41,7 @@ protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(true) + new PSSetterDefinitionOfJDBCInstrumentation(true) }; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java index 713e59fd0625..f59fd0090500 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java @@ -22,7 +22,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; @@ -41,7 +41,7 @@ protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(false) + new PSSetterDefinitionOfJDBCInstrumentation(false) }; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java index 54a5aa85bad6..9f7a01b6e4e6 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java @@ -22,7 +22,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; @@ -42,7 +42,7 @@ protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(true) + new PSSetterDefinitionOfJDBCInstrumentation(true) }; } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java index 5e59bdd3e986..efe9b15a5e8d 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java @@ -22,7 +22,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; @@ -42,7 +42,7 @@ protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new JDBCPreparedStatementSetterInstanceMethodsInterceptPoint(false) + new PSSetterDefinitionOfJDBCInstrumentation(false) }; } From 9e4f7d1138f34614afb2ee6883f6b6cba6181e14 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Tue, 18 Jun 2019 07:44:49 +0800 Subject: [PATCH 23/24] Fix 8.x bug --- .../define/PreparedStatementNullSetterInstrumentation.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java index cbf2c9878fc0..fb1dd01e703a 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java @@ -24,14 +24,15 @@ import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; -import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; /** * @author kezhenxu94 */ public class PreparedStatementNullSetterInstrumentation extends AbstractMysqlInstrumentation { - public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; + private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ClientPreparedStatement"; + private static final String PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement"; @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { @@ -47,7 +48,7 @@ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoint @Override protected ClassMatch enhanceClass() { - return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME); + return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME); } } From beab2b05f9248e5d5f77f8b001825f11db6c5dd2 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Tue, 18 Jun 2019 15:06:40 +0800 Subject: [PATCH 24/24] Adjust class hierarchy --- ...StatementIgnoredSetterInstrumentation.java | 21 +------------------ .../PreparedStatementInstrumentation.java | 14 ++++++------- ...redStatementNullSetterInstrumentation.java | 19 +---------------- ...reparedStatementSetterInstrumentation.java | 19 +---------------- ...StatementIgnoredSetterInstrumentation.java | 18 +--------------- .../PreparedStatementInstrumentation.java | 14 ++++++------- ...redStatementNullSetterInstrumentation.java | 18 +--------------- ...reparedStatementSetterInstrumentation.java | 18 +--------------- ...StatementIgnoredSetterInstrumentation.java | 19 +---------------- .../PreparedStatementInstrumentation.java | 2 +- ...redStatementNullSetterInstrumentation.java | 19 +---------------- ...reparedStatementSetterInstrumentation.java | 18 +--------------- 12 files changed, 24 insertions(+), 175 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java index 3bf51bf38937..99f1c648b822 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementIgnoredSetterInstrumentation.java @@ -19,36 +19,17 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; -import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; - /** * @author kezhenxu94 */ -public class PreparedStatementIgnoredSetterInstrumentation extends AbstractMysqlInstrumentation { - - private static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; - private static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - +public class PreparedStatementIgnoredSetterInstrumentation extends PreparedStatementInstrumentation { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { new PSSetterDefinitionOfJDBCInstrumentation(true) }; } - - @Override - protected ClassMatch enhanceClass() { - return byMultiClassMatch(MYSQL_PREPARED_STATEMENT_CLASS_NAME, JDBC42_PREPARED_STATEMENT_CLASS_NAME); - } - } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java index 77670ea053ea..0837b46ec86f 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementInstrumentation.java @@ -31,13 +31,13 @@ /** * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the - * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and + * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and * com.mysql.cj.jdbc.PreparedStatement class: - * 1. execute - * 2. executeQuery - * 3. executeUpdate - * 4. executeLargeUpdate - * 5. addBatch + * 1. execute + * 2. executeQuery + * 3. executeUpdate + * 4. executeLargeUpdate + * 5. addBatch * * @author zhangxin */ @@ -51,7 +51,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati return new ConstructorInterceptPoint[0]; } - @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java index 92637fbb1213..8e078b9b5c42 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementNullSetterInstrumentation.java @@ -19,25 +19,13 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; -import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; - /** * @author kezhenxu94 */ -public class PreparedStatementNullSetterInstrumentation extends AbstractMysqlInstrumentation { - - private static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; - private static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } +public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { @@ -46,9 +34,4 @@ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoint }; } - @Override - protected ClassMatch enhanceClass() { - return byMultiClassMatch(MYSQL_PREPARED_STATEMENT_CLASS_NAME, JDBC42_PREPARED_STATEMENT_CLASS_NAME); - } - } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java index 88609f8211b4..9acddbc48654 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/define/PreparedStatementSetterInstrumentation.java @@ -19,25 +19,13 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v5.define; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; -import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; - /** * @author kezhenxu94 */ -public class PreparedStatementSetterInstrumentation extends AbstractMysqlInstrumentation { - - private static final String MYSQL_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.PreparedStatement"; - private static final String JDBC42_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.jdbc.JDBC42PreparedStatement"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } +public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { @@ -46,9 +34,4 @@ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoint }; } - @Override - protected ClassMatch enhanceClass() { - return byMultiClassMatch(MYSQL_PREPARED_STATEMENT_CLASS_NAME, JDBC42_PREPARED_STATEMENT_CLASS_NAME); - } - } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java index feb60912401f..ea7d598d0257 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementIgnoredSetterInstrumentation.java @@ -19,24 +19,13 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; -import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - /** * @author kezhenxu94 */ -public class PreparedStatementIgnoredSetterInstrumentation extends AbstractMysqlInstrumentation { - - public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } +public class PreparedStatementIgnoredSetterInstrumentation extends PreparedStatementInstrumentation { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { @@ -45,9 +34,4 @@ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoint }; } - @Override - protected ClassMatch enhanceClass() { - return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME); - } - } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java index 89feca9332e7..958c4145fca3 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementInstrumentation.java @@ -30,13 +30,13 @@ /** * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the - * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and + * com.mysql.jdbc.JDBC42PreparedStatement, com.mysql.jdbc.PreparedStatement and * com.mysql.cj.jdbc.PreparedStatement class: - * 1. execute - * 2. executeQuery - * 3. executeUpdate - * 4. executeLargeUpdate - * 5. addBatch + * 1. execute + * 2. executeQuery + * 3. executeUpdate + * 4. executeLargeUpdate + * 5. addBatch * * @author zhangxin */ @@ -49,7 +49,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati return new ConstructorInterceptPoint[0]; } - @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java index e22eae548e91..023867460972 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementNullSetterInstrumentation.java @@ -19,24 +19,13 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; -import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - /** * @author kezhenxu94 */ -public class PreparedStatementNullSetterInstrumentation extends AbstractMysqlInstrumentation { - - public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } +public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { @@ -45,9 +34,4 @@ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoint }; } - @Override - protected ClassMatch enhanceClass() { - return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME); - } - } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java index f59fd0090500..24778ca8bf33 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v6/define/PreparedStatementSetterInstrumentation.java @@ -19,24 +19,13 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; -import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; - /** * @author kezhenxu94 */ -public class PreparedStatementSetterInstrumentation extends AbstractMysqlInstrumentation { - - public static final String MYSQL6_PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.PreparedStatement"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } +public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { @@ -45,9 +34,4 @@ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoint }; } - @Override - protected ClassMatch enhanceClass() { - return byName(MYSQL6_PREPARED_STATEMENT_CLASS_NAME); - } - } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java index 9f7a01b6e4e6..40dff470b596 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementIgnoredSetterInstrumentation.java @@ -19,25 +19,13 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; -import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; - /** * @author kezhenxu94 */ -public class PreparedStatementIgnoredSetterInstrumentation extends AbstractMysqlInstrumentation { - - private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ClientPreparedStatement"; - private static final String PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } +public class PreparedStatementIgnoredSetterInstrumentation extends PreparedStatementInstrumentation { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { @@ -46,9 +34,4 @@ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoint }; } - @Override - protected ClassMatch enhanceClass() { - return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME); - } - } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java index 183c45d290e8..180b0a009c7f 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementInstrumentation.java @@ -40,7 +40,7 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati return new ConstructorInterceptPoint[0]; } - @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java index fb1dd01e703a..8f47621dafbd 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementNullSetterInstrumentation.java @@ -19,25 +19,13 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint; -import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; - /** * @author kezhenxu94 */ -public class PreparedStatementNullSetterInstrumentation extends AbstractMysqlInstrumentation { - - private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ClientPreparedStatement"; - private static final String PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } +public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { @@ -46,9 +34,4 @@ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoint }; } - @Override - protected ClassMatch enhanceClass() { - return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME); - } - } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java index efe9b15a5e8d..12789f250e33 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v8/define/PreparedStatementSetterInstrumentation.java @@ -19,25 +19,13 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.v8.define; -import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation; -import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; - /** * @author kezhenxu94 */ -public class PreparedStatementSetterInstrumentation extends AbstractMysqlInstrumentation { - - private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ClientPreparedStatement"; - private static final String PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement"; - - @Override - protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } +public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation { @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { @@ -46,8 +34,4 @@ protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoint }; } - @Override - protected ClassMatch enhanceClass() { - return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME); - } }