[강운덕] [LUCYSUS-1744] http::1.1 이런식으로 안나오도록 destination 에 대한 스펙을 다시 생각하여 구현함. 데이터가 중복되어 있어 추가 정리가 필요하고 좀더 정규화가 필요함.

-추가 제거 되어야 될 데이터 : serverName, subspan의 endpoint

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@1261 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Woonduk Kang
2013-02-27 10:04:56 +00:00
parent 012aaf38fe
commit c569b8a601
21 changed files with 149 additions and 44 deletions
@@ -100,11 +100,22 @@ public class AsyncTrace {
subSpan.addAnnotation(new Annotation(key, value));
}
public void recordRpcName(final ServiceType serviceType, final String service, final String rpc) {
public void recordServiceType(final ServiceType serviceType) {
this.subSpan.setServiceType(serviceType);
this.subSpan.setServiceName(service);
this.subSpan.setRpc(rpc);
}
public void recordServiceName(final String serviceName) {
this.subSpan.setServiceName(serviceName);
}
public void recordRpcName(final String rpcName) {
this.subSpan.setRpc(rpcName);
}
public void recordDestinationId(String destinationId) {
this.subSpan.setDestionationId(destinationId);
}
// TODO: final String... endPoint로 받으면 합치는데 비용이 들어가 그냥 한번에 받는게 나을것 같음.
@@ -150,4 +161,6 @@ public class AsyncTrace {
}
return false;
}
}
@@ -22,8 +22,12 @@ public class SubSpan implements Thriftable {
private String serviceName;
private String rpc;
private ServiceType serviceType;
private String endPoint;
private String destionationId;
private List<String> destinationAddress;
private final List<Annotation> annotations = new ArrayList<Annotation>(5);
private int nextSpanId = -1;
@@ -81,6 +85,22 @@ public class SubSpan implements Thriftable {
this.endPoint = endPoint;
}
public String getDestionationId() {
return destionationId;
}
public void setDestionationId(String destionationId) {
this.destionationId = destionationId;
}
public List<String> getDestinationAddress() {
return destinationAddress;
}
public void setDestinationAddress(List<String> destinationAddress) {
this.destinationAddress = destinationAddress;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
@@ -180,6 +200,7 @@ public class SubSpan implements Thriftable {
}
subSpan.setEndPoint(endPoint);
subSpan.setDestinationId(this.destionationId);
// 여기서 데이터 인코딩을 하자.
List<com.profiler.common.dto.thrift.Annotation> annotationList = new ArrayList<com.profiler.common.dto.thrift.Annotation>(annotations.size());
@@ -198,4 +219,8 @@ public class SubSpan implements Thriftable {
return subSpan;
}
public void setDestinationAddress() {
//To change body of created methods use File | Settings | File Templates.
}
}
@@ -58,6 +58,7 @@ public class SubSpanList implements Thriftable {
tSubSpan.setServiceType(subSpan.getServiceType().getCode());
tSubSpan.setEndPoint(subSpan.getEndPoint());
tSubSpan.setDestinationId(subSpan.getDestionationId());
// 여기서 데이터 인코딩을 하자.
List<com.profiler.common.dto.thrift.Annotation> annotationList = new ArrayList<com.profiler.common.dto.thrift.Annotation>(subSpan.getAnnotationSize());
@@ -6,6 +6,7 @@ import com.profiler.common.util.ParsingResult;
import com.profiler.interceptor.MethodDescriptor;
import com.profiler.logging.LoggingUtils;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -315,6 +316,28 @@ public final class Trace {
}
public void recordDestinationId(final String destinationId) {
// TODO API 단일화 필요.
StackFrame currentStackFrame = getCurrentStackFrame();
if (currentStackFrame instanceof SubStackFrame) {
SubSpan subSpan = ((SubStackFrame) currentStackFrame).getSubSpan();
subSpan.setDestionationId(destinationId);
}
}
public void recordDestinationAddress(List<String> address) {
// TODO API 단일화 필요.
StackFrame currentStackFrame = getCurrentStackFrame();
if (currentStackFrame instanceof SubStackFrame) {
SubSpan subSpan = ((SubStackFrame) currentStackFrame).getSubSpan();
subSpan.setDestinationAddress();
}
}
public void recordDestinationAddressList(List<String> addressList) {
//To change body of created methods use File | Settings | File Templates.
}
public void recordEndPoint(final String endPoint) {
// TODO API 단일화 필요.
StackFrame currentStackFrame = getCurrentStackFrame();
@@ -364,4 +387,6 @@ public final class Trace {
this.traceContext = traceContext;
}
}
@@ -72,8 +72,12 @@ public class BaseOperationTransitionStateInterceptor implements StaticBeforeInte
if(serviceCode.equals(ServiceType.MEMCACHED.getDesc())) {
svcType = ServiceType.MEMCACHED;
}
asyncTrace.recordRpcName(svcType, serviceCode, baseOperation.getClass().getSimpleName());
asyncTrace.recordServiceType(svcType);
asyncTrace.recordServiceName(serviceCode);
asyncTrace.recordRpcName(baseOperation.getClass().getSimpleName());
asyncTrace.recordDestinationId(serviceCode);
String cmd = getCommand(baseOperation);
asyncTrace.recordAttibute(AnnotationKey.ARCUS_COMMAND, cmd);
@@ -73,6 +73,7 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
trace.recordEndPoint(request.protocol().toString() + ":" + request.serverName().toString() + ":" + request.getServerPort());
trace.recordDestinationId(request.serverName().toString() + ":" + request.getServerPort());
trace.recordAttribute(AnnotationKey.HTTP_URL, request.requestURI().toString());
if (parameters != null && parameters.length() > 0) {
trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters);
@@ -67,6 +67,7 @@ public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteC
int port = host.getPort();
trace.recordEndPoint(request.getProtocolVersion() + ":" + host.getHostName() + ((port > 0) ? ":" + port : ""));
trace.recordDestinationId(host.getHostName() + ((port > 0) ? ":" + port : ""));
trace.recordAttribute(AnnotationKey.HTTP_URL, request.getRequestLine().getUri());
}
@@ -68,6 +68,8 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
int port = host.getPort();
trace.recordEndPoint(request.getProtocolVersion() + ":" + host.getHostName() + ((port > 0) ? ":" + port : ""));
trace.recordDestinationId(host.getHostName() + ((port > 0) ? ":" + port : ""));
trace.recordAttribute(AnnotationKey.HTTP_URL, request.getRequestLine().getUri());
}
@@ -13,6 +13,7 @@ import com.profiler.util.MetaObject;
import com.profiler.util.StringUtils;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -77,6 +78,10 @@ public class DriverConnectInterceptor implements StaticAroundInterceptor, ByteCo
trace.recordRpcName(databaseInfo.getUrl());
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
trace.recordApi(descriptor, new Object[]{args[0]});
trace.recordException(result);
@@ -52,6 +52,8 @@ public class PreparedStatementCreateInterceptor implements StaticAroundIntercept
trace.recordRpcName(databaseInfo.getUrl());
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
}
@@ -56,6 +56,9 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
trace.recordRpcName(databaseInfo.getUrl());
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
ParsingResult parsingResult = (ParsingResult) getSql.invoke(target);
trace.recordSqlParsingResult(parsingResult);
@@ -53,6 +53,8 @@ public class StatementExecuteQueryInterceptor implements StaticAroundInterceptor
trace.recordRpcName(databaseInfo.getUrl());
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
} catch (Exception e) {
@@ -54,6 +54,9 @@ public class StatementExecuteUpdateInterceptor implements StaticAroundIntercepto
trace.recordRpcName(databaseInfo.getUrl());
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
trace.recordApi(descriptor);
if (args.length > 0) {
Object arg = args[0];
@@ -84,6 +84,8 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
}
private void afterStartTransaction(Trace trace, Connection target, Object[] arg, Object result) {
@@ -135,6 +137,8 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
trace.recordRpcName(databaseInfo.getUrl());
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
// trace.record(Annotation.ClientSend);
}
@@ -148,6 +152,8 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
trace.recordRpcName(databaseInfo.getUrl());
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
trace.recordApi(descriptor);
// trace.recordApi(apiId);
@@ -184,6 +190,8 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
trace.recordRpcName(databaseInfo.getUrl());
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
}
private void afterRollback(Trace trace, Connection target, Object result) {
@@ -196,6 +204,8 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
trace.recordRpcName(databaseInfo.getUrl());
trace.recordEndPoint(databaseInfo.getUrl());
trace.recordDestinationId(databaseInfo.getDatabaseId());
trace.recordDestinationAddress(databaseInfo.getHost());
trace.recordApi(descriptor);
// trace.recordApi(apiId);
@@ -2,6 +2,8 @@ package com.profiler.modifier.db.util;
import com.profiler.common.ServiceType;
import java.util.List;
/**
*
*/
@@ -13,30 +15,23 @@ public class DatabaseInfo {
// 입력된 url을 보정하지 않은 값
private String realUrl;
private String normalizedUrl;
private String host;
private String port;
private List<String> host;
public DatabaseInfo(ServiceType type, ServiceType executeQueryType, String realUrl, String normalizedUrl, String host, String port, String databaseId) {
public DatabaseInfo(ServiceType type, ServiceType executeQueryType, String realUrl, String normalizedUrl, List<String> host, String databaseId) {
this.type = type;
this.executeQueryType = executeQueryType;
this.realUrl = realUrl;
this.normalizedUrl = normalizedUrl;
this.host = host;
this.port = port;
this.databaseId = databaseId;
}
@Deprecated
public String getHost() {
public List<String> getHost() {
// host와 port의 경우 replication 설정등으로 n개가 될수 있어 애매하다.
return host;
}
@Deprecated
public String getPort() {
// host와 port의 경우 replication 설정등으로 n개가 될수 있어 애매하다.
return port;
}
public String getDatabaseId() {
return databaseId;
@@ -66,10 +61,7 @@ public class DatabaseInfo {
", databaseId='" + databaseId + '\'' +
", realUrl='" + realUrl + '\'' +
", normalizedUrl='" + normalizedUrl + '\'' +
", host='" + host + '\'' +
", port='" + port + '\'' +
", host=" + host +
'}';
}
}
@@ -2,6 +2,9 @@ package com.profiler.modifier.db.util;
import com.profiler.common.ServiceType;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@@ -14,8 +17,9 @@ public class JDBCUrlParser {
if (lowCaseURL.startsWith("jdbc:oracle")) {
return parseOracle(url);
}
return new DatabaseInfo(ServiceType.UNKNOWN_DB, ServiceType.UNKNOWN_DB_EXECUTE_QUERY, url, url, "error", "error", "error");
List<String> list = new ArrayList<String>();
list.add("error");
return new DatabaseInfo(ServiceType.UNKNOWN_DB, ServiceType.UNKNOWN_DB_EXECUTE_QUERY, url, url, list, "error");
// else if (url.indexOf("jdbc:oracle") >= 0) {
// maker.lower().after("jdbc:oracle:").after(':');
// info.type = TYPE.ORACLE;
@@ -72,10 +76,14 @@ public class JDBCUrlParser {
// jdbc:mysql://10.98.133.22:3306/test_lucy_db
StringMaker maker = new StringMaker(url);
maker.after("jdbc:mysql:");
String host = maker.after("//").before('/').before(':').value();
String port = maker.next().after(':').before('/').value();
// 10.98.133.22:3306 replacation driver같은 경우 n개가 가능할듯.
String host = maker.after("//").before('/').value();
List<String> hostList = new ArrayList<String>(1);
hostList.add(host);
// String port = maker.next().after(':').before('/').value();
String databaseId = maker.next().afterLast('/').before('?').value();
String normalizedUrl = maker.clear().before('?').value();
return new DatabaseInfo(ServiceType.MYSQL, ServiceType.MYSQL_EXECUTE_QUERY, url, normalizedUrl, host, port, databaseId);
return new DatabaseInfo(ServiceType.MYSQL, ServiceType.MYSQL_EXECUTE_QUERY, url, normalizedUrl, hostList, databaseId);
}
}
@@ -5,10 +5,7 @@ import java.util.logging.Logger;
import com.profiler.common.ServiceType;
import com.profiler.context.Trace;
import com.profiler.context.TraceContext;
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
import com.profiler.interceptor.MethodDescriptor;
import com.profiler.interceptor.StaticAroundInterceptor;
import com.profiler.interceptor.TraceContextSupport;
import com.profiler.interceptor.*;
import com.profiler.logging.LoggingUtils;
/**
@@ -16,13 +13,14 @@ import com.profiler.logging.LoggingUtils;
* @author netspider
*
*/
public class MethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport {
public class MethodInterceptor implements StaticAroundInterceptor, ByteCodeMethodDescriptorSupport, ServiceTypeSupport, TraceContextSupport {
private final Logger logger = Logger.getLogger(MethodInterceptor.class.getName());
private final boolean isDebug = LoggingUtils.isDebug(logger);
private MethodDescriptor descriptor;
private TraceContext traceContext;
private ServiceType serviceType = ServiceType.INTERNAL_METHOD;
@Override
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
@@ -36,7 +34,7 @@ public class MethodInterceptor implements StaticAroundInterceptor, ByteCodeMetho
}
trace.traceBlockBegin();
trace.recordServiceType(ServiceType.INTERNAL_METHOD);
trace.recordServiceType(serviceType);
// trace.recordRpcName(ServiceType.INTERNAL_METHOD, null, null);
trace.markBeforeTime();
}
@@ -58,7 +56,11 @@ public class MethodInterceptor implements StaticAroundInterceptor, ByteCodeMetho
trace.traceBlockEnd();
}
@Override
public void setServiceType(ServiceType serviceType) {
this.serviceType = serviceType;
}
@Override
public void setMethodDescriptor(MethodDescriptor descriptor) {
this.descriptor = descriptor;
TraceContext traceContext = TraceContext.getTraceContext();
@@ -5,6 +5,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import com.profiler.Agent;
import com.profiler.common.ServiceType;
import com.profiler.interceptor.Interceptor;
import com.profiler.interceptor.bci.ByteCodeInstrumentor;
import com.profiler.interceptor.bci.InstrumentClass;
@@ -37,14 +38,18 @@ public class SpringFrameworkServletModifier extends AbstractModifier {
try {
Interceptor doGetInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
Interceptor doPostInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
setServiceType(doGetInterceptor, ServiceType.SPRING_MVC);
setTraceContext(doGetInterceptor);
Interceptor doPostInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.profiler.modifier.method.interceptors.MethodInterceptor");
setServiceType(doPostInterceptor, ServiceType.SPRING_MVC);
setTraceContext(doPostInterceptor);
setTraceContext(doGetInterceptor);
setTraceContext(doPostInterceptor);
InstrumentClass servlet = byteCodeInstrumentor.getClass(javassistClassName);
servlet.addInterceptor("doGet", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, doGetInterceptor);
servlet.addInterceptor("doPost", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, doPostInterceptor);
return servlet.toBytecode();
@@ -94,6 +94,7 @@ public class DoXXXInterceptor implements StaticAroundInterceptor, ByteCodeMethod
int port = request.getServerPort();
trace.recordEndPoint(request.getProtocol() + ":" + request.getServerName() + ((port > 0) ? ":" + port : ""));
trace.recordDestinationId(request.getServerName() + ((port > 0) ? ":" + port : ""));
trace.recordAttribute(AnnotationKey.HTTP_URL, request.getRequestURI());
} catch (Exception e) {
if (logger.isLoggable(Level.WARNING)) {
@@ -71,7 +71,7 @@ public class StandardHostValveInvokeInterceptor implements StaticAroundIntercept
trace.recordRpcName(requestURL);
int port = request.getServerPort();
trace.recordEndPoint(request.getProtocol() + ":" + request.getServerName() + ((port > 0) ? ":" + port : ""));
trace.recordEndPoint(request.getServerName() + ((port > 0) ? ":" + port : ""));
trace.recordRemoteAddr(remoteAddr);
trace.recordAttribute(AnnotationKey.HTTP_URL, request.getRequestURI());
} catch (Exception e) {