#1171 Fixed a side effect of Arcus interceptor

- modify dns lookup api
  InetSocketAddress.getHostName() -> InetAddress.getHostAddress()
This commit is contained in:
emeroad
2015-11-11 14:54:05 +09:00
parent cd182945f1
commit a79a27bde7
2 changed files with 80 additions and 10 deletions
@@ -16,6 +16,7 @@
package com.navercorp.pinpoint.profiler.modifier.arcus.interceptor;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.Future;
@@ -61,11 +62,12 @@ public class ApiInterceptor extends SpanEventSimpleAroundInterceptor implements
if (result instanceof Future && !(result instanceof FrontCacheGetFuture)) {
final Operation op = getOperation(result);
if (op != null) {
MemcachedNode handlingNode = op.getHandlingNode();
SocketAddress socketAddress = handlingNode.getSocketAddress();
if (socketAddress instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) socketAddress;
trace.recordEndPoint(address.getHostName() + ":" + address.getPort());
final MemcachedNode handlingNode = op.getHandlingNode();
if (handlingNode != null) {
final String endPoint = getEndPoint(handlingNode);
if (endPoint != null) {
trace.recordEndPoint(endPoint);
}
}
} else {
logger.info("operation not found");
@@ -85,6 +87,40 @@ public class ApiInterceptor extends SpanEventSimpleAroundInterceptor implements
trace.markAfterTime();
}
private String getEndPoint(MemcachedNode handlingNode) {
// TODO duplicated code : ApiInterceptor, FutureGetInterceptor
final SocketAddress socketAddress = handlingNode.getSocketAddress();
if (socketAddress instanceof InetSocketAddress) {
final InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
final String hostAddress = getHostAddress(inetSocketAddress);
if (hostAddress == null) {
// TODO return "Unknown Host"; ?
logger.debug("hostAddress is null");
return null;
}
return hostAddress + ":" + inetSocketAddress.getPort();
} else {
if (logger.isDebugEnabled()) {
logger.debug("invalid socketAddress:{}", socketAddress);
}
return null;
}
}
private String getHostAddress(InetSocketAddress inetSocketAddress) {
if (inetSocketAddress == null) {
return null;
}
// TODO JDK 1.7 InetSocketAddress.getHostString();
// Warning : Avoid unnecessary DNS lookup (warning:InetSocketAddress.getHostName())
final InetAddress inetAddress = inetSocketAddress.getAddress();
if (inetAddress == null) {
return null;
}
return inetAddress.getHostAddress();
}
private Operation getOperation(Object result) {
// __operation -> ObjectTraceValue1.class
final Object operationObject = ObjectTraceValue1Utils.__getTraceObject1(result, null);
@@ -16,6 +16,7 @@
package com.navercorp.pinpoint.profiler.modifier.arcus.interceptor;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@@ -77,12 +78,11 @@ public class FutureGetInterceptor implements SimpleAroundInterceptor, ByteCodeMe
// find the target node
final Operation op = getOperation(target);
if (op != null) {
MemcachedNode handlingNode = op.getHandlingNode();
final MemcachedNode handlingNode = op.getHandlingNode();
if (handlingNode != null) {
SocketAddress socketAddress = handlingNode.getSocketAddress();
if (socketAddress instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) socketAddress;
trace.recordEndPoint(address.getHostName() + ":" + address.getPort());
final String endPoint = getEndPoint(handlingNode);
if (endPoint != null) {
trace.recordEndPoint(endPoint);
}
trace.recordException(op.getException());
} else {
@@ -113,6 +113,40 @@ public class FutureGetInterceptor implements SimpleAroundInterceptor, ByteCodeMe
}
}
private String getEndPoint(MemcachedNode handlingNode) {
// TODO duplicated code : ApiInterceptor, FutureGetInterceptor
final SocketAddress socketAddress = handlingNode.getSocketAddress();
if (socketAddress instanceof InetSocketAddress) {
final InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
final String hostAddress = getHostAddress(inetSocketAddress);
if (hostAddress == null) {
// TODO return "Unknown Host";
logger.debug("hostAddress is null");
return null;
}
return hostAddress + ":" + inetSocketAddress.getPort();
} else {
if (logger.isDebugEnabled()) {
logger.debug("invalid socketAddress:{}", socketAddress);
}
return null;
}
}
private String getHostAddress(InetSocketAddress inetSocketAddress) {
if (inetSocketAddress == null) {
return null;
}
// TODO JDK 1.7 InetSocketAddress.getHostString();
// Warning : Avoid unnecessary DNS lookup (warning:InetSocketAddress.getHostName())
final InetAddress inetAddress = inetSocketAddress.getAddress();
if (inetAddress == null) {
return null;
}
return inetAddress.getHostAddress();
}
// __operation -> ObjectTraceValue1.class
private Operation getOperation(Object target) {
final Object operationObject = ObjectTraceValue1Utils.__getTraceObject1(target, null);