Skip to content

Commit

Permalink
Merge pull request #1034 from emeroad/#117_refactoring_plugin_api
Browse files Browse the repository at this point in the history
#117 refactoring plugin api
  • Loading branch information
emeroad committed Oct 5, 2015
2 parents b96398b + 737561e commit 09905f4
Show file tree
Hide file tree
Showing 25 changed files with 207 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,27 @@ public interface InstrumentClass {
void addField(String accessorTypeName, String initValExp) throws InstrumentException;

void addGetter(String getterTypeName, String fieldName) throws InstrumentException;

int addInterceptor(String interceptorClassName, Object... constructorArgs) throws InstrumentException;

int addInterceptor(MethodFilter filter, String interceptorClassName, Object... constructorArgs) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, Object... constructorArgs) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException;

int addGroupedInterceptor(MethodFilter filter, String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException;
int addInterceptor(String interceptorClassName) throws InstrumentException;

int addInterceptor(String interceptorClassName, Object[] constructorArgs) throws InstrumentException;

int addInterceptor(MethodFilter filter, String interceptorClassName) throws InstrumentException;

int addInterceptor(MethodFilter filter, String interceptorClassName, Object[] constructorArgs) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException;

int addGroupedInterceptor(MethodFilter filter, String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException;

int addGroupedInterceptor(MethodFilter filter, String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException;

/**
* You should check that class already have Declared method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ public interface InstrumentMethod {
boolean isConstructor();

MethodDescriptor getDescriptor();

int addInterceptor(String interceptorClassName, Object... constructorArgs) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, Object... constructorArgs) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy, Object... constructorArgs) throws InstrumentException;
int addInterceptor(String interceptorClassName) throws InstrumentException;

int addInterceptor(String interceptorClassName, Object[] constructorArgs) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group) throws InstrumentException;

int addGroupedInterceptor(String interceptorClassName, Object[] constructorArgs, InterceptorGroup group, ExecutionPolicy executionPolicy) throws InstrumentException;

void addInterceptor(int interceptorId) throws InstrumentException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class PinpointClassFileTransformers {

public static PinpointClassFileTransformer addInterceptor(final String interceptorClassName, final Object... constructorArgs) {
public static PinpointClassFileTransformer addInterceptor(final String interceptorClassName, final Object[] constructorArgs) {
return new PinpointClassFileTransformer() {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2014 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.common.util;

public final class VarArgs {
private VarArgs() {
}

public static <T> T[] va(T... args) {
return args;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.navercorp.pinpoint.plugin.arcus.filter.ArcusMethodFilter;
import com.navercorp.pinpoint.plugin.arcus.filter.FrontCacheMemcachedMethodFilter;

import static com.navercorp.pinpoint.common.util.VarArgs.va;

/**
*
* @author jaehong.kim
Expand Down Expand Up @@ -89,7 +91,7 @@ public byte[] transform(Instrumentor context, ClassLoader loader, String classNa

for (InstrumentMethod m : target.getDeclaredMethods(new ArcusMethodFilter())) {
try {
m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", traceKey);
m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", va(traceKey));
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("Unsupported method " + className + "." + m.getName(), e);
Expand Down Expand Up @@ -165,7 +167,7 @@ public byte[] transform(Instrumentor context, ClassLoader loader, String classNa

for (InstrumentMethod m : target.getDeclaredMethods(new FrontCacheMemcachedMethodFilter())) {
try {
m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", traceKey);
m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", va(traceKey));
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("Unsupported method " + className + "." + m.getName(), e);
Expand Down Expand Up @@ -195,7 +197,7 @@ public byte[] transform(Instrumentor context, ClassLoader loader, String classNa

for (InstrumentMethod m : target.getDeclaredMethods(new FrontCacheMemcachedMethodFilter())) {
try {
m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", traceKey);
m.addInterceptor("com.navercorp.pinpoint.plugin.arcus.interceptor.ApiInterceptor", va(traceKey));
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("Unsupported method " + className + "." + m.getName(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;

import static com.navercorp.pinpoint.common.util.VarArgs.va;

/**
* @author Jongho Moon
*
Expand Down Expand Up @@ -81,7 +83,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri
InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer);
InterceptorGroup group = instrumentContext.getInterceptorGroup(CubridConstants.GROUP_CUBRID);

target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", group, ExecutionPolicy.ALWAYS, new CubridJdbcUrlParser());
target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.DriverConnectInterceptor", va(new CubridJdbcUrlParser()), group, ExecutionPolicy.ALWAYS);

return target.toBytecode();
}
Expand All @@ -102,7 +104,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader, Stri
int maxBindValueSize = config.getMaxSqlBindValueSize();
InterceptorGroup group = instrumentContext.getInterceptorGroup(CubridConstants.GROUP_CUBRID);

target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", group, maxBindValueSize);
target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementExecuteQueryInterceptor", va(maxBindValueSize), group);
target.addGroupedInterceptor("com.navercorp.pinpoint.bootstrap.plugin.jdbc.interceptor.PreparedStatementBindVariableInterceptor", group);

return target.toBytecode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;

import static com.navercorp.pinpoint.common.util.VarArgs.va;

/**
* @author netspider
* @author emeroad
Expand Down Expand Up @@ -142,17 +144,17 @@ private void injectHttpClientExecuteMethodWithHttpRequestInterceptor(InstrumentC
InstrumentMethod execute = target.getDeclaredMethod("execute", parameterTypeNames);

if (execute != null) {
execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpRequestInterceptor", isHasCallbackParam);
execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodInternalInterceptor", isHasCallbackParam);
execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpRequestInterceptor", va(isHasCallbackParam));
execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodInternalInterceptor", va(isHasCallbackParam));
}
}

private void injectHttpClientExecuteMethodWithHttpUriRequestInterceptor(InstrumentClass target, boolean isHasCallbackParam, String... parameterTypeNames) throws InstrumentException {
InstrumentMethod execute = target.getDeclaredMethod("execute", parameterTypeNames);

if (execute != null) {
execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpUriRequestInterceptor", isHasCallbackParam);
execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodInternalInterceptor", isHasCallbackParam);
execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpUriRequestInterceptor", va(isHasCallbackParam));
execute.addInterceptor("com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodInternalInterceptor", va(isHasCallbackParam));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.navercorp.pinpoint.plugin.ibatis;

import static com.navercorp.pinpoint.common.trace.HistogramSchema.NORMAL_SCHEMA;
import static com.navercorp.pinpoint.common.util.VarArgs.va;

import java.security.ProtectionDomain;
import java.util.List;

Expand Down Expand Up @@ -92,8 +95,8 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader loader,
final List<InstrumentMethod> methodsToTrace = target.getDeclaredMethods(methodFilter);
for (InstrumentMethod methodToTrace : methodsToTrace) {
String sqlMapOperationInterceptor = "com.navercorp.pinpoint.plugin.ibatis.interceptor.SqlMapOperationInterceptor";
methodToTrace.addGroupedInterceptor(sqlMapOperationInterceptor, group, ExecutionPolicy.BOUNDARY,
serviceType);
methodToTrace.addGroupedInterceptor(sqlMapOperationInterceptor, va(serviceType), group, ExecutionPolicy.BOUNDARY
);
}

return target.toBytecode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;

import static com.navercorp.pinpoint.common.util.VarArgs.va;

/**
* @author Sungkook Kim
*
Expand Down Expand Up @@ -62,16 +64,16 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader,
InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP);

final InstrumentMethod constructor1 = target.getConstructor();
addInterceptor(constructor1, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(constructor1, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);

final InstrumentMethod constructor2 = target.getConstructor("com.fasterxml.jackson.core.JsonFactory");
addInterceptor(constructor2, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(constructor2, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);

final InstrumentMethod constructor3 = target.getConstructor("com.fasterxml.jackson.core.JsonFactory", "com.fasterxml.jackson.databind.ser.DefaultSerializerProvider", "com.fasterxml.jackson.databind.deser.DefaultDeserializationContext");
addInterceptor(constructor3, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(constructor3, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);

for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValue"))) {
addInterceptor(method, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(method, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);
}

for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValueAsString"))) {
Expand Down Expand Up @@ -101,23 +103,23 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader,
InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP);

final InstrumentMethod constructor1 = target.getConstructor();
addInterceptor(constructor1, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(constructor1, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);

final InstrumentMethod constructor2 = target.getConstructor("org.codehaus.jackson.JsonFactory");
addInterceptor(constructor2, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(constructor2, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);

final InstrumentMethod constructor3 = target.getConstructor("org.codehaus.jackson.JsonFactory", "org.codehaus.jackson.map.SerializerProvider", "org.codehaus.jackson.map.DeserializerProvider");
addInterceptor(constructor3, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(constructor3, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);

final InstrumentMethod constructor4 = target.getConstructor("org.codehaus.jackson.map.SerializerFactory");
addInterceptor(constructor4, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(constructor4, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);

final InstrumentMethod constructor5 = target.getConstructor("org.codehaus.jackson.JsonFactory", "org.codehaus.jackson.map.SerializerProvider", "org.codehaus.jackson.map.DeserializerProvider", "org.codehaus.jackson.map.SerializationConfig", "org.codehaus.jackson.map.DeserializationConfig");
addInterceptor(constructor5, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(constructor5, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);


for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValue"))) {
addInterceptor(method, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(method, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);
}

for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValueAsString"))) {
Expand Down Expand Up @@ -166,7 +168,7 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader,
InterceptorGroup group = instrumentContext.getInterceptorGroup(GROUP);

for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValue"))) {
addInterceptor(method, BASIC_METHOD_INTERCEPTOR, group, JacksonConstants.SERVICE_TYPE);
addInterceptor(method, BASIC_METHOD_INTERCEPTOR, va(JacksonConstants.SERVICE_TYPE), group);
}

for (InstrumentMethod method : target.getDeclaredMethods(MethodFilters.name("writeValueAsString"))) {
Expand All @@ -183,10 +185,14 @@ public byte[] transform(Instrumentor instrumentContext, ClassLoader classLoader,
});
}

private boolean addInterceptor(InstrumentMethod method, String interceptorClassName, InterceptorGroup group, Object... constructorArgs) {
private boolean addInterceptor(InstrumentMethod method, String interceptorClassName, InterceptorGroup group) {
return addInterceptor(method, interceptorClassName, null, group);
}

private boolean addInterceptor(InstrumentMethod method, String interceptorClassName, Object[] constructorArgs, InterceptorGroup group) {
if (method != null) {
try {
method.addGroupedInterceptor(interceptorClassName, group, constructorArgs);
method.addGroupedInterceptor(interceptorClassName, constructorArgs, group);
return true;
} catch (InstrumentException e) {
if (logger.isWarnEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;

import static com.navercorp.pinpoint.common.util.VarArgs.va;

public class JettyPlugin implements ProfilerPlugin {

@Override
Expand All @@ -30,7 +32,7 @@ public void setup(ProfilerPluginSetupContext context) {
}

private void addServerInterceptor(ProfilerPluginSetupContext context, JettyConfiguration config){
context.addClassFileTransformer("org.eclipse.jetty.server.Server", PinpointClassFileTransformers.addInterceptor("com.navercorp.pinpoint.plugin.jetty.interceptor.ServerHandleInterceptor", config.getJettyExcludeUrlFilter()));
context.addClassFileTransformer("org.eclipse.jetty.server.Server", PinpointClassFileTransformers.addInterceptor("com.navercorp.pinpoint.plugin.jetty.interceptor.ServerHandleInterceptor", va(config.getJettyExcludeUrlFilter())));
}

private void addRequestEditor(ProfilerPluginSetupContext context) {
Expand Down
Loading

0 comments on commit 09905f4

Please # to comment.