Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Agent] Support jdbc4, jdbc3 and jdbc42 of postgresql driver #743

Merged
merged 2 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
*/


package org.apache.skywalking.apm.plugin.jdbc.mysql.define;
package org.apache.skywalking.apm.agent.core.plugin.match;

import java.util.Arrays;
import java.util.List;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.IndirectMatch;

import static net.bytebuddy.matcher.ElementMatchers.named;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;

import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;

/**
* {@link CallableInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;

import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;

/**
* {@link DriverInstrumentation} presents that skywalking intercepts {@link com.mysql.jdbc.Driver}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;

import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;

/**
* {@link Mysql5xConnectionInstrumentation } interceptor {@link com.mysql.cj.jdbc.ConnectionImpl} and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;

import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;

/**
* {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;

import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch;
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;

/**
* {@link StatementInstrumentation} intercepts the following methods in the {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;

/**
* {@link AbstractJdbc2StatementInstrumentation} intercept the following methods that the class which extend {@link
Expand Down Expand Up @@ -61,16 +62,27 @@ public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsE
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("execute").and(takesArguments(0))
.or(named("execute").and(takesArguments(1)))
.or(named("executeBatch"))
.or(named("executeQuery").and(takesArguments(0)))
.or(named("executeUpdate").and(takesArguments(0)));
}

@Override public String getMethodsInterceptor() {
return PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
}

@Override public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("execute").and(takesArguments(1))
.or(named("executeQuery").and(takesArguments(1)))
.or(named("executeUpdate").and(takesArguments(0)))
.or(named("executeUpdate").and(takesArguments(1)));
}

@Override public String getMethodsInterceptor() {
return PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
return PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
}

@Override public boolean isOverrideArgs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;

/**
* {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link
Expand All @@ -49,8 +49,11 @@
public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {

private static final String PREPARE_STATEMENT_METHOD_WITH_STRING_ARRAY_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.JDBCPrepareStatementWithStringArrayInterceptor";
public static final String ENHANCE_CLASS = "org.postgresql.jdbc.PgConnection";
public static final String PG_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc.PgConnection";
public static final String STRING_ARRAY_ARGUMENT_TYPE = "java.lang.String[]";
public static final String PG_JDBC42_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc42.Jdbc42Connection";
public static final String PG_JDBC3_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc3g.Jdbc3gConnection";
public static final String PG_JDBC4_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc4.Jdbc4Connection";

@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
Expand Down Expand Up @@ -127,6 +130,6 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin
}

@Override protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
return byMultiClassMatch(PG_CONNECTION_ENHANCE_CLASS, PG_JDBC42_CONNECTION_ENHANCE_CLASS, PG_JDBC3_CONNECTION_ENHANCE_CLASS, PG_JDBC4_CONNECTION_ENHANCE_CLASS);
}
}