Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract ning async-http-client profiler as a plugin
- Loading branch information
Showing
19 changed files
with
379 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...c/test/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Response> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/target/ | ||
/.settings/ | ||
/.classpath | ||
/.project | ||
/*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RMRqrdbgbKFhbaVnDxHUdDQvrOQXxIBklnvcmahheubVC | ||
mh2KM35CLkwUHS4DH7QVhxy52J5hnWbyEm6Cyd3KkF<mV | ||
RmmnSVOqOMnOnMMrmMqwXomoroNrqPNRrPSsWwtUxXuUU | ||
sRONqpnmqmUUnqonmstsmmmmmUUnqonmstsmmmmmUUGfk | ||
mlfkqUUnmmmm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.navercorp.pinpoint</groupId> | ||
<artifactId>pom</artifactId> | ||
<relativePath>../..</relativePath> | ||
<version>1.5.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>pinpoint-ning-asynchttpclient-plugin</artifactId> | ||
<name>pinpoint-ning-asynchttpclient-plugin</name> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.navercorp.pinpoint</groupId> | ||
<artifactId>pinpoint-bootstrap-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.ning</groupId> | ||
<artifactId>async-http-client</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
...m/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientMetadataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...in/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/NingAsyncHttpClientPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.