diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java
new file mode 100644
index 0000000000000000000000000000000000000000..3ce8604232e614209504fac3566905d5b1fadb66
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.jdbc.connectionurl.parser;
+
+import org.skywalking.apm.network.trace.component.ComponentsDefine;
+import org.skywalking.apm.plugin.jdbc.ConnectionInfo;
+
+/**
+ * {@link PostgreSQLURLParser} parse connection url of mysql.
+ *
+ * The {@link ConnectionInfo#host} be set the string between charset "//" and the first
+ * charset "/" after the charset "//", and {@link ConnectionInfo#databaseName} be set the
+ * string between the last index of "/" and the first charset "?". but one more thing, the
+ * {@link ConnectionInfo#hosts} be set if the host container multiple host.
+ *
+ * @author zhangxin
+ */
+public class PostgreSQLURLParser extends AbstractURLParser {
+
+ private static final int DEFAULT_PORT = 5432;
+ private static final String DB_TYPE = "PostgreSQL";
+
+ public PostgreSQLURLParser(String url) {
+ super(url);
+ }
+
+ @Override
+ protected int[] fetchDatabaseHostsIndexRange() {
+ int hostLabelStartIndex = url.indexOf("//");
+ int hostLabelEndIndex = url.indexOf("/", hostLabelStartIndex + 2);
+ return new int[] {hostLabelStartIndex + 2, hostLabelEndIndex};
+ }
+
+ @Override
+ protected int[] fetchDatabaseNameIndexRange() {
+ int databaseStartTag = url.lastIndexOf("/");
+ int databaseEndTag = url.indexOf("?", databaseStartTag);
+ if (databaseEndTag == -1) {
+ databaseEndTag = url.length();
+ }
+ return new int[] {databaseStartTag + 1, databaseEndTag};
+ }
+
+ @Override
+ public ConnectionInfo parse() {
+ int[] hostRangeIndex = fetchDatabaseHostsIndexRange();
+ String hosts = url.substring(hostRangeIndex[0], hostRangeIndex[1]);
+ String[] hostSegment = hosts.split(",");
+ if (hostSegment.length > 1) {
+ StringBuilder sb = new StringBuilder();
+ for (String host : hostSegment) {
+ if (host.split(":").length == 1) {
+ sb.append(host + ":" + DEFAULT_PORT + ",");
+ } else {
+ sb.append(host + ",");
+ }
+ }
+ return new ConnectionInfo(ComponentsDefine.POSTGRESQL, DB_TYPE, sb.toString(), fetchDatabaseNameFromURL());
+ } else {
+ String[] hostAndPort = hostSegment[0].split(":");
+ if (hostAndPort.length != 1) {
+ return new ConnectionInfo(ComponentsDefine.POSTGRESQL, DB_TYPE, hostAndPort[0], Integer.valueOf(hostAndPort[1]), fetchDatabaseNameFromURL());
+ } else {
+ return new ConnectionInfo(ComponentsDefine.POSTGRESQL, DB_TYPE, hostAndPort[0], DEFAULT_PORT, fetchDatabaseNameFromURL());
+ }
+ }
+ }
+
+}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
index ff52f80ec575d4e82150e963e44ee8bd04a8194a..ffc5ac051028368aa2f5056652c4a9348c25e5bc 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
@@ -21,8 +21,8 @@ package org.skywalking.apm.plugin.jdbc.connectionurl.parser;
import org.skywalking.apm.plugin.jdbc.ConnectionInfo;
/**
- * {@link URLParser#parser(String)} support parse the connection url, such as Mysql, Oracle, H2 Database.
- * But there are some url cannot be parsed, such as Oracle connection url with multiple host.
+ * {@link URLParser#parser(String)} support parse the connection url, such as Mysql, Oracle, H2 Database. But there are
+ * some url cannot be parsed, such as Oracle connection url with multiple host.
*
* @author zhangxin
*/
@@ -31,6 +31,7 @@ public class URLParser {
private static final String MYSQL_JDBC_URL_PREFIX = "jdbc:mysql";
private static final String ORACLE_JDBC_URL_PREFIX = "jdbc:oracle";
private static final String H2_JDBC_URL_PREFIX = "jdbc:h2";
+ private static final String POSTGRESQL_JDBC_URL_PREFIX = "jdbc:postgresql";
public static ConnectionInfo parser(String url) {
ConnectionURLParser parser = null;
@@ -40,6 +41,8 @@ public class URLParser {
parser = new OracleURLParser(url);
} else if (url.startsWith(H2_JDBC_URL_PREFIX)) {
parser = new H2URLParser(url);
+ } else if (url.startsWith(POSTGRESQL_JDBC_URL_PREFIX)) {
+ parser = new PostgreSQLURLParser(url);
}
return parser.parse();
}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/define/PostgreSQLInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/define/PostgreSQLInstrumentation.java
new file mode 100644
index 0000000000000000000000000000000000000000..99e249a64f416c008535662638da94af57de125c
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/java/org/skywalking/apm/plugin/jdbc/define/PostgreSQLInstrumentation.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.jdbc.define;
+
+import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
+
+import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
+
+/**
+ * {@link PostgreSQLInstrumentation} presents that skywalking intercepts {@link org.postgresql.Driver}.
+ *
+ * @author zhangxin
+ */
+public class PostgreSQLInstrumentation extends AbstractDatabaseInstrumentation {
+ @Override
+ protected ClassMatch enhanceClass() {
+ return byName("org.postgresql.Driver");
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def
index c946b2924ce5670b02a3d72778a9edb636d57501..a28a6c03dab0588174ea364ba15413abdd791517 100644
--- a/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def
+++ b/apm-sniffer/apm-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def
@@ -1,3 +1,4 @@
jdbc=org.skywalking.apm.plugin.jdbc.define.H2Instrumentation
jdbc=org.skywalking.apm.plugin.jdbc.define.MysqlInstrumentation
-jdbc=org.skywalking.apm.plugin.jdbc.define.OracleInstrumentation
\ No newline at end of file
+jdbc=org.skywalking.apm.plugin.jdbc.define.OracleInstrumentation
+jdbc=org.skywalking.apm.plugin.jdbc.define.PostgreSQLInstrumentation
diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml
index 84ccc21931d6400f536ad2faf3b564f42d9bfb8a..77c3cae9a13f83929fee93551911052b83a4b148 100644
--- a/apm-sniffer/apm-sdk-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/pom.xml
@@ -46,6 +46,8 @@
jetty-plugin
spymemcached-2.x-plugin
sharding-jdbc-1.5.x-plugin
+ xmemcached-2.x-plugin
+ grpc-1.x-plugin
pom
diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java
index cac14c7770383d7123c695c44bcd590ef07d0a7d..3bdfd8802694ede54999b0dbcc42aba32de3f0d8 100644
--- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptor.java
@@ -37,8 +37,8 @@ public class MemcachedMethodInterceptor implements InstanceMethodsAroundIntercep
Class>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
String peer = String.valueOf(objInst.getSkyWalkingDynamicField());
AbstractSpan span = ContextManager.createExitSpan(SPY_MEMCACHE + method.getName(), peer);
- span.setComponent(ComponentsDefine.MEMCACHE);
- Tags.DB_TYPE.set(span, ComponentsDefine.MEMCACHE.getName());
+ span.setComponent(ComponentsDefine.MEMCACHED);
+ Tags.DB_TYPE.set(span, ComponentsDefine.MEMCACHED.getName());
SpanLayer.asDB(span);
Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]);
}
diff --git a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java
index 17f1885ea8da3698155538587ff0a99f0f62df49..d7cbdd8620d1a33b27c0765ba169b06344109a6a 100644
--- a/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java
+++ b/apm-sniffer/apm-sdk-plugin/spymemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/spymemcached/v2/MemcachedMethodInterceptorTest.java
@@ -112,7 +112,7 @@ public class MemcachedMethodInterceptorTest {
assertThat(span.isExit(), is(true));
assertThat(SpanHelper.getComponentId(span), is(20));
List tags = SpanHelper.getTags(span);
- assertThat(tags.get(0).getValue(), is("Memcache"));
+ assertThat(tags.get(0).getValue(), is("Memcached"));
assertThat(tags.get(1).getValue(), is("set OperationKey"));
assertThat(SpanHelper.getLayer(span), is(SpanLayer.DB));
}
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..69a4eea0756c60fd802aab4d9b19baea16173b84
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/pom.xml
@@ -0,0 +1,52 @@
+
+
+
+ 4.0.0
+
+ org.skywalking
+ apm-sdk-plugin
+ 3.2.3-2017
+
+
+ apm-xmemcached-2.x-plugin
+ xmemcached-2.x-plugin
+ jar
+
+
+ UTF-8
+ 2.0.0
+
+
+
+
+ com.googlecode.xmemcached
+ xmemcached
+ ${xmemcached.version}
+ provided
+
+
+ org.apache.logging.log4j
+ log4j-core
+ 2.4.1
+ test
+
+
+
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java
new file mode 100644
index 0000000000000000000000000000000000000000..491f6a9b0c48896be906d922eb1351e5d95d7cac
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptor.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import java.net.InetSocketAddress;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
+
+/**
+ * {@link XMemcachedConstructorWithComplexArgInterceptor} intercept constructor of
+ * {@link XMemcachedClient(MemcachedSessionLocator locator,BufferAllocator allocator, Configuration conf,
+ * Map socketOptions, CommandFactory commandFactory, Transcoder transcoder,
+ * Map addressMap, List stateListeners,
+ * Map map, int poolSize, long connectTimeout, String name, boolean failureMode)} or
+ * {@link XMemcachedClient(MemcachedSessionLocator locator, BufferAllocator allocator, Configuration conf,
+ * Map socketOptions, CommandFactory commandFactory, Transcoder transcoder,
+ * Map addressMap, int[] weights, List stateListeners,
+ * Map infoMap, int poolSize, long connectTimeout, final String name, boolean failureMode)}.
+ * For parameter addressMap, every k-v is a master standby mode.
+ *
+ * @author IluckySi
+ */
+public class XMemcachedConstructorWithComplexArgInterceptor implements InstanceConstructorInterceptor {
+
+ @Override
+ public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
+ StringBuilder memcachConnInfo = new StringBuilder();
+ @SuppressWarnings("unchecked")
+ Map inetSocketAddressMap = (Map)allArguments[6];
+ for (Entry entry : inetSocketAddressMap.entrySet()) {
+ memcachConnInfo = append(memcachConnInfo, entry.getKey());
+ memcachConnInfo = append(memcachConnInfo, entry.getValue());
+ }
+ Integer length = memcachConnInfo.length();
+ if (length > 1) {
+ memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, length - 1));
+ }
+ objInst.setSkyWalkingDynamicField(memcachConnInfo.toString());
+ }
+
+ /**
+ * Parse InetSocketAddress in specified format
+ * @param sb
+ * @param inetSocketAddress
+ * @return
+ */
+ private StringBuilder append(StringBuilder sb, InetSocketAddress inetSocketAddress) {
+ if (inetSocketAddress != null) {
+ String host = inetSocketAddress.getAddress().getHostAddress();
+ int port = inetSocketAddress.getPort();
+ sb.append(host).append(":").append(port).append(";");
+ }
+ return sb;
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java
new file mode 100644
index 0000000000000000000000000000000000000000..c2f63fe79a1f8d0f1fb5d2df437c00b296d127dc
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptor.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
+
+/**
+ * {@link XMemcachedConstructorWithHostPortArgInterceptor} intercept constructor of
+ * {@link XMemcachedClient(final String host, final int port)} or
+ * {@link XMemcachedClient(final String host, final int port, int weight)}.
+ *
+ * @author IluckySi
+ */
+public class XMemcachedConstructorWithHostPortArgInterceptor implements InstanceConstructorInterceptor {
+
+ @Override
+ public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
+ Object host = allArguments[0];
+ Object port = allArguments[1];
+ objInst.setSkyWalkingDynamicField(host + ":" + port);
+ }
+}
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java
new file mode 100644
index 0000000000000000000000000000000000000000..023fa944539897a0571fc6915c3cdd254697fab8
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptor.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import java.net.InetSocketAddress;
+
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
+
+/**
+ * {@link XMemcachedConstructorWithInetSocketAddressArgInterceptor} intercept constructor of
+ * {@link XMemcachedClient(final InetSocketAddress inetSocketAddress)} or
+ * {@link XMemcachedClient(final InetSocketAddress inetSocketAddress, int weight)}.
+ *
+ * @author IluckySi
+ */
+public class XMemcachedConstructorWithInetSocketAddressArgInterceptor implements InstanceConstructorInterceptor {
+
+ @Override
+ public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
+ InetSocketAddress inetSocketAddress = (InetSocketAddress)allArguments[0];
+ String host = inetSocketAddress.getAddress().getHostAddress();
+ int port = inetSocketAddress.getPort();
+ objInst.setSkyWalkingDynamicField(host + ":" + port);
+ }
+}
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java
new file mode 100644
index 0000000000000000000000000000000000000000..a38111b980345720c3fe737d1f5e345ccd5de99c
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptor.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import java.net.InetSocketAddress;
+import java.util.List;
+
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
+
+/**
+ * {@link XMemcachedConstructorWithInetSocketAddressListArgInterceptor} intercept constructor of
+ * {@link XMemcachedClient(List addressList).
+ *
+ * @author IluckySi
+ */
+public class XMemcachedConstructorWithInetSocketAddressListArgInterceptor implements InstanceConstructorInterceptor {
+
+ @Override
+ public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
+ StringBuilder memcachConnInfo = new StringBuilder();
+ @SuppressWarnings("unchecked")
+ List inetSocketAddressList = (List)allArguments[0];
+ for (InetSocketAddress inetSocketAddress : inetSocketAddressList) {
+ String host = inetSocketAddress.getAddress().getHostAddress();
+ int port = inetSocketAddress.getPort();
+ memcachConnInfo.append(host).append(":").append(port).append(";");
+ }
+ int length = memcachConnInfo.length();
+ if (length > 1) {
+ memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, length - 1));
+ }
+ objInst.setSkyWalkingDynamicField(memcachConnInfo.toString());
+ }
+}
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java
new file mode 100644
index 0000000000000000000000000000000000000000..77fb444406ae9ff354d4f399dcb979d4edf2c80e
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptor.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import java.lang.reflect.Method;
+
+import org.skywalking.apm.agent.core.context.ContextManager;
+import org.skywalking.apm.agent.core.context.tag.Tags;
+import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
+import org.skywalking.apm.agent.core.context.trace.SpanLayer;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.skywalking.apm.network.trace.component.ComponentsDefine;
+
+/**
+ * {@link XMemcachedMethodInterceptor} intercept the operation method,
+ * record the memcached host, operation name and the key of the operation.
+ *
+ * @author IluckySi
+ */
+public class XMemcachedMethodInterceptor implements InstanceMethodsAroundInterceptor {
+
+ private static final String XMEMCACHED = "XMemcached/";
+
+ @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
+ String peer = String.valueOf(objInst.getSkyWalkingDynamicField());
+ AbstractSpan span = ContextManager.createExitSpan(XMEMCACHED + method.getName(), peer);
+ span.setComponent(ComponentsDefine.MEMCACHED);
+ Tags.DB_TYPE.set(span, ComponentsDefine.MEMCACHED.getName());
+ SpanLayer.asDB(span);
+ Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]);
+ }
+
+ @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Object ret) throws Throwable {
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class>[] argumentsTypes, Throwable t) {
+ AbstractSpan span = ContextManager.activeSpan();
+ span.errorOccurred();
+ span.log(t);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java
new file mode 100644
index 0000000000000000000000000000000000000000..8a6fb3ea5d7de3b90fc6c35a09723e31dec5ad1e
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/java/org/skywalking/apm/plugin/xmemcached/v2/define/XMemcachedInstrumentation.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2.define;
+
+import java.net.InetSocketAddress;
+import java.util.List;
+import java.util.Map;
+
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
+import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
+import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
+import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
+
+/**
+ * {@link MemcachedInstrumentation} presents that skywalking intercept all constructors and methods of
+ * {@link net.rubyeye.xmemcached.XMemcachedClient}.
+ * {@link XMemcachedConstructorWithHostPortArgInterceptor} intercepts the constructor with
+ * ip and port arguments.
+ * {@link XMemcachedConstructorWithInetSocketAddressArgInterceptor} intercepts the constructor with
+ * argument {@link java.net.InetSocketAddress}.
+ * {@link XMemcachedConstructorWithInetSocketAddressListArgInterceptor} intercepts the constructor with
+ * argument {@link java.net.InetSocketAddress}.
+ * {@link XMemcachedConstructorWithComplexArgInterceptor} intercepts the constructor with complex arguments.
+ *
+ * @author IluckySi
+ */
+public class XMemcachedInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+
+ private static final String ENHANCE_CLASS = "net.rubyeye.xmemcached.XMemcachedClient";
+ private static final String CONSTRUCTOR_WITH_HOSTPORT_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedConstructorWithHostPortArgInterceptor";
+ private static final String CONSTRUCTOR_WITH_INETSOCKETADDRESS_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedConstructorWithInetSocketAddressArgInterceptor";
+ private static final String CONSTRUCTOR_WITH_INETSOCKETADDRESS_LIST_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedConstructorWithInetSocketAddressListArgInterceptor";
+ private static final String CONSTRUCTOR_WITH_COMPLEX_ARG_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedConstructorWithComplexArgInterceptor";
+ private static final String METHOD_INTERCEPT_CLASS = "org.skywalking.apm.plugin.xmemcached.v2.XMemcachedMethodInterceptor";
+
+ @Override
+ public ClassMatch enhanceClass() {
+ return byName(ENHANCE_CLASS);
+ }
+ @Override
+ protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
+ return new ConstructorInterceptPoint[] {
+ new ConstructorInterceptPoint() {
+ @Override
+ public ElementMatcher getConstructorMatcher() {
+ return takesArguments(String.class, int.class);
+ }
+
+ @Override
+ public String getConstructorInterceptor() {
+ return CONSTRUCTOR_WITH_HOSTPORT_ARG_INTERCEPT_CLASS;
+ }
+ },
+ new ConstructorInterceptPoint() {
+ @Override
+ public ElementMatcher getConstructorMatcher() {
+ return takesArgument(0, InetSocketAddress.class);
+ }
+
+ @Override
+ public String getConstructorInterceptor() {
+ return CONSTRUCTOR_WITH_INETSOCKETADDRESS_ARG_INTERCEPT_CLASS;
+ }
+ },
+ new ConstructorInterceptPoint() {
+ @Override
+ public ElementMatcher getConstructorMatcher() {
+ return takesArgument(0, List.class);
+ }
+
+ @Override
+ public String getConstructorInterceptor() {
+ return CONSTRUCTOR_WITH_INETSOCKETADDRESS_LIST_ARG_INTERCEPT_CLASS;
+ }
+ },
+ new ConstructorInterceptPoint() {
+ @Override
+ public ElementMatcher getConstructorMatcher() {
+ return takesArgument(6, Map.class);
+ }
+
+ @Override
+ public String getConstructorInterceptor() {
+ return CONSTRUCTOR_WITH_COMPLEX_ARG_INTERCEPT_CLASS;
+ }
+ }
+ };
+ }
+
+ @Override
+ protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
+ return new InstanceMethodsInterceptPoint[] {
+ new InstanceMethodsInterceptPoint() {
+ @Override
+ public ElementMatcher getMethodsMatcher() {
+ return named("get").or(named("set")) .or(named("add")).or(named("replace")).or(named("gets"))
+ .or(named("append")) .or(named("prepend")).or(named("cas")).or(named("delete")).or(named("touch")).
+ or(named("getAndTouch")).or(named("incr")) .or(named("decr"));
+ }
+
+ @Override
+ public String getMethodsInterceptor() {
+ return METHOD_INTERCEPT_CLASS;
+ }
+
+ @Override public boolean isOverrideArgs() {
+ return false;
+ }
+ }
+ };
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/resources/skywalking-plugin.def
new file mode 100644
index 0000000000000000000000000000000000000000..c04b8817ba5a3fd072f92ba3449b81e5e51cb81e
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/main/resources/skywalking-plugin.def
@@ -0,0 +1 @@
+memcache-2.x=org.skywalking.apm.plugin.xmemcached.v2.define.XMemcachedInstrumentation
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..6615eee2f742aef5823c9fe7a84a92cbd7ac7cb5
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithComplexArgInterceptorTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+
+@RunWith(MockitoJUnitRunner.class)
+public class XMemcachedConstructorWithComplexArgInterceptorTest {
+
+ private XMemcachedConstructorWithComplexArgInterceptor interceptor;
+
+ @Mock
+ private EnhancedInstance enhancedInstance;
+
+ @Before
+ public void setUp() throws Exception {
+ interceptor = new XMemcachedConstructorWithComplexArgInterceptor();
+ }
+
+ @Test
+ public void onConstructWithComplex() {
+ Map inetSocketAddressMap = new HashMap();
+ inetSocketAddressMap.put(new InetSocketAddress("127.0.0.1", 11211), new InetSocketAddress("127.0.0.2", 11211));
+ interceptor.onConstruct(enhancedInstance, new Object[]{null, null, null, null, null, null, inetSocketAddressMap});
+
+ verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211;127.0.0.2:11211");
+ }
+}
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..ae8101e19a4efb5f188e698be4bd7f7e8aff9985
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithHostPortArgInterceptorTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+
+@RunWith(MockitoJUnitRunner.class)
+public class XMemcachedConstructorWithHostPortArgInterceptorTest {
+
+ private XMemcachedConstructorWithHostPortArgInterceptor interceptor;
+
+ @Mock
+ private EnhancedInstance enhancedInstance;
+
+ @Before
+ public void setUp() throws Exception {
+ interceptor = new XMemcachedConstructorWithHostPortArgInterceptor();
+ }
+
+ @Test
+ public void onConstructWithHostPort() {
+ interceptor.onConstruct(enhancedInstance, new Object[]{"127.0.0.1", 11211});
+
+ verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211");
+ }
+}
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..f83178ba9261f5acb58b5c52125743d3df941969
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressArgInterceptorTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.net.InetSocketAddress;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+
+@RunWith(MockitoJUnitRunner.class)
+public class XMemcachedConstructorWithInetSocketAddressArgInterceptorTest {
+
+ private XMemcachedConstructorWithInetSocketAddressArgInterceptor interceptor;
+
+ @Mock
+ private EnhancedInstance enhancedInstance;
+
+ @Before
+ public void setUp() throws Exception {
+ interceptor = new XMemcachedConstructorWithInetSocketAddressArgInterceptor();
+ }
+
+ @Test
+ public void onConstructWithInetSocketAddress() {
+ interceptor.onConstruct(enhancedInstance, new Object[]{new InetSocketAddress("127.0.0.1", 11211)});
+
+ verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211");
+ }
+}
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..0e4a96ca67428982093b4c302269a71b932df36c
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+
+@RunWith(MockitoJUnitRunner.class)
+public class XMemcachedConstructorWithInetSocketAddressListArgInterceptorTest {
+
+ private XMemcachedConstructorWithInetSocketAddressListArgInterceptor interceptor;
+
+ @Mock
+ private EnhancedInstance enhancedInstance;
+
+ @Before
+ public void setUp() throws Exception {
+ interceptor = new XMemcachedConstructorWithInetSocketAddressListArgInterceptor();
+ }
+
+ @Test
+ public void onConstructWithInetSocketAddressList() {
+ List inetSocketAddressList = new ArrayList();
+ inetSocketAddressList.add(new InetSocketAddress("127.0.0.1", 11211));
+ inetSocketAddressList.add(new InetSocketAddress("127.0.0.2", 11211));
+ interceptor.onConstruct(enhancedInstance, new Object[]{inetSocketAddressList});
+
+ verify(enhancedInstance, times(1)).setSkyWalkingDynamicField("127.0.0.1:11211;127.0.0.2:11211");
+ }
+}
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..96f66d25ee62f9595926b5d2e3ffd185103b7c12
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/xmemcached-2.x-plugin/src/test/java/org/skywalking/apm/plugin/xmemcached/v2/XMemcachedMethodInterceptorTest.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * 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.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.plugin.xmemcached.v2;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.when;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
+import org.skywalking.apm.agent.core.context.trace.LogDataEntity;
+import org.skywalking.apm.agent.core.context.trace.SpanLayer;
+import org.skywalking.apm.agent.core.context.trace.TraceSegment;
+import org.skywalking.apm.agent.core.context.util.KeyValuePair;
+import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.skywalking.apm.agent.test.helper.SegmentHelper;
+import org.skywalking.apm.agent.test.helper.SpanHelper;
+import org.skywalking.apm.agent.test.tools.AgentServiceRule;
+import org.skywalking.apm.agent.test.tools.SegmentStorage;
+import org.skywalking.apm.agent.test.tools.SegmentStoragePoint;
+import org.skywalking.apm.agent.test.tools.TracingSegmentRunner;
+
+import net.rubyeye.xmemcached.XMemcachedClient;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+public class XMemcachedMethodInterceptorTest {
+
+ @SegmentStoragePoint
+ private SegmentStorage segmentStorage;
+
+ @Rule
+ public AgentServiceRule serviceRule = new AgentServiceRule();
+
+ @Mock
+ private EnhancedInstance enhancedInstance;
+ private XMemcachedMethodInterceptor interceptor;
+
+ private Object[] allArgument;
+ private Class[] argumentType;
+
+ @Before
+ public void setUp() throws Exception {
+ allArgument = new Object[] {"OperationKey", "OperationValue"};
+ argumentType = new Class[] {String.class, String.class};
+
+ interceptor = new XMemcachedMethodInterceptor();
+ when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:11211");
+ }
+
+ @Test
+ public void testIntercept() throws Throwable {
+ interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
+ interceptor.afterMethod(enhancedInstance, getMockGetMethod(), allArgument, argumentType, null);
+
+ TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
+ List spans = SegmentHelper.getSpans(traceSegment);
+ assertThat(spans.size(), is(1));
+ assertMemcacheSpan(spans.get(0));
+ }
+
+ @Test
+ public void testInterceptWithException() throws Throwable {
+ interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
+ interceptor.handleMethodException(enhancedInstance, getMockSetMethod(), allArgument, argumentType, new RuntimeException());
+ interceptor.afterMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
+
+ TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
+ List spans = SegmentHelper.getSpans(traceSegment);
+ assertThat(spans.size(), is(1));
+ assertMemcacheSpan(spans.get(0));
+
+ assertLogData(SpanHelper.getLogs(spans.get(0)));
+ }
+
+ private void assertLogData(List logDataEntities) {
+ assertThat(logDataEntities.size(), is(1));
+ LogDataEntity logData = logDataEntities.get(0);
+ Assert.assertThat(logData.getLogs().size(), is(4));
+ Assert.assertThat(logData.getLogs().get(0).getValue(), CoreMatchers.