diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/tracevalue/MapTraceValue.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/tracevalue/MapTraceValue.java new file mode 100644 index 000000000..a4af1a81e --- /dev/null +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/tracevalue/MapTraceValue.java @@ -0,0 +1,14 @@ +package com.nhn.pinpoint.bootstrap.interceptor.tracevalue; + +import java.util.Map; + +/** + * + * @author jaehong.kim + * + */ +public interface MapTraceValue extends TraceValue { + void __setTraceBindValue(Map value); + + Map __getTraceBindValue(); +} diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/ServiceType.java b/commons/src/main/java/com/navercorp/pinpoint/common/ServiceType.java index 63bd8ff17..4f27c3ddb 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/ServiceType.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/ServiceType.java @@ -111,7 +111,7 @@ public enum ServiceType { /** * Redis & nBase-ARC */ - REDIS((short) 8200, "REDIS", TERMINAL, RECORD_STATISTICS, INCLUDE_DESTINATION, FAST_SCHEMA), + REDIS((short) 8200, "REDIS", TERMINAL, RECORD_STATISTICS, !INCLUDE_DESTINATION, FAST_SCHEMA), NBASE_ARC((short) 8250, "NBASE_ARC", TERMINAL, RECORD_STATISTICS, INCLUDE_DESTINATION, FAST_SCHEMA), /** diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/DefaultModifierRegistry.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/DefaultModifierRegistry.java index 86e7dd841..a1f1fb702 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/DefaultModifierRegistry.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/DefaultModifierRegistry.java @@ -59,6 +59,8 @@ import com.nhn.pinpoint.profiler.modifier.orm.ibatis.SqlMapClientImplModifier; import com.nhn.pinpoint.profiler.modifier.orm.ibatis.SqlMapSessionImplModifier; import com.nhn.pinpoint.profiler.modifier.orm.mybatis.DefaultSqlSessionModifier; import com.nhn.pinpoint.profiler.modifier.orm.mybatis.SqlSessionTemplateModifier; +import com.nhn.pinpoint.profiler.modifier.redis.GatewayModifier; +import com.nhn.pinpoint.profiler.modifier.redis.GatewayServerModifier; import com.nhn.pinpoint.profiler.modifier.redis.JedisClientModifier; import com.nhn.pinpoint.profiler.modifier.redis.JedisModifier; import com.nhn.pinpoint.profiler.modifier.redis.JedisPipelineModifier; @@ -391,6 +393,8 @@ public class DefaultModifierRegistry implements ModifierRegistry { public void addNBaseArcSupport() { if (profilerConfig.isNBaseArcEnabled()) { + addModifier(new GatewayModifier(byteCodeInstrumentor, agent)); + addModifier(new GatewayServerModifier(byteCodeInstrumentor, agent)); addModifier(new RedisClusterModifier(byteCodeInstrumentor, agent)); addModifier(new RedisClusterPipelineModifier(byteCodeInstrumentor, agent)); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/GatewayModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/GatewayModifier.java new file mode 100644 index 000000000..fec26e844 --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/GatewayModifier.java @@ -0,0 +1,68 @@ +package com.nhn.pinpoint.profiler.modifier.redis; + +import java.security.ProtectionDomain; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.nhn.pinpoint.bootstrap.Agent; +import com.nhn.pinpoint.bootstrap.interceptor.Interceptor; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; +import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor; +import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass; +import com.nhn.pinpoint.profiler.interceptor.bci.Method; +import com.nhn.pinpoint.profiler.modifier.AbstractModifier; + +/** + * Gateway(nBase-ARC client) modifier + * + * @author jaehong.kim + * + */ +public class GatewayModifier extends AbstractModifier { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + public GatewayModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) { + super(byteCodeInstrumentor, agent); + } + + @Override + public String getTargetClass() { + return "com/nhncorp/redis/cluster/gateway/Gateway"; + } + + @Override + public byte[] modify(ClassLoader classLoader, String className, ProtectionDomain protectedDomain, byte[] classFileBuffer) { + if (logger.isInfoEnabled()) { + logger.info("Modifing. {}", className); + } + + try { + final InstrumentClass instrumentClass = byteCodeInstrumentor.getClass(className); + + // trace destinationId + instrumentClass.addTraceValue(MapTraceValue.class); + final Interceptor constructorInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.nhn.pinpoint.profiler.modifier.redis.interceptor.GatewayConstructorInterceptor"); + instrumentClass.addConstructorInterceptor(new String[] { "com.nhncorp.redis.cluster.gateway.GatewayConfig" }, constructorInterceptor); + + // method + final List declaredMethods = instrumentClass.getDeclaredMethods(); + for (Method method : declaredMethods) { + if (method.getMethodName().equals("getServer")) { + final Interceptor methodInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.nhn.pinpoint.profiler.modifier.redis.interceptor.GatewayMethodInterceptor"); + instrumentClass.addInterceptor(method.getMethodName(), method.getMethodParams(), methodInterceptor); + } + } + + return instrumentClass.toBytecode(); + } catch (Exception e) { + if (logger.isWarnEnabled()) { + logger.warn("redis.GatewayModifier(nBase-ARC) fail. Target class is " + getTargetClass() + ", Caused " + e.getMessage(), e); + } + } + + return null; + } +} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/GatewayServerModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/GatewayServerModifier.java new file mode 100644 index 000000000..9d423cb26 --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/GatewayServerModifier.java @@ -0,0 +1,66 @@ +package com.nhn.pinpoint.profiler.modifier.redis; + +import java.security.ProtectionDomain; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.nhn.pinpoint.bootstrap.Agent; +import com.nhn.pinpoint.bootstrap.interceptor.Interceptor; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; +import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor; +import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass; +import com.nhn.pinpoint.profiler.interceptor.bci.Method; +import com.nhn.pinpoint.profiler.modifier.AbstractModifier; + +/** + * RedisCluster(nBase-ARC client) modifier + * + * @author jaehong.kim + * + */ +public class GatewayServerModifier extends AbstractModifier { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + public GatewayServerModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) { + super(byteCodeInstrumentor, agent); + } + + @Override + public String getTargetClass() { + return "com/nhncorp/redis/cluster/gateway/GatewayServer"; + } + + @Override + public byte[] modify(ClassLoader classLoader, String className, ProtectionDomain protectedDomain, byte[] classFileBuffer) { + if (logger.isInfoEnabled()) { + logger.info("Modifing. {}", className); + } + + try { + final InstrumentClass instrumentClass = byteCodeInstrumentor.getClass(className); + + // trace host & port + instrumentClass.addTraceValue(MapTraceValue.class); + + // method + final List declaredMethods = instrumentClass.getDeclaredMethods(); + for (Method method : declaredMethods) { + if (method.getMethodName().equals("getResource")) { + final Interceptor methodInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.nhn.pinpoint.profiler.modifier.redis.interceptor.GatewayServerMethodInterceptor"); + instrumentClass.addInterceptor(method.getMethodName(), method.getMethodParams(), methodInterceptor); + } + } + + return instrumentClass.toBytecode(); + } catch (Exception e) { + if (logger.isWarnEnabled()) { + logger.warn("redis.GatewayModifier(nBase-ARC) fail. Target class is " + getTargetClass() + ", Caused " + e.getMessage(), e); + } + } + + return null; + } +} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisClientModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisClientModifier.java index 18c76ff10..97533c907 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisClientModifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisClientModifier.java @@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory; import com.nhn.pinpoint.bootstrap.Agent; import com.nhn.pinpoint.bootstrap.interceptor.Interceptor; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor; import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass; import com.nhn.pinpoint.profiler.modifier.AbstractModifier; @@ -40,8 +40,8 @@ public class JedisClientModifier extends AbstractModifier { try { final InstrumentClass instrumentClass = byteCodeInstrumentor.getClass(className); - // trace host & port - instrumentClass.addTraceValue(ObjectTraceValue.class); + // trace endPoint + instrumentClass.addTraceValue(MapTraceValue.class); final Interceptor constructorInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.nhn.pinpoint.profiler.modifier.redis.interceptor.JedisClientConstructorInterceptor"); instrumentClass.addConstructorInterceptor(new String[] { "java.lang.String" }, constructorInterceptor); instrumentClass.addConstructorInterceptor(new String[] { "java.lang.String", "int" }, constructorInterceptor); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisModifier.java index cc9bc54b7..5826770e0 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisModifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisModifier.java @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import com.nhn.pinpoint.bootstrap.Agent; import com.nhn.pinpoint.bootstrap.interceptor.Interceptor; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor; import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass; import com.nhn.pinpoint.profiler.interceptor.bci.Method; @@ -45,7 +45,7 @@ public class JedisModifier extends AbstractModifier { final InstrumentClass instrumentClass = byteCodeInstrumentor.getClass(className); // trace host & port - instrumentClass.addTraceValue(ObjectTraceValue.class); + instrumentClass.addTraceValue(MapTraceValue.class); final Interceptor constructorInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.nhn.pinpoint.profiler.modifier.redis.interceptor.JedisConstructorInterceptor"); instrumentClass.addConstructorInterceptor(new String[] { "java.lang.String" }, constructorInterceptor); try { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisPipelineModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisPipelineModifier.java index 7b098759f..e1356efb6 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisPipelineModifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisPipelineModifier.java @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import com.nhn.pinpoint.bootstrap.Agent; import com.nhn.pinpoint.bootstrap.interceptor.Interceptor; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor; import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass; import com.nhn.pinpoint.profiler.interceptor.bci.Method; @@ -45,7 +45,7 @@ public class JedisPipelineModifier extends AbstractModifier { final InstrumentClass instrumentClass = byteCodeInstrumentor.getClass(className); // trace host & port - instrumentClass.addTraceValue(ObjectTraceValue.class); + instrumentClass.addTraceValue(MapTraceValue.class); final Interceptor constructorInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.nhn.pinpoint.profiler.modifier.redis.interceptor.JedisPipelineConstructorInterceptor"); try { // jedis 1.x diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterModifier.java index e63c14c57..7f899d22f 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterModifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterModifier.java @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import com.nhn.pinpoint.bootstrap.Agent; import com.nhn.pinpoint.bootstrap.interceptor.Interceptor; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor; import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass; import com.nhn.pinpoint.profiler.interceptor.bci.Method; @@ -45,7 +45,7 @@ public class RedisClusterModifier extends AbstractModifier { final InstrumentClass instrumentClass = byteCodeInstrumentor.getClass(className); // trace host & port - instrumentClass.addTraceValue(ObjectTraceValue.class); + instrumentClass.addTraceValue(MapTraceValue.class); final Interceptor constructorInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.nhn.pinpoint.profiler.modifier.redis.interceptor.RedisClusterConstructorInterceptor"); instrumentClass.addConstructorInterceptor(new String[] { "java.lang.String" }, constructorInterceptor); instrumentClass.addConstructorInterceptor(new String[] { "java.lang.String", "int" }, constructorInterceptor); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterPipelineModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterPipelineModifier.java index 7ba721789..cb84f6132 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterPipelineModifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterPipelineModifier.java @@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory; import com.nhn.pinpoint.bootstrap.Agent; import com.nhn.pinpoint.bootstrap.interceptor.Interceptor; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor; import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass; import com.nhn.pinpoint.profiler.interceptor.bci.Method; @@ -45,7 +45,7 @@ public class RedisClusterPipelineModifier extends AbstractModifier { final InstrumentClass instrumentClass = byteCodeInstrumentor.getClass(className); // trace host & port - instrumentClass.addTraceValue(ObjectTraceValue.class); + instrumentClass.addTraceValue(MapTraceValue.class); final Interceptor constructorInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.nhn.pinpoint.profiler.modifier.redis.interceptor.RedisClusterPipelineConstructorInterceptor"); try { instrumentClass.addConstructorInterceptor(new String[] { "com.nhncorp.redis.cluster.gateway.GatewayServer" }, constructorInterceptor); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/GatewayConstructorInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/GatewayConstructorInterceptor.java new file mode 100644 index 000000000..f421f164c --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/GatewayConstructorInterceptor.java @@ -0,0 +1,56 @@ +package com.nhn.pinpoint.profiler.modifier.redis.interceptor; + +import java.util.HashMap; +import java.util.Map; + +import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; +import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; +import com.nhn.pinpoint.bootstrap.logging.PLogger; +import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; +import com.nhncorp.redis.cluster.gateway.GatewayConfig; + +/** + * Gateway(nBase-ARC client) constructor interceptor + * - trace destinationId + * + * @author jaehong.kim + * + */ +public class GatewayConstructorInterceptor implements SimpleAroundInterceptor, TargetClassLoader { + + private final PLogger logger = PLoggerFactory.getLogger(this.getClass()); + private final boolean isDebug = logger.isDebugEnabled(); + + @Override + public void before(Object target, Object[] args) { + if (isDebug) { + logger.beforeInterceptor(target, args); + } + + if (!(target instanceof MapTraceValue)) { + return; + } + + final GatewayConfig config = (GatewayConfig) args[0]; + final Map traceValue = new HashMap(); + try { + if (config.getDomainAddress() != null) { + traceValue.put("destinationId", config.getDomainAddress()); + } else if (config.getIpAddress() != null) { + traceValue.put("destinationId", config.getIpAddress()); + } else if (config.getClusterName() != null) { + // over 1.1.x + traceValue.put("destinationId", config.getClusterName()); + } + } catch (Exception ignored) { + // backward compatibility error + } + + ((MapTraceValue) target).__setTraceBindValue(traceValue); + } + + @Override + public void after(Object target, Object[] args, Object result, Throwable throwable) { + } +} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/GatewayMethodInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/GatewayMethodInterceptor.java new file mode 100644 index 000000000..6601f588d --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/GatewayMethodInterceptor.java @@ -0,0 +1,46 @@ +package com.nhn.pinpoint.profiler.modifier.redis.interceptor; + +import java.util.HashMap; +import java.util.Map; + +import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; +import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; +import com.nhn.pinpoint.bootstrap.logging.PLogger; +import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; + +/** + * Gateway(nBase-ARC client) getServer() method interceptor + * - trace destinationId + * + * @author jaehong.kim + * + */ +public class GatewayMethodInterceptor implements SimpleAroundInterceptor, TargetClassLoader { + private final PLogger logger = PLoggerFactory.getLogger(this.getClass()); + private final boolean isDebug = logger.isDebugEnabled(); + + @Override + public void before(Object target, Object[] args) { + } + + @Override + public void after(Object target, Object[] args, Object result, Throwable throwable) { + if (isDebug) { + logger.beforeInterceptor(target, args); + } + + if (!(target instanceof MapTraceValue) || result == null || !(result instanceof MapTraceValue)) { + return; + } + + // result - GatewayServer + final Map gatewayTraceValue = ((MapTraceValue) target).__getTraceBindValue(); + if (gatewayTraceValue != null) { + final Map traceValue = new HashMap(); + // copy to destinationId + traceValue.put("destinationId", gatewayTraceValue.get("destinationId")); + ((MapTraceValue) result).__setTraceBindValue(traceValue); + } + } +} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/GatewayServerMethodInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/GatewayServerMethodInterceptor.java new file mode 100644 index 000000000..59397aacc --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/GatewayServerMethodInterceptor.java @@ -0,0 +1,38 @@ +package com.nhn.pinpoint.profiler.modifier.redis.interceptor; + +import java.util.Map; + +import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; +import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; + +/** + * GatewayServer(nBase-ARC client) getResource() method interceptor + * - trace destinationId + * + * @author jaehong.kim + * + */ +public class GatewayServerMethodInterceptor implements SimpleAroundInterceptor, TargetClassLoader { + + @Override + public void before(Object target, Object[] args) { + } + + @Override + public void after(Object target, Object[] args, Object result, Throwable throwable) { + if (!(target instanceof MapTraceValue) || result == null || !(result instanceof MapTraceValue)) { + return; + } + + // result - RedisCluster + final Map gatewayServerTraceValue = ((MapTraceValue) target).__getTraceBindValue(); + if (gatewayServerTraceValue != null) { + final Map traceValue = ((MapTraceValue) result).__getTraceBindValue(); + // copy to destinationId + if (traceValue != null) { + traceValue.put("destinationId", gatewayServerTraceValue.get("destinationId")); + } + } + } +} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisClientConstructorInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisClientConstructorInterceptor.java index fd71df1d7..921f04daf 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisClientConstructorInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisClientConstructorInterceptor.java @@ -5,12 +5,13 @@ import java.util.Map; import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.bootstrap.logging.PLogger; import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; /** - * Redis client(jedis) constructor interceptor + * Jedis client(redis client) constructor interceptor + * - trace endPoint * * @author jaehong.kim * @@ -26,26 +27,28 @@ public class JedisClientConstructorInterceptor implements SimpleAroundIntercepto logger.beforeInterceptor(target, args); } - if (!(target instanceof ObjectTraceValue)) { + // trace endPoint + if (!(target instanceof MapTraceValue)) { return; } - // trace host & port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - final Map map = new HashMap(); + final StringBuilder endPoint = new StringBuilder(); // first arg - host if (args[0] instanceof String) { - map.put("host", args[0]); - // default port - map.put("port", 6379); + endPoint.append(args[0]); + + // second arg - port + if (args.length >= 2 && args[1] instanceof Integer) { + endPoint.append(":").append(args[1]); + } else { + // default port + endPoint.append(":").append(6379); + } } - // second arg - port - if (args.length >= 2 && args[1] instanceof Integer) { - map.put("port", args[1]); - } - - traceValue.__setTraceObject(map); + final Map traceValue = new HashMap(); + traceValue.put("endPoint", endPoint.toString()); + ((MapTraceValue) target).__setTraceBindValue(traceValue); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisConstructorInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisConstructorInterceptor.java index 839ad747a..ee433b61f 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisConstructorInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisConstructorInterceptor.java @@ -8,12 +8,13 @@ import redis.clients.jedis.JedisShardInfo; import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.bootstrap.logging.PLogger; import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; /** - * Redis client(jedis) constructor interceptor + * Jedis (redis client) constructor interceptor + * - trace endPoint * * @author jaehong.kim * @@ -22,45 +23,48 @@ public class JedisConstructorInterceptor implements SimpleAroundInterceptor, Tar private final PLogger logger = PLoggerFactory.getLogger(this.getClass()); private final boolean isDebug = logger.isDebugEnabled(); - + @Override public void before(Object target, Object[] args) { if (isDebug) { logger.beforeInterceptor(target, args); } - if (!(target instanceof ObjectTraceValue)) { + // trace endPoint + if (!(target instanceof MapTraceValue)) { return; } - // trace host & port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - final Map map = new HashMap(); - + final StringBuilder endPoint = new StringBuilder(); try { // first arg - host if (args[0] instanceof String) { - map.put("host", args[0]); - // default port - map.put("port", 6379); + endPoint.append(args[0]); + // second arg - port + if (args.length >= 2 && args[1] instanceof Integer) { + endPoint.append(":").append(args[1]); + } else { + // default port + endPoint.append(":").append(6379); + } } else if (args[0] instanceof URI) { final URI uri = (URI) args[0]; - map.put("host", uri.getHost()); - map.put("port", uri.getPort()); + endPoint.append(uri.getHost()); + endPoint.append(":"); + endPoint.append(uri.getPort()); } else if (args[0] instanceof JedisShardInfo) { final JedisShardInfo info = (JedisShardInfo) args[0]; - map.put("host", info.getHost()); - map.put("port", info.getPort()); + endPoint.append(info.getHost()); + endPoint.append(":"); + endPoint.append(info.getPort()); } - - // second arg - port - if (args.length >= 2 && args[1] instanceof Integer) { - map.put("port", args[1]); - } - traceValue.__setTraceObject(map); } catch (Exception ignored) { // expect 'class not found exception - JedisShardInfo' } + + final Map traceValue = new HashMap(); + traceValue.put("endPoint", endPoint.toString()); + ((MapTraceValue) target).__setTraceBindValue(traceValue); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisMethodInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisMethodInterceptor.java index 76434b827..2f1e43136 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisMethodInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisMethodInterceptor.java @@ -5,11 +5,11 @@ import java.util.Map; import com.nhn.pinpoint.bootstrap.context.RecordableTrace; import com.nhn.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.common.ServiceType; /** - * Redis client(jedis) method interceptor + * Jedis (redis client) method interceptor * * @author jaehong.kim * @@ -27,30 +27,17 @@ public class JedisMethodInterceptor extends SpanEventSimpleAroundInterceptor imp @Override public void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) { - String destinationId = "Unknown"; - String endPoint = "Unknown"; - if (target instanceof ObjectTraceValue) { - // find host & port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - if (traceValue.__getTraceObject() != null && traceValue.__getTraceObject() instanceof Map) { - final Map map = (Map) traceValue.__getTraceObject(); - final Object host = map.get("host"); - final Object port = map.get("port"); - - if (host != null) { - destinationId = (String) host; - if (port != null) { - endPoint = (String) host + ":" + port; - } else { - endPoint = (String) host; - } - } + String endPoint = null; + if (target instanceof MapTraceValue) { + final Map traceValue = ((MapTraceValue) target).__getTraceBindValue(); + if (traceValue != null) { + endPoint = (String) traceValue.get("endPoint"); } } trace.recordApi(getMethodDescriptor()); - trace.recordEndPoint(endPoint); - trace.recordDestinationId(destinationId); + trace.recordEndPoint(endPoint != null ? endPoint : "Unknown"); + trace.recordDestinationId(ServiceType.REDIS.toString()); trace.recordServiceType(ServiceType.REDIS); trace.recordException(throwable); trace.markAfterTime(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineConstructorInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineConstructorInterceptor.java index d9b3e401f..04f62ff7e 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineConstructorInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineConstructorInterceptor.java @@ -5,12 +5,13 @@ import java.util.Map; import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.bootstrap.logging.PLogger; import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; /** - * Redis client(jedis) constructor interceptor + * Jedis Pipeline(redis client) constructor interceptor + * - trace endPoint * * @author jaehong.kim * @@ -26,22 +27,20 @@ public class JedisPipelineConstructorInterceptor implements SimpleAroundIntercep logger.beforeInterceptor(target, args); } - if (!(target instanceof ObjectTraceValue) || !(args[0] instanceof ObjectTraceValue)) { + // trace endPoint + if (!(target instanceof MapTraceValue) || !(args[0] instanceof MapTraceValue)) { return; } - // trace host & port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - final Map map = new HashMap(); - // first arg - redis.clients.jedis.Client - final ObjectTraceValue clientTraceValue = (ObjectTraceValue) args[0]; - if (clientTraceValue.__getTraceObject() != null) { - final Map clientMap = (Map) clientTraceValue.__getTraceObject(); - map.put("host", clientMap.get("host")); - map.put("port", clientMap.get("port")); + final Map clientTraceValue = ((MapTraceValue) args[0]).__getTraceBindValue(); + if (clientTraceValue == null) { + return; } - traceValue.__setTraceObject(map); + + final Map traceValue = new HashMap(); + traceValue.put("endPoint", clientTraceValue.get("endPoint")); + ((MapTraceValue) target).__setTraceBindValue(traceValue); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineMethodInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineMethodInterceptor.java index b8da4bc19..a5a47c406 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineMethodInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineMethodInterceptor.java @@ -5,11 +5,11 @@ import java.util.Map; import com.nhn.pinpoint.bootstrap.context.RecordableTrace; import com.nhn.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.common.ServiceType; /** - * Redis client(jedis) method interceptor + * Jedis Pipeline(redis client) method interceptor * * @author jaehong.kim * @@ -27,32 +27,17 @@ public class JedisPipelineMethodInterceptor extends SpanEventSimpleAroundInterce @Override public void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) { - trace.recordApi(getMethodDescriptor()); - - String destinationId = "Unknown"; - String endPoint = "Unknown"; - - if (target instanceof ObjectTraceValue) { - // find host & port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - if (traceValue.__getTraceObject() != null) { - final Map map = (Map) traceValue.__getTraceObject(); - final Object host = map.get("host"); - final Object port = map.get("port"); - - if (host != null) { - destinationId = (String) host; - if (port != null) { - endPoint = (String) host + ":" + port; - } else { - endPoint = (String) host; - } - } + String endPoint = null; + if (target instanceof MapTraceValue) { + final Map traceValue = ((MapTraceValue) target).__getTraceBindValue(); + if (traceValue != null) { + endPoint = (String) traceValue.get("endPoint"); } } - trace.recordEndPoint(endPoint); - trace.recordDestinationId(destinationId); + trace.recordApi(getMethodDescriptor()); + trace.recordEndPoint(endPoint != null ? endPoint : "Unknown"); + trace.recordDestinationId(ServiceType.REDIS.toString()); trace.recordServiceType(ServiceType.REDIS); trace.recordException(throwable); trace.markAfterTime(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineSetClientMethodInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineSetClientMethodInterceptor.java index ec46e2998..7bf7fa2c5 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineSetClientMethodInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/JedisPipelineSetClientMethodInterceptor.java @@ -5,12 +5,12 @@ import java.util.Map; import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.bootstrap.logging.PLogger; import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; /** - * Redis client(jedis) pipeline method interceptor + * Jedis pipeline (redis client) setClient method interceptor * * @author jaehong.kim * @@ -25,24 +25,20 @@ public class JedisPipelineSetClientMethodInterceptor implements SimpleAroundInte logger.beforeInterceptor(target, args); } - if (!(target instanceof ObjectTraceValue) || !(args[0] instanceof ObjectTraceValue)) { + // trace endPoint + if (!(target instanceof MapTraceValue) || !(args[0] instanceof MapTraceValue)) { return; } - // trace host & port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - final Map map = new HashMap(); - // first arg - redis.clients.jedis.Client - final ObjectTraceValue clientTraceValue = (ObjectTraceValue) args[0]; - if (clientTraceValue.__getTraceObject() != null) { - final Map clientMap = (Map) clientTraceValue.__getTraceObject(); - map.put("host", clientMap.get("host")); - map.put("port", clientMap.get("port")); + final Map clientTraceValue = ((MapTraceValue) args[0]).__getTraceBindValue(); + if (clientTraceValue == null) { + return; } - traceValue.__setTraceObject(map); - return; + final Map traceValue = new HashMap(); + traceValue.put("endPoint", clientTraceValue.get("endPoint")); + ((MapTraceValue) target).__setTraceBindValue(traceValue); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterConstructorInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterConstructorInterceptor.java index c0731c2d9..e3ad9c824 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterConstructorInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterConstructorInterceptor.java @@ -5,12 +5,12 @@ import java.util.Map; import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.bootstrap.logging.PLogger; import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; /** - * nBase-ARC client constructor interceptor + * RedisCluster(nBase-ARC client) constructor interceptor - trace endPoint * * @author jaehong.kim * @@ -26,26 +26,27 @@ public class RedisClusterConstructorInterceptor implements SimpleAroundIntercept logger.beforeInterceptor(target, args); } - if (!(target instanceof ObjectTraceValue)) { + if (!(target instanceof MapTraceValue)) { return; } - // trace host & port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - final Map map = new HashMap(); - + // trace endPoint // first arg - host + final StringBuilder endPoint = new StringBuilder(); if (args[0] instanceof String) { - map.put("host", args[0]); - // default port - map.put("port", 6379); + endPoint.append(args[0]); + // second arg - port + if (args.length >= 2 && args[1] instanceof Integer) { + endPoint.append(":").append(args[1]); + } else { + // default port + endPoint.append(":").append(6379); + } } - // second arg - port - if (args.length >= 2 && args[1] instanceof Integer) { - map.put("port", args[1]); - } - traceValue.__setTraceObject(map); + final Map traceValue = new HashMap(); + traceValue.put("endPoint", endPoint.toString()); + ((MapTraceValue) target).__setTraceBindValue(traceValue); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterMethodInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterMethodInterceptor.java index 4b181b130..c7eebb3be 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterMethodInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterMethodInterceptor.java @@ -5,11 +5,11 @@ import java.util.Map; import com.nhn.pinpoint.bootstrap.context.RecordableTrace; import com.nhn.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.common.ServiceType; /** - * nBase-ARC client method interceptor + * RedisCluster(nBase-ARC client) method interceptor * * @author jaehong.kim * @@ -27,31 +27,19 @@ public class RedisClusterMethodInterceptor extends SpanEventSimpleAroundIntercep @Override public void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) { - String destinationId = "Unknown"; - String endPoint = "Unknown"; - if (target instanceof ObjectTraceValue) { - // find host:port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - if (traceValue.__getTraceObject() != null && traceValue.__getTraceObject() instanceof Map) { - final Map map = (Map) traceValue.__getTraceObject(); - final Object host = map.get("host"); - final Object port = map.get("port"); - - if (host != null) { - destinationId = (String) host; - if (port != null) { - endPoint = (String) host + ":" + port; - } else { - endPoint = (String) host; - } - } + String destinationId = null; + String endPoint = null; + if (target instanceof MapTraceValue) { + final Map traceValue = ((MapTraceValue) target).__getTraceBindValue(); + if (traceValue != null) { + destinationId = (String) traceValue.get("destinationId"); + endPoint = (String) traceValue.get("endPoint"); } } - System.out.println("### method: " + getMethodDescriptor().getMethodName()); trace.recordApi(getMethodDescriptor()); - trace.recordEndPoint(endPoint); - trace.recordDestinationId(destinationId); + trace.recordEndPoint(endPoint != null ? endPoint : "Unknown"); + trace.recordDestinationId(destinationId != null ? destinationId : ServiceType.NBASE_ARC.toString()); trace.recordServiceType(ServiceType.NBASE_ARC); trace.recordException(throwable); trace.markAfterTime(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterPipelineConstructorInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterPipelineConstructorInterceptor.java index cb40c089f..eee4aa0f4 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterPipelineConstructorInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterPipelineConstructorInterceptor.java @@ -5,13 +5,14 @@ import java.util.Map; import com.nhn.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.bootstrap.logging.PLogger; import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; import com.nhncorp.redis.cluster.gateway.GatewayServer; /** - * nBase-ARC client constructor interceptor + * RedisCluster pipeline(nBase-ARC client) constructor interceptor + * - trace destinationId & endPoint * * @author jaehong.kim * @@ -27,19 +28,25 @@ public class RedisClusterPipelineConstructorInterceptor implements SimpleAroundI logger.beforeInterceptor(target, args); } - if (!(target instanceof ObjectTraceValue)) { + if (!(target instanceof MapTraceValue)) { return; } - // trace host & port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - final Map map = new HashMap(); + // trace destinationId & endPoint + final Map traceValue = new HashMap(); // first arg : GatewayServer final GatewayServer server = (GatewayServer) args[0]; - map.put("host", server.getAddress().getHost()); - map.put("port", server.getAddress().getPort()); - traceValue.__setTraceObject(map); + traceValue.put("endPoint", server.getAddress().getHost() + ":" + server.getAddress().getPort()); + + if (args[0] instanceof MapTraceValue) { + final Map gatewayServerTraceValue = ((MapTraceValue) args[0]).__getTraceBindValue(); + if (gatewayServerTraceValue != null) { + traceValue.put("destinationId", gatewayServerTraceValue.get("destinationId")); + } + } + + ((MapTraceValue) target).__setTraceBindValue(traceValue); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterPipelineMethodInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterPipelineMethodInterceptor.java index 1abb1f4e6..7c2bee674 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterPipelineMethodInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/redis/interceptor/RedisClusterPipelineMethodInterceptor.java @@ -5,11 +5,11 @@ import java.util.Map; import com.nhn.pinpoint.bootstrap.context.RecordableTrace; import com.nhn.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptor; import com.nhn.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.ObjectTraceValue; +import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue; import com.nhn.pinpoint.common.ServiceType; /** - * nBase-ARC client method interceptor + * RedisCluster pipeline(nBase-ARC client) method interceptor * * @author jaehong.kim * @@ -27,31 +27,19 @@ public class RedisClusterPipelineMethodInterceptor extends SpanEventSimpleAround @Override public void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) { - String destinationId = "Unknown"; - String endPoint = "Unknown"; - if (target instanceof ObjectTraceValue) { - // find host:port - final ObjectTraceValue traceValue = (ObjectTraceValue) target; - if (traceValue.__getTraceObject() != null && traceValue.__getTraceObject() instanceof Map) { - final Map map = (Map) traceValue.__getTraceObject(); - final Object host = map.get("host"); - final Object port = map.get("port"); - - if (host != null) { - destinationId = (String) host; - if (port != null) { - endPoint = (String) host + ":" + port; - } else { - endPoint = (String) host; - } - } + String destinationId = null; + String endPoint = null; + if (target instanceof MapTraceValue) { + final Map traceValue = ((MapTraceValue) target).__getTraceBindValue(); + if (traceValue != null) { + destinationId = (String) traceValue.get("destinationId"); + endPoint = (String) traceValue.get("endPoint"); } } - System.out.println("### method: " + getMethodDescriptor().getMethodName()); trace.recordApi(getMethodDescriptor()); - trace.recordEndPoint(endPoint); - trace.recordDestinationId(destinationId); + trace.recordEndPoint(endPoint != null ? endPoint : "Unknown"); + trace.recordDestinationId(destinationId != null ? destinationId : ServiceType.NBASE_ARC.toString()); trace.recordServiceType(ServiceType.NBASE_ARC); trace.recordException(throwable); trace.markAfterTime(); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisModifierTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisModifierTest.java index 669e26a7c..b649b46ac 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisModifierTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisModifierTest.java @@ -47,7 +47,7 @@ public class JedisModifierTest extends BasePinpointTest { SpanEventBo event = spanEvents.get(0); assertEquals(HOST + ":" + PORT, event.getEndPoint()); - assertEquals(HOST, event.getDestinationId()); + assertEquals("REDIS", event.getDestinationId()); assertEquals(ServiceType.REDIS, event.getServiceType()); assertNull(event.getExceptionMessage()); } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisPipelineModifierTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisPipelineModifierTest.java index 37367157e..41f5a5106 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisPipelineModifierTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/JedisPipelineModifierTest.java @@ -49,7 +49,7 @@ public class JedisPipelineModifierTest extends BasePinpointTest { SpanEventBo event = spanEvents.get(0); assertEquals(HOST + ":" + PORT, event.getEndPoint()); - assertEquals(HOST, event.getDestinationId()); + assertEquals("REDIS", event.getDestinationId()); assertEquals(ServiceType.REDIS, event.getServiceType()); assertNull(event.getExceptionMessage()); } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterModifierTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterModifierTest.java index b5d4576d3..d52d968bf 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterModifierTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterModifierTest.java @@ -1,4 +1,3 @@ - package com.nhn.pinpoint.profiler.modifier.redis; import static org.junit.Assert.assertEquals; @@ -16,16 +15,21 @@ import com.nhn.pinpoint.common.ServiceType; import com.nhn.pinpoint.common.bo.SpanEventBo; import com.nhn.pinpoint.profiler.junit4.BasePinpointTest; import com.nhncorp.redis.cluster.RedisCluster; +import com.nhncorp.redis.cluster.gateway.GatewayClient; +import com.nhncorp.redis.cluster.gateway.GatewayConfig; public class RedisClusterModifierTest extends BasePinpointTest { private static final String HOST = "10.99.116.91"; private static final int PORT = 6390; + private static final String ZK_ADDRESS = "dev.xnbasearc.navercorp.com:2181"; + private static final String CLUSTER_NAME = "java_client_test"; private RedisCluster redis; @Before public void before() { redis = new RedisCluster(HOST, PORT); + } @Test @@ -36,12 +40,33 @@ public class RedisClusterModifierTest extends BasePinpointTest { assertEquals(1, spanEvents.size()); SpanEventBo event = spanEvents.get(0); - assertEquals(HOST, event.getDestinationId()); + assertEquals("NBASE_ARC", event.getDestinationId()); assertEquals(HOST + ":" + PORT, event.getEndPoint()); assertEquals(ServiceType.NBASE_ARC, event.getServiceType()); assertNull(event.getExceptionMessage()); } + @Test + public void traceDestinationId() { + GatewayConfig config = new GatewayConfig(); + config.setZkAddress(ZK_ADDRESS); + config.setClusterName(CLUSTER_NAME); + + GatewayClient client = new GatewayClient(config); + + client.get("foo"); + + final List spanEvents = getCurrentSpanEvents(); + SpanEventBo event = spanEvents.get(spanEvents.size() - 1); + + assertEquals(CLUSTER_NAME, event.getDestinationId()); + assertEquals(HOST + ":" + PORT, event.getEndPoint()); + assertEquals(ServiceType.NBASE_ARC, event.getServiceType()); + assertNull(event.getExceptionMessage()); + + client.destroy(); + } + @Test public void traceMethodThrowException() { // 에러가 발생한 경우에 대한 event 결과를 확인한다. diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterPipelineModifierTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterPipelineModifierTest.java index 079310696..e067e2e05 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterPipelineModifierTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/redis/RedisClusterPipelineModifierTest.java @@ -1,7 +1,6 @@ package com.nhn.pinpoint.profiler.modifier.redis; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.util.List; @@ -9,12 +8,10 @@ import java.util.List; import org.junit.Before; import org.junit.Test; -import redis.clients.jedis.exceptions.JedisDataException; import com.nhn.pinpoint.common.ServiceType; import com.nhn.pinpoint.common.bo.SpanEventBo; import com.nhn.pinpoint.profiler.junit4.BasePinpointTest; -import com.nhncorp.redis.cluster.RedisCluster; import com.nhncorp.redis.cluster.gateway.GatewayAddress; import com.nhncorp.redis.cluster.gateway.GatewayClient; import com.nhncorp.redis.cluster.gateway.GatewayConfig; @@ -24,6 +21,8 @@ import com.nhncorp.redis.cluster.pipeline.RedisClusterPipeline; public class RedisClusterPipelineModifierTest extends BasePinpointTest { private static final String HOST = "10.99.116.91"; private static final int PORT = 6390; + private static final String ZK_ADDRESS = "dev.xnbasearc.navercorp.com:2181"; + private static final String CLUSTER_NAME = "java_client_test"; private RedisClusterPipeline pipeline; @@ -46,10 +45,32 @@ public class RedisClusterPipelineModifierTest extends BasePinpointTest { assertEquals(2, spanEvents.size()); SpanEventBo event = spanEvents.get(0); - assertEquals(HOST, event.getDestinationId()); + assertEquals("NBASE_ARC", event.getDestinationId()); assertEquals(HOST + ":" + PORT, event.getEndPoint()); assertEquals(ServiceType.NBASE_ARC, event.getServiceType()); assertNull(event.getExceptionMessage()); } + + @Test + public void traceDestinationId() { + GatewayConfig config = new GatewayConfig(); + config.setZkAddress(ZK_ADDRESS); + config.setClusterName(CLUSTER_NAME); + GatewayClient client = new GatewayClient(config); + RedisClusterPipeline pipeline = client.pipeline(); + + pipeline.get("foo"); + pipeline.syncAndReturnAll(); + + final List spanEvents = getCurrentSpanEvents(); + SpanEventBo event = spanEvents.get(spanEvents.size() - 1); + + assertEquals(CLUSTER_NAME, event.getDestinationId()); + assertEquals(HOST + ":" + PORT, event.getEndPoint()); + assertEquals(ServiceType.NBASE_ARC, event.getServiceType()); + assertNull(event.getExceptionMessage()); + + client.destroy(); + } } \ No newline at end of file