#7 add pipeline & trace destination id

This commit is contained in:
Jaehong Kim
2014-09-24 18:38:47 +09:00
parent f6a0aedccd
commit 4d4738ded7
27 changed files with 496 additions and 200 deletions
@@ -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<String, Object> value);
Map<String, Object> __getTraceBindValue();
}
@@ -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),
/**
@@ -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));
}
@@ -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<Method> 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;
}
}
@@ -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<Method> 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;
}
}
@@ -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);
@@ -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 {
@@ -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
@@ -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);
@@ -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);
@@ -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<String, Object> traceValue = new HashMap<String, Object>();
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) {
}
}
@@ -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<String, Object> gatewayTraceValue = ((MapTraceValue) target).__getTraceBindValue();
if (gatewayTraceValue != null) {
final Map<String, Object> traceValue = new HashMap<String, Object>();
// copy to destinationId
traceValue.put("destinationId", gatewayTraceValue.get("destinationId"));
((MapTraceValue) result).__setTraceBindValue(traceValue);
}
}
}
@@ -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<String, Object> gatewayServerTraceValue = ((MapTraceValue) target).__getTraceBindValue();
if (gatewayServerTraceValue != null) {
final Map<String, Object> traceValue = ((MapTraceValue) result).__getTraceBindValue();
// copy to destinationId
if (traceValue != null) {
traceValue.put("destinationId", gatewayServerTraceValue.get("destinationId"));
}
}
}
}
@@ -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<String, Object> map = new HashMap<String, Object>();
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<String, Object> traceValue = new HashMap<String, Object>();
traceValue.put("endPoint", endPoint.toString());
((MapTraceValue) target).__setTraceBindValue(traceValue);
}
@Override
@@ -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<String, Object> map = new HashMap<String, Object>();
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<String, Object> traceValue = new HashMap<String, Object>();
traceValue.put("endPoint", endPoint.toString());
((MapTraceValue) target).__setTraceBindValue(traceValue);
}
@Override
@@ -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<String, Object> map = (Map<String, Object>) 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<String, Object> 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();
@@ -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<String, Object> map = new HashMap<String, Object>();
// first arg - redis.clients.jedis.Client
final ObjectTraceValue clientTraceValue = (ObjectTraceValue) args[0];
if (clientTraceValue.__getTraceObject() != null) {
final Map<String, Object> clientMap = (Map<String, Object>) clientTraceValue.__getTraceObject();
map.put("host", clientMap.get("host"));
map.put("port", clientMap.get("port"));
final Map<String, Object> clientTraceValue = ((MapTraceValue) args[0]).__getTraceBindValue();
if (clientTraceValue == null) {
return;
}
traceValue.__setTraceObject(map);
final Map<String, Object> traceValue = new HashMap<String, Object>();
traceValue.put("endPoint", clientTraceValue.get("endPoint"));
((MapTraceValue) target).__setTraceBindValue(traceValue);
}
@Override
@@ -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<String, Object> map = (Map<String, Object>) 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<String, Object> 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();
@@ -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<String, Object> map = new HashMap<String, Object>();
// first arg - redis.clients.jedis.Client
final ObjectTraceValue clientTraceValue = (ObjectTraceValue) args[0];
if (clientTraceValue.__getTraceObject() != null) {
final Map<String, Object> clientMap = (Map<String, Object>) clientTraceValue.__getTraceObject();
map.put("host", clientMap.get("host"));
map.put("port", clientMap.get("port"));
final Map<String, Object> clientTraceValue = ((MapTraceValue) args[0]).__getTraceBindValue();
if (clientTraceValue == null) {
return;
}
traceValue.__setTraceObject(map);
return;
final Map<String, Object> traceValue = new HashMap<String, Object>();
traceValue.put("endPoint", clientTraceValue.get("endPoint"));
((MapTraceValue) target).__setTraceBindValue(traceValue);
}
@Override
@@ -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<String, Object> map = new HashMap<String, Object>();
// 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<String, Object> traceValue = new HashMap<String, Object>();
traceValue.put("endPoint", endPoint.toString());
((MapTraceValue) target).__setTraceBindValue(traceValue);
}
@Override
@@ -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<String, Object> map = (Map<String, Object>) 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<String, Object> 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();
@@ -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<String, Object> map = new HashMap<String, Object>();
// trace destinationId & endPoint
final Map<String, Object> traceValue = new HashMap<String, Object>();
// 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<String, Object> gatewayServerTraceValue = ((MapTraceValue) args[0]).__getTraceBindValue();
if (gatewayServerTraceValue != null) {
traceValue.put("destinationId", gatewayServerTraceValue.get("destinationId"));
}
}
((MapTraceValue) target).__setTraceBindValue(traceValue);
}
@Override
@@ -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<String, Object> map = (Map<String, Object>) 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<String, Object> 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();
@@ -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());
}
@@ -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());
}
@@ -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<SpanEventBo> 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 결과를 확인한다.
@@ -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<SpanEventBo> 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();
}
}