From 7b8aae4001c18acb14a9fa440e4fc75de7323197 Mon Sep 17 00:00:00 2001 From: Jongho Moon Date: Thu, 10 Sep 2015 16:12:40 +0900 Subject: [PATCH] Extract ning async-http-client profiler as a plugin --- agent/pom.xml | 25 ++- .../NingAsyncHttpClientIT.java | 45 ++++++ .../bootstrap/config/ProfilerConfig.java | 116 -------------- .../pinpoint/common/trace/ServiceType.java | 4 +- plugins/ning-asynchttpclient/.gitignore | 5 + plugins/ning-asynchttpclient/clover.license | 5 + plugins/ning-asynchttpclient/pom.xml | 27 ++++ .../NingAsyncHttpClientMetadataProvider.java | 36 +++++ .../NingAsyncHttpClientPlugin.java | 55 +++++++ .../NingAsyncHttpClientPluginConfig.java | 105 +++++++++++++ .../ExecuteRequestInterceptor.java | 147 ++++++++---------- ...p.pinpoint.bootstrap.plugin.ProfilerPlugin | 1 + ...inpoint.common.trace.TraceMetadataProvider | 1 + .../jdbc/oracle/OracleTypeProvider.java | 6 +- plugins/pom.xml | 6 + .../ClassFileTransformerDispatcher.java | 3 - .../modifier/DefaultModifierRegistry.java | 5 - .../monitor/metric/DefaultRpcMetricTest.java | 10 +- .../monitor/metric/MetricRegistryTest.java | 10 +- 19 files changed, 379 insertions(+), 233 deletions(-) create mode 100644 agent/src/test/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientIT.java create mode 100644 plugins/ning-asynchttpclient/.gitignore create mode 100644 plugins/ning-asynchttpclient/clover.license create mode 100644 plugins/ning-asynchttpclient/pom.xml create mode 100644 plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientMetadataProvider.java create mode 100644 plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientPlugin.java create mode 100644 plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientPluginConfig.java create mode 100644 plugins/ning-asynchttpclient/src/main/resources/META-INF/services/com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin create mode 100644 plugins/ning-asynchttpclient/src/main/resources/META-INF/services/com.navercorp.pinpoint.common.trace.TraceMetadataProvider diff --git a/agent/pom.xml b/agent/pom.xml index bed9ad402064..a59627a21dd2 100644 --- a/agent/pom.xml +++ b/agent/pom.xml @@ -116,37 +116,32 @@ org.apache.httpcomponents httpcore - provided + test org.apache.httpcomponents httpasyncclient - provided + test org.apache.httpcomponents httpcore-nio - provided + test org.apache.httpcomponents httpclient - provided - - - commons-codec - commons-codec - - - commons-logging - commons-logging - - + test commons-httpclient commons-httpclient - provided + test + + + com.ning + async-http-client + test diff --git a/agent/src/test/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientIT.java b/agent/src/test/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientIT.java new file mode 100644 index 000000000000..0604ca8f2cde --- /dev/null +++ b/agent/src/test/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientIT.java @@ -0,0 +1,45 @@ +package com.navercorp.pinpoint.plugin.ning.asynchttpclient; + +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.*; + +import java.util.concurrent.Future; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier; +import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder; +import com.navercorp.pinpoint.test.plugin.Dependency; +import com.navercorp.pinpoint.test.plugin.JvmVersion; +import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import com.ning.http.client.AsyncHandler; +import com.ning.http.client.AsyncHttpClient; +import com.ning.http.client.Request; +import com.ning.http.client.Response; + +/** + * @author netspider + */ +@RunWith(PinpointPluginTestSuite.class) +@Dependency({ "com.ning:async-http-client:[1.7.24],[1.8.16,1.8.999)" }) +@JvmVersion(7) +public class NingAsyncHttpClientIT { + + @Test + public void test() throws Exception { + AsyncHttpClient client = new AsyncHttpClient(); + + try { + Future f = client.preparePost("http://www.naver.com/").addParameter("param1", "value1").execute(); + Response response = f.get(); + } finally { + client.close(); + } + + PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); + verifier.printCache(); + + verifier.verifyTrace(event("ASYNC_HTTP_CLIENT", AsyncHttpClient.class.getMethod("executeRequest", Request.class, AsyncHandler.class), null, null, "www.naver.com", annotation("http.url", "http://www.naver.com"), annotation("http.param", "param1=value1"))); + verifier.verifyTraceCount(0); + } +} \ No newline at end of file diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java index d804ed3a6a7f..58688189a293 100644 --- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java +++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java @@ -149,23 +149,6 @@ public static ProfilerConfig load(String pinpointConfigFileName) throws IOExcept */ private boolean apacheNIOHttpClient4Profile = true; - /** - * ning async http client - */ - private boolean ningAsyncHttpClientProfile = true; - private boolean ningAsyncHttpClientProfileCookie = false; - private DumpType ningAsyncHttpClientProfileCookieDumpType = DumpType.EXCEPTION; - private int ningAsyncHttpClientProfileCookieDumpSize = 1024; - private int ningAsyncHttpClientProfileCookieSamplingRate = 1; - private boolean ningAsyncHttpClientProfileEntity = false; - private DumpType ningAsyncHttpClientProfileEntityDumpType = DumpType.EXCEPTION; - private int ningAsyncHttpClientProfileEntityDumpSize = 1024; - private int ningAsyncHttpClientProfileEntitySamplingRate = 1; - private boolean ningAsyncHttpClientProfileParam = false; - private DumpType ningAsyncHttpClientProfileParamDumpType = DumpType.EXCEPTION; - private int ningAsyncHttpClientProfileParamDumpSize = 1024; - private int ningAsyncHttpClientProfileParamSamplingRate = 1; - // Sampling private boolean samplingEnable = true; private int samplingRate = 1; @@ -385,60 +368,6 @@ public boolean getApacheNIOHttpClient4Profile() { return apacheNIOHttpClient4Profile; } - //----------------------------------------- - // com/ning/http/client/AsyncHttpClient - public boolean isNingAsyncHttpClientProfile() { - return ningAsyncHttpClientProfile; - } - - public boolean isNingAsyncHttpClientProfileCookie() { - return ningAsyncHttpClientProfileCookie; - } - - public DumpType getNingAsyncHttpClientProfileCookieDumpType() { - return ningAsyncHttpClientProfileCookieDumpType; - } - - public int getNingAsyncHttpClientProfileCookieDumpSize() { - return ningAsyncHttpClientProfileCookieDumpSize; - } - - public int getNingAsyncHttpClientProfileCookieSamplingRate() { - return ningAsyncHttpClientProfileCookieSamplingRate; - } - - public boolean isNingAsyncHttpClientProfileEntity() { - return ningAsyncHttpClientProfileEntity; - } - - public DumpType getNingAsyncHttpClientProfileEntityDumpType() { - return ningAsyncHttpClientProfileEntityDumpType; - } - - public int getNingAsyncHttpClientProfileEntityDumpSize() { - return ningAsyncHttpClientProfileEntityDumpSize; - } - - public int getNingAsyncHttpClientProfileEntitySamplingRate() { - return ningAsyncHttpClientProfileEntitySamplingRate; - } - - public boolean isNingAsyncHttpClientProfileParam() { - return ningAsyncHttpClientProfileParam; - } - - public DumpType getNingAsyncHttpClientProfileParamDumpType() { - return ningAsyncHttpClientProfileParamDumpType; - } - - public int getNingAsyncHttpClientProfileParamDumpSize() { - return ningAsyncHttpClientProfileParamDumpSize; - } - - public int getNingAsyncHttpClientProfileParamSamplingRate() { - return ningAsyncHttpClientProfileParamSamplingRate; - } - public boolean isIBatisEnabled() { return ibatis; } @@ -577,25 +506,6 @@ void readPropertyValues() { */ this.apacheNIOHttpClient4Profile = readBoolean("profiler.apache.nio.httpclient4", true); - /** - * ning.async http client - */ - this.ningAsyncHttpClientProfile = readBoolean("profiler.ning.asynchttpclient", true); - this.ningAsyncHttpClientProfileCookie = readBoolean("profiler.ning.asynchttpclient.cookie", false); - this.ningAsyncHttpClientProfileCookieDumpType = readDumpType("profiler.ning.asynchttpclient.cookie.dumptype", DumpType.EXCEPTION); - this.ningAsyncHttpClientProfileCookieDumpSize = readInt("profiler.ning.asynchttpclient.cookie.dumpsize", 1024); - this.ningAsyncHttpClientProfileCookieSamplingRate = readInt("profiler.ning.asynchttpclient.cookie.sampling.rate", 1); - - this.ningAsyncHttpClientProfileEntity = readBoolean("profiler.ning.asynchttpclient.entity", false); - this.ningAsyncHttpClientProfileEntityDumpType = readDumpType("profiler.ning.asynchttpclient.entity.dumptype", DumpType.EXCEPTION); - this.ningAsyncHttpClientProfileEntityDumpSize = readInt("profiler.ning.asynchttpclient.entity.dumpsize", 1024); - this.ningAsyncHttpClientProfileEntitySamplingRate = readInt("profiler.asynchttpclient.entity.sampling.rate", 1); - - this.ningAsyncHttpClientProfileParam = readBoolean("profiler.ning.asynchttpclient.param", false); - this.ningAsyncHttpClientProfileParamDumpType = readDumpType("profiler.ning.asynchttpclient.param.dumptype", DumpType.EXCEPTION); - this.ningAsyncHttpClientProfileParamDumpSize = readInt("profiler.ning.asynchttpclient.param.dumpsize", 1024); - this.ningAsyncHttpClientProfileParamSamplingRate = readInt("profiler.asynchttpclient.param.sampling.rate", 1); - /** * log4j */ @@ -814,32 +724,6 @@ public String toString() { builder.append(apacheHttpClient4ProfileIo); builder.append(", apacheNIOHttpClient4Profile="); builder.append(apacheNIOHttpClient4Profile); - builder.append(", ningAsyncHttpClientProfile="); - builder.append(ningAsyncHttpClientProfile); - builder.append(", ningAsyncHttpClientProfileCookie="); - builder.append(ningAsyncHttpClientProfileCookie); - builder.append(", ningAsyncHttpClientProfileCookieDumpType="); - builder.append(ningAsyncHttpClientProfileCookieDumpType); - builder.append(", ningAsyncHttpClientProfileCookieDumpSize="); - builder.append(ningAsyncHttpClientProfileCookieDumpSize); - builder.append(", ningAsyncHttpClientProfileCookieSamplingRate="); - builder.append(ningAsyncHttpClientProfileCookieSamplingRate); - builder.append(", ningAsyncHttpClientProfileEntity="); - builder.append(ningAsyncHttpClientProfileEntity); - builder.append(", ningAsyncHttpClientProfileEntityDumpType="); - builder.append(ningAsyncHttpClientProfileEntityDumpType); - builder.append(", ningAsyncHttpClientProfileEntityDumpSize="); - builder.append(ningAsyncHttpClientProfileEntityDumpSize); - builder.append(", ningAsyncHttpClientProfileEntitySamplingRate="); - builder.append(ningAsyncHttpClientProfileEntitySamplingRate); - builder.append(", ningAsyncHttpClientProfileParam="); - builder.append(ningAsyncHttpClientProfileParam); - builder.append(", ningAsyncHttpClientProfileParamDumpType="); - builder.append(ningAsyncHttpClientProfileParamDumpType); - builder.append(", ningAsyncHttpClientProfileParamDumpSize="); - builder.append(ningAsyncHttpClientProfileParamDumpSize); - builder.append(", ningAsyncHttpClientProfileParamSamplingRate="); - builder.append(ningAsyncHttpClientProfileParamSamplingRate); builder.append(", samplingEnable="); builder.append(samplingEnable); builder.append(", samplingRate="); diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/trace/ServiceType.java b/commons/src/main/java/com/navercorp/pinpoint/common/trace/ServiceType.java index 842656217c9a..2b98a45b6cee 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/trace/ServiceType.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/trace/ServiceType.java @@ -302,8 +302,8 @@ public boolean equals(Object obj) { // 9053 HTTP_CLIENT_4_INTERNAL // 9054 GOOGLE_HTTP_CLIENT_INTERNAL // public static final ServiceType JDK_HTTPURLCONNECTOR = of(9055, "JDK_HTTPURLCONNECTOR", "JDK_HTTPCONNECTOR", NORMAL_SCHEMA); - public static final ServiceType ASYNC_HTTP_CLIENT = of(9056, "ASYNC_HTTP_CLIENT", NORMAL_SCHEMA, RECORD_STATISTICS); - public static final ServiceType ASYNC_HTTP_CLIENT_INTERNAL = of(9057, "ASYNC_HTTP_CLIENT_INTERNAL", "ASYNC_HTTP_CLIENT", NORMAL_SCHEMA); +// public static final ServiceType ASYNC_HTTP_CLIENT = of(9056, "ASYNC_HTTP_CLIENT", NORMAL_SCHEMA, RECORD_STATISTICS); +// public static final ServiceType ASYNC_HTTP_CLIENT_INTERNAL = of(9057, "ASYNC_HTTP_CLIENT_INTERNAL", "ASYNC_HTTP_CLIENT", NORMAL_SCHEMA); // public static final ServiceType NPC_CLIENT = of(9060, "NPC_CLIENT", NORMAL_SCHEMA, RECORD_STATISTICS); public static final ServiceType NIMM_CLIENT = of(9070, "NIMM_CLIENT", NORMAL_SCHEMA, RECORD_STATISTICS); diff --git a/plugins/ning-asynchttpclient/.gitignore b/plugins/ning-asynchttpclient/.gitignore new file mode 100644 index 000000000000..8c2d47305b59 --- /dev/null +++ b/plugins/ning-asynchttpclient/.gitignore @@ -0,0 +1,5 @@ +/target/ +/.settings/ +/.classpath +/.project +/*.iml diff --git a/plugins/ning-asynchttpclient/clover.license b/plugins/ning-asynchttpclient/clover.license new file mode 100644 index 000000000000..569fa6175b4c --- /dev/null +++ b/plugins/ning-asynchttpclient/clover.license @@ -0,0 +1,5 @@ +RMRqrdbgbKFhbaVnDxHUdDQvrOQXxIBklnvcmahheubVC +mh2KM35CLkwUHS4DH7QVhxy52J5hnWbyEm6Cyd3KkF + 4.0.0 + + com.navercorp.pinpoint + pom + ../.. + 1.5.0-SNAPSHOT + + + pinpoint-ning-asynchttpclient-plugin + pinpoint-ning-asynchttpclient-plugin + jar + + + + com.navercorp.pinpoint + pinpoint-bootstrap-core + provided + + + com.ning + async-http-client + provided + + + diff --git a/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientMetadataProvider.java b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientMetadataProvider.java new file mode 100644 index 000000000000..f49375dd0ae0 --- /dev/null +++ b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientMetadataProvider.java @@ -0,0 +1,36 @@ +/* + * 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.plugin.ning.asynchttpclient; + +import com.navercorp.pinpoint.common.trace.AnnotationKey; +import com.navercorp.pinpoint.common.trace.AnnotationKeyMatchers; +import com.navercorp.pinpoint.common.trace.TraceMetadataProvider; +import com.navercorp.pinpoint.common.trace.TraceMetadataSetupContext; + +/** + * + * @author jaehong.kim + * + */ +public class NingAsyncHttpClientMetadataProvider implements TraceMetadataProvider { + + @Override + public void setup(TraceMetadataSetupContext context) { + context.addServiceType(NingAsyncHttpClientPlugin.ASYNC_HTTP_CLIENT, AnnotationKeyMatchers.exact(AnnotationKey.HTTP_URL)); + context.addServiceType(NingAsyncHttpClientPlugin.ASYNC_HTTP_CLIENT_INTERNAL, AnnotationKeyMatchers.exact(AnnotationKey.HTTP_INTERNAL_DISPLAY)); + } + +} diff --git a/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientPlugin.java b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientPlugin.java new file mode 100644 index 000000000000..bc82c9e11b49 --- /dev/null +++ b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientPlugin.java @@ -0,0 +1,55 @@ +/* + * 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.plugin.ning.asynchttpclient; + +import static com.navercorp.pinpoint.common.trace.HistogramSchema.*; +import static com.navercorp.pinpoint.common.trace.ServiceTypeProperty.*; + +import java.security.ProtectionDomain; + +import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass; +import com.navercorp.pinpoint.bootstrap.instrument.InstrumentException; +import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin; +import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginInstrumentContext; +import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext; +import com.navercorp.pinpoint.bootstrap.plugin.transformer.PinpointClassFileTransformer; +import com.navercorp.pinpoint.common.trace.ServiceType; + +/** + * @author netspider + * @author emeroad + * @author minwoo.jung + * @author jaehong.kim + * + */ +public class NingAsyncHttpClientPlugin implements ProfilerPlugin { + public static final ServiceType ASYNC_HTTP_CLIENT = ServiceType.of(9056, "ASYNC_HTTP_CLIENT", NORMAL_SCHEMA, RECORD_STATISTICS); + public static final ServiceType ASYNC_HTTP_CLIENT_INTERNAL = ServiceType.of(9057, "ASYNC_HTTP_CLIENT_INTERNAL", "ASYNC_HTTP_CLIENT", NORMAL_SCHEMA); + + @Override + public void setup(ProfilerPluginSetupContext context) { + context.addClassFileTransformer("com.ning.http.client.AsyncHttpClient", new PinpointClassFileTransformer() { + + @Override + public byte[] transform(ProfilerPluginInstrumentContext instrumentContext, ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException { + InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer); + target.addInterceptor("com.navercorp.pinpoint.plugin.ning.asynchttpclient.interceptor.ExecuteRequestInterceptor"); + + return target.toBytecode(); + } + }); + } +} \ No newline at end of file diff --git a/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientPluginConfig.java b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientPluginConfig.java new file mode 100644 index 000000000000..00d211919583 --- /dev/null +++ b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientPluginConfig.java @@ -0,0 +1,105 @@ +/* + * 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.plugin.ning.asynchttpclient; + +import com.navercorp.pinpoint.bootstrap.config.DumpType; +import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; + +/** + * + * @author jaehong.kim + * + */ +public class NingAsyncHttpClientPluginConfig { + private final boolean profileCookie; + private final DumpType cookieDumpType; + private final int cookieDumpSize; + private final int cookieSamplingRate; + private final boolean profileEntity; + private final DumpType entityDumpType; + private final int entityDumpSize; + private final int entitySamplingRate; + private final boolean profileParam; + private final DumpType paramDumpType; + private final int paramDumpSize; + private final int paramSamplingRate; + + public NingAsyncHttpClientPluginConfig(ProfilerConfig src) { + this.profileCookie = src.readBoolean("profiler.ning.asynchttpclient.cookie", false); + this.cookieDumpType = src.readDumpType("profiler.ning.asynchttpclient.cookie.dumptype", DumpType.EXCEPTION); + this.cookieDumpSize = src.readInt("profiler.ning.asynchttpclient.cookie.dumpsize", 1024); + this.cookieSamplingRate = src.readInt("profiler.ning.asynchttpclient.cookie.sampling.rate", 1); + + this.profileEntity = src.readBoolean("profiler.ning.asynchttpclient.entity", false); + this.entityDumpType = src.readDumpType("profiler.ning.asynchttpclient.entity.dumptype", DumpType.EXCEPTION); + this.entityDumpSize = src.readInt("profiler.ning.asynchttpclient.entity.dumpsize", 1024); + this.entitySamplingRate = src.readInt("profiler.asynchttpclient.entity.sampling.rate", 1); + + this.profileParam = src.readBoolean("profiler.ning.asynchttpclient.param", false); + this.paramDumpType = src.readDumpType("profiler.ning.asynchttpclient.param.dumptype", DumpType.EXCEPTION); + this.paramDumpSize = src.readInt("profiler.ning.asynchttpclient.param.dumpsize", 1024); + this.paramSamplingRate = src.readInt("profiler.asynchttpclient.param.sampling.rate", 1); + + } + + public boolean isProfileCookie() { + return profileCookie; + } + + public DumpType getCookieDumpType() { + return cookieDumpType; + } + + public int getCookieDumpSize() { + return cookieDumpSize; + } + + public int getCookieSamplingRate() { + return cookieSamplingRate; + } + + public boolean isProfileEntity() { + return profileEntity; + } + + public DumpType getEntityDumpType() { + return entityDumpType; + } + + public int getEntityDumpSize() { + return entityDumpSize; + } + + public int getEntitySamplingRate() { + return entitySamplingRate; + } + + public boolean isProfileParam() { + return profileParam; + } + + public DumpType getParamDumpType() { + return paramDumpType; + } + + public int getParamDumpSize() { + return paramDumpSize; + } + + public int getParamSamplingRate() { + return paramSamplingRate; + } +} diff --git a/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/interceptor/ExecuteRequestInterceptor.java b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/interceptor/ExecuteRequestInterceptor.java index 7df5f747e74c..5c8c795ef2b2 100644 --- a/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/interceptor/ExecuteRequestInterceptor.java +++ b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/interceptor/ExecuteRequestInterceptor.java @@ -14,32 +14,33 @@ * limitations under the License. */ -package com.navercorp.pinpoint.profiler.modifier.connector.asynchttpclient.interceptor; +package com.navercorp.pinpoint.plugin.ning.asynchttpclient.interceptor; import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; -import com.navercorp.pinpoint.bootstrap.config.DumpType; -import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; import com.navercorp.pinpoint.bootstrap.context.Header; import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; import com.navercorp.pinpoint.bootstrap.context.TraceId; -import com.navercorp.pinpoint.bootstrap.interceptor.ByteCodeMethodDescriptorSupport; import com.navercorp.pinpoint.bootstrap.interceptor.MethodDescriptor; import com.navercorp.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; -import com.navercorp.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.navercorp.pinpoint.bootstrap.interceptor.TraceContextSupport; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.plugin.annotation.TargetMethod; import com.navercorp.pinpoint.bootstrap.sampler.SamplingFlagUtils; import com.navercorp.pinpoint.bootstrap.util.InterceptorUtils; import com.navercorp.pinpoint.bootstrap.util.SimpleSampler; import com.navercorp.pinpoint.bootstrap.util.SimpleSamplerFactory; import com.navercorp.pinpoint.bootstrap.util.StringUtils; import com.navercorp.pinpoint.common.trace.AnnotationKey; -import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.plugin.ning.asynchttpclient.NingAsyncHttpClientPlugin; +import com.navercorp.pinpoint.plugin.ning.asynchttpclient.NingAsyncHttpClientPluginConfig; import com.ning.http.client.FluentCaseInsensitiveStringsMap; import com.ning.http.client.FluentStringsMap; import com.ning.http.client.Part; @@ -53,29 +54,29 @@ * @author netspider * */ -public class ExecuteRequestInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport, TargetClassLoader { +@TargetMethod(name="executeRequest", paramTypes= { "com.ning.http.client.Request", "com.ning.http.client.AsyncHandler" }) +public class ExecuteRequestInterceptor implements SimpleAroundInterceptor { - protected final PLogger logger = PLoggerFactory.getLogger(ExecuteRequestInterceptor.class); - protected final boolean isDebug = logger.isDebugEnabled(); + private final PLogger logger = PLoggerFactory.getLogger(ExecuteRequestInterceptor.class); + private final boolean isDebug = logger.isDebugEnabled(); - protected TraceContext traceContext; - protected MethodDescriptor descriptor; - - protected boolean dumpCookie; - protected DumpType cookieDumpType; - protected SimpleSampler cookieSampler; - protected int cookieDumpSize; - - protected boolean dumpEntity; - protected DumpType entityDumpType; - protected SimpleSampler entitySampler; - protected int entityDumpSize; - - protected boolean dumpParam; - protected DumpType paramDumpType; - protected SimpleSampler paramSampler; - protected int paramDumpSize; + private final TraceContext traceContext; + private final MethodDescriptor descriptor; + private final NingAsyncHttpClientPluginConfig config; + + private final SimpleSampler cookieSampler; + private final SimpleSampler entitySampler; + private final SimpleSampler paramSampler; + public ExecuteRequestInterceptor(TraceContext traceContext, MethodDescriptor descriptor) { + this.traceContext = traceContext; + this.descriptor = descriptor; + this.config = new NingAsyncHttpClientPluginConfig(traceContext.getProfilerConfig()); + + this.cookieSampler = config.isProfileCookie() ? SimpleSamplerFactory.createSampler(true, config.getCookieSamplingRate()) : null; + this.entitySampler = config.isProfileEntity() ? SimpleSamplerFactory.createSampler(true, config.getEntitySamplingRate()) : null; + this.paramSampler = config.isProfileParam() ? SimpleSamplerFactory.createSampler(true, config.getParamSamplingRate()) : null; + } @Override public void before(Object target, Object[] args) { @@ -111,7 +112,7 @@ public void before(Object target, Object[] args) { SpanEventRecorder recorder = trace.currentSpanEventRecorder(); TraceId nextId = trace.getTraceId().getNextTraceId(); recorder.recordNextSpanId(nextId.getSpanId()); - recorder.recordServiceType(ServiceType.ASYNC_HTTP_CLIENT); + recorder.recordServiceType(NingAsyncHttpClientPlugin.ASYNC_HTTP_CLIENT); if (httpRequest != null) { final FluentCaseInsensitiveStringsMap httpRequestHeaders = httpRequest.getHeaders(); @@ -186,25 +187,40 @@ private String getEndpoint(String host, int port) { private void recordHttpRequest(SpanEventRecorder recorder, com.ning.http.client.Request httpRequest, Throwable throwable) { final boolean isException = InterceptorUtils.isThrowable(throwable); - if (dumpCookie) { - if (DumpType.ALWAYS == cookieDumpType) { - recordCookie(httpRequest, recorder); - } else if (DumpType.EXCEPTION == cookieDumpType && isException) { + if (config.isProfileCookie()) { + switch (config.getCookieDumpType()) { + case ALWAYS: recordCookie(httpRequest, recorder); + break; + case EXCEPTION: + if (isException) { + recordCookie(httpRequest, recorder); + } + break; } } - if (dumpEntity) { - if (DumpType.ALWAYS == entityDumpType) { - recordEntity(httpRequest, recorder); - } else if (DumpType.EXCEPTION == entityDumpType && isException) { + if (config.isProfileEntity()) { + switch (config.getEntityDumpType()) { + case ALWAYS: recordEntity(httpRequest, recorder); + break; + case EXCEPTION: + if (isException) { + recordEntity(httpRequest, recorder); + } + break; } } - if (dumpParam) { - if (DumpType.ALWAYS == paramDumpType) { - recordParam(httpRequest, recorder); - } else if (DumpType.EXCEPTION == paramDumpType && isException) { + if (config.isProfileParam()) { + switch (config.getParamDumpType()) { + case ALWAYS: recordParam(httpRequest, recorder); + break; + case EXCEPTION: + if (isException) { + recordParam(httpRequest, recorder); + } + break; } } } @@ -217,7 +233,7 @@ protected void recordCookie(com.ning.http.client.Request httpRequest, SpanEventR return; } - StringBuilder sb = new StringBuilder(cookieDumpSize * 2); + StringBuilder sb = new StringBuilder(config.getCookieDumpSize() * 2); Iterator iterator = cookies.iterator(); while (iterator.hasNext()) { Cookie cookie = iterator.next(); @@ -226,7 +242,7 @@ protected void recordCookie(com.ning.http.client.Request httpRequest, SpanEventR sb.append(","); } } - recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(sb.toString(), cookieDumpSize)); + recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(sb.toString(), config.getCookieDumpSize())); } } @@ -249,7 +265,7 @@ protected void recordEntity(final com.ning.http.client.Request httpRequest, fina protected void recordNonMultipartData(final com.ning.http.client.Request httpRequest, final SpanEventRecorder recorder) { final String stringData = httpRequest.getStringData(); if (stringData != null) { - recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, StringUtils.drop(stringData, entityDumpSize)); + recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, StringUtils.drop(stringData, config.getEntityDumpSize())); return; } @@ -281,7 +297,7 @@ protected void recordNonMultipartData(final com.ning.http.client.Request httpReq protected void recordMultipartData(final com.ning.http.client.Request httpRequest, final SpanEventRecorder recorder) { List parts = httpRequest.getParts(); if (parts != null && parts.isEmpty()) { - StringBuilder sb = new StringBuilder(entityDumpSize * 2); + StringBuilder sb = new StringBuilder(config.getEntityDumpSize() * 2); Iterator iterator = parts.iterator(); while (iterator.hasNext()) { Part part = iterator.next(); @@ -312,7 +328,7 @@ protected void recordMultipartData(final com.ning.http.client.Request httpReques sb.append("=STRING"); } - if (sb.length() >= entityDumpSize) { + if (sb.length() >= config.getEntityDumpSize()) { break; } @@ -320,7 +336,7 @@ protected void recordMultipartData(final com.ning.http.client.Request httpReques sb.append(","); } } - recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, StringUtils.drop(sb.toString(), entityDumpSize)); + recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, StringUtils.drop(sb.toString(), config.getEntityDumpSize())); } } @@ -334,8 +350,8 @@ protected void recordParam(final com.ning.http.client.Request httpRequest, final if (paramSampler.isSampling()) { FluentStringsMap requestParams = httpRequest.getParams(); if (requestParams != null) { - String params = paramsToString(requestParams, paramDumpSize); - recorder.recordAttribute(AnnotationKey.HTTP_PARAM, StringUtils.drop(params, paramDumpSize)); + String params = paramsToString(requestParams, config.getParamDumpSize()); + recorder.recordAttribute(AnnotationKey.HTTP_PARAM, StringUtils.drop(params, config.getParamDumpSize())); } } } @@ -374,37 +390,4 @@ private String paramsToString(FluentStringsMap params, int limit) { } return result.toString(); } - - @Override - public void setTraceContext(TraceContext traceContext) { - this.traceContext = traceContext; - - final ProfilerConfig profilerConfig = traceContext.getProfilerConfig(); - this.dumpCookie = profilerConfig.isNingAsyncHttpClientProfileCookie(); - this.cookieDumpType = profilerConfig.getNingAsyncHttpClientProfileCookieDumpType(); - this.cookieDumpSize = profilerConfig.getNingAsyncHttpClientProfileCookieDumpSize(); - if (dumpCookie) { - this.cookieSampler = SimpleSamplerFactory.createSampler(dumpCookie, profilerConfig.getNingAsyncHttpClientProfileCookieSamplingRate()); - } - - this.dumpEntity = profilerConfig.isNingAsyncHttpClientProfileEntity(); - this.entityDumpType = profilerConfig.getNingAsyncHttpClientProfileEntityDumpType(); - this.entityDumpSize = profilerConfig.getNingAsyncHttpClientProfileEntityDumpSize(); - if (dumpEntity) { - this.entitySampler = SimpleSamplerFactory.createSampler(dumpEntity, profilerConfig.getNingAsyncHttpClientProfileEntitySamplingRate()); - } - - this.dumpParam = profilerConfig.isNingAsyncHttpClientProfileParam(); - this.paramDumpType = profilerConfig.getNingAsyncHttpClientProfileParamDumpType(); - this.paramDumpSize = profilerConfig.getNingAsyncHttpClientProfileParamDumpSize(); - if (dumpParam) { - this.paramSampler = SimpleSamplerFactory.createSampler(dumpParam, profilerConfig.getNingAsyncHttpClientProfileParamSamplingRate()); - } - } - - @Override - public void setMethodDescriptor(MethodDescriptor descriptor) { - this.descriptor = descriptor; - traceContext.cacheApi(descriptor); - } } diff --git a/plugins/ning-asynchttpclient/src/main/resources/META-INF/services/com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin b/plugins/ning-asynchttpclient/src/main/resources/META-INF/services/com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin new file mode 100644 index 000000000000..08d606497fce --- /dev/null +++ b/plugins/ning-asynchttpclient/src/main/resources/META-INF/services/com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin @@ -0,0 +1 @@ +com.navercorp.pinpoint.plugin.ning.asynchttpclient.NingAsyncHttpClientPlugin \ No newline at end of file diff --git a/plugins/ning-asynchttpclient/src/main/resources/META-INF/services/com.navercorp.pinpoint.common.trace.TraceMetadataProvider b/plugins/ning-asynchttpclient/src/main/resources/META-INF/services/com.navercorp.pinpoint.common.trace.TraceMetadataProvider new file mode 100644 index 000000000000..7ec773e26133 --- /dev/null +++ b/plugins/ning-asynchttpclient/src/main/resources/META-INF/services/com.navercorp.pinpoint.common.trace.TraceMetadataProvider @@ -0,0 +1 @@ +com.navercorp.pinpoint.plugin.ning.asynchttpclient.NingAsyncHttpClientMetadataProvider \ No newline at end of file diff --git a/plugins/oracle-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/oracle/OracleTypeProvider.java b/plugins/oracle-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/oracle/OracleTypeProvider.java index 2d23797a67fb..0038d536a749 100644 --- a/plugins/oracle-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/oracle/OracleTypeProvider.java +++ b/plugins/oracle-jdbc/src/main/java/com/navercorp/pinpoint/plugin/jdbc/oracle/OracleTypeProvider.java @@ -15,7 +15,7 @@ package com.navercorp.pinpoint.plugin.jdbc.oracle; import com.navercorp.pinpoint.common.trace.AnnotationKey; -import com.navercorp.pinpoint.common.trace.AnnotationKeyMatcher; +import com.navercorp.pinpoint.common.trace.AnnotationKeyMatchers; import com.navercorp.pinpoint.common.trace.TraceMetadataProvider; import com.navercorp.pinpoint.common.trace.TraceMetadataSetupContext; @@ -27,8 +27,8 @@ public class OracleTypeProvider implements TraceMetadataProvider, OracleConstant @Override public void setup(TraceMetadataSetupContext context) { - context.addServiceType(ORACLE, new AnnotationKeyMatcher.ExactMatcher(AnnotationKey.ARGS0)); - context.addServiceType(ORACLE_EXECUTE_QUERY, new AnnotationKeyMatcher.ExactMatcher(AnnotationKey.ARGS0)); + context.addServiceType(ORACLE, AnnotationKeyMatchers.exact(AnnotationKey.ARGS0)); + context.addServiceType(ORACLE_EXECUTE_QUERY, AnnotationKeyMatchers.exact(AnnotationKey.ARGS0)); } } diff --git a/plugins/pom.xml b/plugins/pom.xml index c49a793a277b..bfa4839619c1 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -14,6 +14,7 @@ httpclient3 httpclient4 + ning-asynchttpclient gson jackson cubrid-jdbc @@ -48,6 +49,11 @@ pinpoint-httpclient4-plugin ${project.version} + + com.navercorp.pinpoint + pinpoint-ning-asynchttpclient-plugin + ${project.version} + com.navercorp.pinpoint pinpoint-gson-plugin diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/ClassFileTransformerDispatcher.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/ClassFileTransformerDispatcher.java index 222472d1d6cb..4fb7ade83ac3 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/ClassFileTransformerDispatcher.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/ClassFileTransformerDispatcher.java @@ -181,9 +181,6 @@ private ModifierRegistry createModifierRegistry(List