提交 da0b4ca5 编写于 作者: IluckySi's avatar IluckySi

Suppor Xmemcached V2.x

上级 70025899
......@@ -25,6 +25,20 @@ 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<SocketOption, Object> socketOptions, CommandFactory commandFactory, Transcoder transcoder,
* Map<InetSocketAddress, InetSocketAddress> addressMap, List<MemcachedClientStateListener> stateListeners,
* Map<InetSocketAddress, AuthInfo> map, int poolSize, long connectTimeout, String name, boolean failureMode)} or
* {@link XMemcachedClient(MemcachedSessionLocator locator, BufferAllocator allocator, Configuration conf,
* Map<SocketOption, Object> socketOptions, CommandFactory commandFactory, Transcoder transcoder,
* Map<InetSocketAddress, InetSocketAddress> addressMap, int[] weights, List<MemcachedClientStateListener> stateListeners,
* Map<InetSocketAddress, AuthInfo> 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
......@@ -32,23 +46,19 @@ public class XMemcachedConstructorWithComplexArgInterceptor implements InstanceC
StringBuilder memcachConnInfo = new StringBuilder();
@SuppressWarnings("unchecked")
Map<InetSocketAddress, InetSocketAddress> inetSocketAddressMap = (Map<InetSocketAddress, InetSocketAddress>)allArguments[6];
StringBuilder master = new StringBuilder();
for (Entry<InetSocketAddress, InetSocketAddress> entry : inetSocketAddressMap.entrySet()) {
if (master.length() == 0) {
master = append(master,entry.getKey());
}
memcachConnInfo = append(memcachConnInfo, entry.getKey());
memcachConnInfo = append(memcachConnInfo, entry.getValue());
}
memcachConnInfo = master.append(memcachConnInfo);
Integer l = memcachConnInfo.length();
if (l > 1) {
memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, l - 1));
Integer length = memcachConnInfo.length();
if (length > 1) {
memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, length - 1));
}
objInst.setSkyWalkingDynamicField(memcachConnInfo.toString());
}
/**
* Parse InetSocketAddress
* Parse InetSocketAddress in specified format
* @param sb
* @param inetSocketAddress
* @return
......
......@@ -21,6 +21,13 @@ 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
......
......@@ -23,6 +23,13 @@ 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
......
......@@ -24,6 +24,12 @@ 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<InetSocketAddress> addressList).
*
* @author IluckySi
*/
public class XMemcachedConstructorWithInetSocketAddressListArgInterceptor implements InstanceConstructorInterceptor {
@Override
......@@ -36,9 +42,9 @@ public class XMemcachedConstructorWithInetSocketAddressListArgInterceptor implem
int port = inetSocketAddress.getPort();
memcachConnInfo.append(host).append(":").append(port).append(";");
}
int l = memcachConnInfo.length();
if (l > 1) {
memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, l - 1));
int length = memcachConnInfo.length();
if (length > 1) {
memcachConnInfo = new StringBuilder(memcachConnInfo.substring(0, length - 1));
}
objInst.setSkyWalkingDynamicField(memcachConnInfo.toString());
}
......
......@@ -29,6 +29,12 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsA
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/";
......
......@@ -116,7 +116,7 @@ public class XMemcachedMethodInterceptorTest {
assertThat(span.isExit(), is(true));
assertThat(SpanHelper.getComponentId(span), is(20));
List<KeyValuePair> 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));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册