Loading skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ public class JedisClusterConstructorWithHostAndPortArgInterceptor implements Ins public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { StringBuilder redisConnInfo = new StringBuilder(); HostAndPort hostAndPort = (HostAndPort) interceptorContext.allArguments()[0]; redisConnInfo.append(hostAndPort.toString()).append(";"); redisConnInfo.append(hostAndPort.toString()); context.set(KEY_OF_REDIS_CONN_INFO, redisConnInfo.toString()); context.set(KEY_OF_REDIS_HOST, hostAndPort.getHost()); context.set(KEY_OF_REDIS_PORT, hostAndPort.getPort()); Loading skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java +1 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,6 @@ public class JedisClusterConstructorWithListHostAndPortArgInterceptor implements redisConnInfo.append(hostAndPort.toString()).append(";"); } context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo.toString()); context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, redisConnInfo); context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, redisConnInfo.toString()); } } skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java +7 −1 Original line number Diff line number Diff line Loading @@ -46,11 +46,17 @@ public class JedisMethodInterceptor extends NoCocurrencyAceessObject { this.whenEnter(context, new Runnable() { @Override public void run() { Span span = ContextManager.INSTANCE.createSpan(context.get(KEY_OF_REDIS_CONN_INFO, String.class) + " " + interceptorContext.methodName()); Span span = ContextManager.INSTANCE.createSpan("Jedis/" + interceptorContext.methodName()); Tags.COMPONENT.set(span, REDIS_COMPONENT); Tags.DB_TYPE.set(span, REDIS_COMPONENT); tagPeer(span, context); Tags.SPAN_LAYER.asDB(span); if (StringUtil.isEmpty(context.get(KEY_OF_REDIS_HOST, String.class))) { Tags.PEERS.set(span, String.valueOf(context.get(KEY_OF_REDIS_HOSTS))); } else { Tags.PEER_HOST.set(span, context.get(KEY_OF_REDIS_HOST, String.class)); Tags.PEER_PORT.set(span, (Integer) context.get(KEY_OF_REDIS_PORT)); } if (interceptorContext.allArguments().length > 0 && interceptorContext.allArguments()[0] instanceof String) { Loading skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/test/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java 0 → 100644 +56 −0 Original line number Diff line number Diff line package com.a.eye.skywalking.plugin.jedis.v2; import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.powermock.modules.junit4.PowerMockRunner; import redis.clients.jedis.HostAndPort; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOST; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_PORT; import static org.junit.Assert.*; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class JedisClusterConstructorWithHostAndPortArgInterceptorTest { private JedisClusterConstructorWithHostAndPortArgInterceptor interceptor; @Mock private EnhancedClassInstanceContext instanceContext; @Mock private ConstructorInvokeContext invokeContext; @Before public void setUp() throws Exception { interceptor = new JedisClusterConstructorWithHostAndPortArgInterceptor(); when(invokeContext.allArguments()).thenReturn(new Object[]{new HostAndPort("127.0.0.1", 6379)}); } @After public void tearDown() throws Exception { } @Test public void onConstruct() throws Exception { interceptor.onConstruct(instanceContext, invokeContext); verify(instanceContext, times(1)).set(KEY_OF_REDIS_CONN_INFO, "127.0.0.1:6379"); verify(instanceContext, times(1)).set(KEY_OF_REDIS_HOST, "127.0.0.1"); verify(instanceContext, times(1)).set(KEY_OF_REDIS_PORT, 6379); } } No newline at end of file skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/test/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java 0 → 100644 +62 −0 Original line number Diff line number Diff line package com.a.eye.skywalking.plugin.jedis.v2; import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.util.HashSet; import java.util.Set; import redis.clients.jedis.HostAndPort; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOSTS; import static org.hamcrest.core.Is.is; import static org.mockito.Matchers.any; import static org.mockito.Matchers.contains; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class JedisClusterConstructorWithListHostAndPortArgInterceptorTest { private JedisClusterConstructorWithListHostAndPortArgInterceptor interceptor; @Mock private EnhancedClassInstanceContext instanceContext; @Mock private ConstructorInvokeContext invokeContext; private Set<HostAndPort> hostAndPortSet; @Before public void setUp() throws Exception { hostAndPortSet = new HashSet<HostAndPort>(); interceptor = new JedisClusterConstructorWithListHostAndPortArgInterceptor(); hostAndPortSet.add(new HostAndPort("127.0.0.1", 6379)); hostAndPortSet.add(new HostAndPort("127.0.0.1", 16379)); when(invokeContext.allArguments()).thenReturn(new Object[]{hostAndPortSet}); } @After public void tearDown() throws Exception { } @Test public void onConstruct() throws Exception { interceptor.onConstruct(instanceContext, invokeContext); verify(instanceContext, times(1)).set(eq(KEY_OF_REDIS_CONN_INFO), contains("127.0.0.1:6379;")); verify(instanceContext, times(1)).set(eq(KEY_OF_REDIS_HOSTS), contains("127.0.0.1:16379;")); } } No newline at end of file Loading
skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java +1 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ public class JedisClusterConstructorWithHostAndPortArgInterceptor implements Ins public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { StringBuilder redisConnInfo = new StringBuilder(); HostAndPort hostAndPort = (HostAndPort) interceptorContext.allArguments()[0]; redisConnInfo.append(hostAndPort.toString()).append(";"); redisConnInfo.append(hostAndPort.toString()); context.set(KEY_OF_REDIS_CONN_INFO, redisConnInfo.toString()); context.set(KEY_OF_REDIS_HOST, hostAndPort.getHost()); context.set(KEY_OF_REDIS_PORT, hostAndPort.getPort()); Loading
skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java +1 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,6 @@ public class JedisClusterConstructorWithListHostAndPortArgInterceptor implements redisConnInfo.append(hostAndPort.toString()).append(";"); } context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo.toString()); context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, redisConnInfo); context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, redisConnInfo.toString()); } }
skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java +7 −1 Original line number Diff line number Diff line Loading @@ -46,11 +46,17 @@ public class JedisMethodInterceptor extends NoCocurrencyAceessObject { this.whenEnter(context, new Runnable() { @Override public void run() { Span span = ContextManager.INSTANCE.createSpan(context.get(KEY_OF_REDIS_CONN_INFO, String.class) + " " + interceptorContext.methodName()); Span span = ContextManager.INSTANCE.createSpan("Jedis/" + interceptorContext.methodName()); Tags.COMPONENT.set(span, REDIS_COMPONENT); Tags.DB_TYPE.set(span, REDIS_COMPONENT); tagPeer(span, context); Tags.SPAN_LAYER.asDB(span); if (StringUtil.isEmpty(context.get(KEY_OF_REDIS_HOST, String.class))) { Tags.PEERS.set(span, String.valueOf(context.get(KEY_OF_REDIS_HOSTS))); } else { Tags.PEER_HOST.set(span, context.get(KEY_OF_REDIS_HOST, String.class)); Tags.PEER_PORT.set(span, (Integer) context.get(KEY_OF_REDIS_PORT)); } if (interceptorContext.allArguments().length > 0 && interceptorContext.allArguments()[0] instanceof String) { Loading
skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/test/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptorTest.java 0 → 100644 +56 −0 Original line number Diff line number Diff line package com.a.eye.skywalking.plugin.jedis.v2; import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.powermock.modules.junit4.PowerMockRunner; import redis.clients.jedis.HostAndPort; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOST; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_PORT; import static org.junit.Assert.*; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class JedisClusterConstructorWithHostAndPortArgInterceptorTest { private JedisClusterConstructorWithHostAndPortArgInterceptor interceptor; @Mock private EnhancedClassInstanceContext instanceContext; @Mock private ConstructorInvokeContext invokeContext; @Before public void setUp() throws Exception { interceptor = new JedisClusterConstructorWithHostAndPortArgInterceptor(); when(invokeContext.allArguments()).thenReturn(new Object[]{new HostAndPort("127.0.0.1", 6379)}); } @After public void tearDown() throws Exception { } @Test public void onConstruct() throws Exception { interceptor.onConstruct(instanceContext, invokeContext); verify(instanceContext, times(1)).set(KEY_OF_REDIS_CONN_INFO, "127.0.0.1:6379"); verify(instanceContext, times(1)).set(KEY_OF_REDIS_HOST, "127.0.0.1"); verify(instanceContext, times(1)).set(KEY_OF_REDIS_PORT, 6379); } } No newline at end of file
skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/test/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptorTest.java 0 → 100644 +62 −0 Original line number Diff line number Diff line package com.a.eye.skywalking.plugin.jedis.v2; import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.util.HashSet; import java.util.Set; import redis.clients.jedis.HostAndPort; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOSTS; import static org.hamcrest.core.Is.is; import static org.mockito.Matchers.any; import static org.mockito.Matchers.contains; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class JedisClusterConstructorWithListHostAndPortArgInterceptorTest { private JedisClusterConstructorWithListHostAndPortArgInterceptor interceptor; @Mock private EnhancedClassInstanceContext instanceContext; @Mock private ConstructorInvokeContext invokeContext; private Set<HostAndPort> hostAndPortSet; @Before public void setUp() throws Exception { hostAndPortSet = new HashSet<HostAndPort>(); interceptor = new JedisClusterConstructorWithListHostAndPortArgInterceptor(); hostAndPortSet.add(new HostAndPort("127.0.0.1", 6379)); hostAndPortSet.add(new HostAndPort("127.0.0.1", 16379)); when(invokeContext.allArguments()).thenReturn(new Object[]{hostAndPortSet}); } @After public void tearDown() throws Exception { } @Test public void onConstruct() throws Exception { interceptor.onConstruct(instanceContext, invokeContext); verify(instanceContext, times(1)).set(eq(KEY_OF_REDIS_CONN_INFO), contains("127.0.0.1:6379;")); verify(instanceContext, times(1)).set(eq(KEY_OF_REDIS_HOSTS), contains("127.0.0.1:16379;")); } } No newline at end of file