mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-16 16:28:48 +10:00
[유치수] [NOBTS] remove terminal:boolean from thrift obj.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@919 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -1,178 +1,164 @@
|
||||
package com.profiler.context;
|
||||
|
||||
import com.profiler.common.util.AnnotationTranscoder;
|
||||
import com.profiler.sender.DataSender;
|
||||
|
||||
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.common.ServiceType;
|
||||
import com.profiler.sender.DataSender;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AsyncTrace {
|
||||
private Logger logger = Logger.getLogger(this.getClass().getName());
|
||||
private Logger logger = Logger.getLogger(this.getClass().getName());
|
||||
|
||||
public static final int NON_REGIST = -1;
|
||||
// private int id;
|
||||
// 비동기일 경우 traceenable의 경우 애매함. span을 보내는것으로 데이터를 생성하므로 약간 이상.
|
||||
// private boolean tracingEnabled;
|
||||
public static final int NON_REGIST = -1;
|
||||
// private int id;
|
||||
// 비동기일 경우 traceenable의 경우 애매함. span을 보내는것으로 데이터를 생성하므로 약간 이상.
|
||||
// private boolean tracingEnabled;
|
||||
|
||||
public static final int STATE_INIT = 0;
|
||||
public static final int STATE_FIRE = 1;
|
||||
public static final int STATE_TIMEOUT = 2;
|
||||
public static final int STATE_INIT = 0;
|
||||
public static final int STATE_FIRE = 1;
|
||||
public static final int STATE_TIMEOUT = 2;
|
||||
|
||||
private final AtomicInteger state = new AtomicInteger(STATE_INIT);
|
||||
|
||||
private final AtomicInteger state = new AtomicInteger(STATE_INIT);
|
||||
private int asyncId = NON_REGIST;
|
||||
private Span span;
|
||||
private DataSender dataSender;
|
||||
private TimerTask timeoutTask;
|
||||
|
||||
private int asyncId = NON_REGIST;
|
||||
private Span span;
|
||||
private DataSender dataSender;
|
||||
private TimerTask timeoutTask;
|
||||
public AsyncTrace(Span span) {
|
||||
this.span = span;
|
||||
}
|
||||
|
||||
public AsyncTrace(Span span) {
|
||||
this.span = span;
|
||||
}
|
||||
public void setDataSender(DataSender dataSender) {
|
||||
this.dataSender = dataSender;
|
||||
}
|
||||
|
||||
public void setDataSender(DataSender dataSender) {
|
||||
this.dataSender = dataSender;
|
||||
}
|
||||
public void setTimeoutTask(TimerTask timeoutTask) {
|
||||
this.timeoutTask = timeoutTask;
|
||||
}
|
||||
|
||||
public void setTimeoutTask(TimerTask timeoutTask) {
|
||||
this.timeoutTask = timeoutTask;
|
||||
}
|
||||
public void setAsyncId(int asyncId) {
|
||||
this.asyncId = asyncId;
|
||||
}
|
||||
|
||||
public void setAsyncId(int asyncId) {
|
||||
this.asyncId = asyncId;
|
||||
}
|
||||
public int getAsyncId() {
|
||||
return asyncId;
|
||||
}
|
||||
|
||||
public int getAsyncId() {
|
||||
return asyncId;
|
||||
}
|
||||
public Span getSpan() {
|
||||
return span;
|
||||
}
|
||||
|
||||
public Span getSpan() {
|
||||
return span;
|
||||
}
|
||||
private Object attachObject;
|
||||
|
||||
private Object attachObject;
|
||||
public Object getAttachObject() {
|
||||
return attachObject;
|
||||
}
|
||||
|
||||
public Object getAttachObject() {
|
||||
return attachObject;
|
||||
}
|
||||
public void setAttachObject(Object attachObject) {
|
||||
this.attachObject = attachObject;
|
||||
}
|
||||
|
||||
public void setAttachObject(Object attachObject) {
|
||||
this.attachObject = attachObject;
|
||||
}
|
||||
public void traceBlockBegin() {
|
||||
}
|
||||
|
||||
public void traceBlockBegin() {
|
||||
}
|
||||
public void markBeforeTime() {
|
||||
span.setStartTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void markBeforeTime() {
|
||||
span.setStartTime(System.currentTimeMillis());
|
||||
}
|
||||
public long getBeforeTime() {
|
||||
return span.getStartTime();
|
||||
}
|
||||
|
||||
public long getBeforeTime() {
|
||||
return span.getStartTime();
|
||||
}
|
||||
public void traceBlockEnd() {
|
||||
logSpan(this.span);
|
||||
}
|
||||
|
||||
public void traceBlockEnd() {
|
||||
logSpan(this.span);
|
||||
}
|
||||
public void markAfterTime() {
|
||||
span.setEndTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void markAfterTime() {
|
||||
span.setEndTime(System.currentTimeMillis());
|
||||
}
|
||||
public void record(Annotation annotation) {
|
||||
annotate(annotation.getCode());
|
||||
}
|
||||
|
||||
public void record(Annotation annotation) {
|
||||
annotate(annotation.getCode());
|
||||
}
|
||||
public void recordAttribute(final String key, final String value) {
|
||||
recordAttibute(key, (Object) value);
|
||||
}
|
||||
|
||||
public void recordAttibute(final String key, final Object value) {
|
||||
span.addAnnotation(new HippoAnnotation(System.currentTimeMillis(), key, value));
|
||||
}
|
||||
|
||||
public void recordAttribute(final String key, final String value) {
|
||||
recordAttibute(key, (Object) value);
|
||||
}
|
||||
public void recordMessage(String key) {
|
||||
annotate(key);
|
||||
}
|
||||
|
||||
public void recordAttibute(final String key, final Object value) {
|
||||
span.addAnnotation(new HippoAnnotation(System.currentTimeMillis(), key, value));
|
||||
}
|
||||
public void recordRpcName(final ServiceType serviceType, final String service, final String rpc) {
|
||||
try {
|
||||
this.span.setServiceType(serviceType);
|
||||
this.span.setServiceName(service);
|
||||
this.span.setRpc(rpc);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void recordMessage(String key) {
|
||||
annotate(key);
|
||||
}
|
||||
// TODO: final String... endPoint로 받으면 합치는데 비용이 들어가 그냥 한번에 받는게 나을것 같음.
|
||||
public void recordEndPoint(final String endPoint) {
|
||||
try {
|
||||
this.span.setEndPoint(endPoint);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void recordRpcName(final String service, final String rpc) {
|
||||
try {
|
||||
this.span.setServiceName(service);
|
||||
this.span.setRpc(rpc);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
private void annotate(final String key) {
|
||||
|
||||
public void recordTerminalEndPoint(final String endPoint) {
|
||||
recordEndPoint(endPoint, true);
|
||||
}
|
||||
try {
|
||||
this.span.addAnnotation(new HippoAnnotation(System.currentTimeMillis(), key));
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void recordEndPoint(final String endPoint) {
|
||||
recordEndPoint(endPoint, false);
|
||||
}
|
||||
void logSpan(Span span) {
|
||||
try {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
Thread thread = Thread.currentThread();
|
||||
logger.info("[WRITE SPAN]" + span + " CurrentThreadID=" + thread.getId() + ",\n\t CurrentThreadName=" + thread.getName());
|
||||
}
|
||||
|
||||
// TODO: final String... endPoint로 받으면 합치는데 비용이 들어가 그냥 한번에 받는게 나을것 같음.
|
||||
private void recordEndPoint(final String endPoint, final boolean isTerminal) {
|
||||
try {
|
||||
this.span.setEndPoint(endPoint);
|
||||
this.span.setTerminal(isTerminal);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
this.dataSender.send(span.toThrift());
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void annotate(final String key) {
|
||||
|
||||
try {
|
||||
this.span.addAnnotation(new HippoAnnotation(System.currentTimeMillis(), key));
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void logSpan(Span span) {
|
||||
try {
|
||||
if (logger.isLoggable(Level.INFO)) {
|
||||
Thread thread = Thread.currentThread();
|
||||
logger.info("[WRITE SPAN]" + span + " CurrentThreadID=" + thread.getId() + ",\n\t CurrentThreadName=" + thread.getName());
|
||||
}
|
||||
|
||||
this.dataSender.send(span.toThrift());
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state.get();
|
||||
}
|
||||
|
||||
public void timeout() {
|
||||
if (state.compareAndSet(STATE_INIT, STATE_TIMEOUT)) {
|
||||
// TODO timeout span log 던지기.
|
||||
// 뭘 어떤 내용을 던져야 되는지 아직 모르겠음????
|
||||
}
|
||||
}
|
||||
|
||||
public boolean fire() {
|
||||
if (state.compareAndSet(STATE_INIT, STATE_FIRE)) {
|
||||
if (timeoutTask != null) {
|
||||
// timeout이 걸려 있는 asynctrace일 경우 호출해 준다.
|
||||
this.timeoutTask.cancel();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public int getState() {
|
||||
return state.get();
|
||||
}
|
||||
|
||||
public void timeout() {
|
||||
if (state.compareAndSet(STATE_INIT, STATE_TIMEOUT)) {
|
||||
// TODO timeout span log 던지기.
|
||||
// 뭘 어떤 내용을 던져야 되는지 아직 모르겠음????
|
||||
}
|
||||
}
|
||||
|
||||
public boolean fire() {
|
||||
if (state.compareAndSet(STATE_INIT, STATE_FIRE)) {
|
||||
if (timeoutTask != null) {
|
||||
// timeout이 걸려 있는 asynctrace일 경우 호출해 준다.
|
||||
this.timeoutTask.cancel();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ public class Span implements Thriftable {
|
||||
private String rpc;
|
||||
private ServiceType serviceType;
|
||||
private String endPoint;
|
||||
private boolean isTerminal = false;
|
||||
|
||||
private final List<HippoAnnotation> annotations = new ArrayList<HippoAnnotation>(5);
|
||||
|
||||
@@ -64,14 +63,6 @@ public class Span implements Thriftable {
|
||||
this.endPoint = endPoint;
|
||||
}
|
||||
|
||||
public boolean isTerminal() {
|
||||
return isTerminal;
|
||||
}
|
||||
|
||||
public void setTerminal(boolean isTerminal) {
|
||||
this.isTerminal = isTerminal;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
@@ -133,7 +124,6 @@ public class Span implements Thriftable {
|
||||
span.setSpanId(traceID.getSpanId());
|
||||
span.setParentSpanId(traceID.getParentSpanId());
|
||||
span.setEndPoint(endPoint);
|
||||
span.setTerminal(isTerminal);
|
||||
|
||||
// 여기서 데이터 인코딩을 하자.
|
||||
List<com.profiler.common.dto.thrift.Annotation> annotationList = new ArrayList<com.profiler.common.dto.thrift.Annotation>(annotations.size());
|
||||
|
||||
@@ -283,23 +283,14 @@ public final class Trace {
|
||||
}
|
||||
}
|
||||
|
||||
public void recordTerminalEndPoint(final String endPoint) {
|
||||
recordEndPoint(endPoint, true);
|
||||
}
|
||||
|
||||
public void recordEndPoint(final String endPoint) {
|
||||
recordEndPoint(endPoint, false);
|
||||
}
|
||||
|
||||
// TODO: final String... endPoint로 받으면 합치는데 비용이 들어가 그냥 한번에 받는게 나을것 같음.
|
||||
private void recordEndPoint(final String endPoint, final boolean isTerminal) {
|
||||
public void recordEndPoint(final String endPoint) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
|
||||
try {
|
||||
Span span = getCurrentStackFrame().getSpan();
|
||||
span.setEndPoint(endPoint);
|
||||
span.setTerminal(isTerminal);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
|
||||
+4
-3
@@ -12,6 +12,7 @@ import net.spy.memcached.MemcachedNode;
|
||||
import net.spy.memcached.ops.OperationState;
|
||||
import net.spy.memcached.protocol.BaseOperationImpl;
|
||||
|
||||
import com.profiler.common.ServiceType;
|
||||
import com.profiler.context.AsyncTrace;
|
||||
import com.profiler.interceptor.StaticBeforeInterceptor;
|
||||
import com.profiler.util.InterceptorUtils;
|
||||
@@ -56,16 +57,16 @@ public class BaseOperationTransitionStateInterceptor implements StaticBeforeInte
|
||||
SocketAddress socketAddress = handlingNode.getSocketAddress();
|
||||
if (socketAddress instanceof InetSocketAddress) {
|
||||
InetSocketAddress address = (InetSocketAddress) socketAddress;
|
||||
asyncTrace.recordTerminalEndPoint("ARCUS:" + address.getHostName() + ":" + address.getPort());
|
||||
asyncTrace.recordEndPoint("ARCUS:" + address.getHostName() + ":" + address.getPort());
|
||||
}
|
||||
|
||||
String serviceName = (String) getServiceCode.invoke(target);
|
||||
|
||||
if (serviceName == null) {
|
||||
serviceName = "ARCUS/UNKNOWN";
|
||||
serviceName = "UNKNOWN";
|
||||
}
|
||||
|
||||
asyncTrace.recordRpcName(serviceName, baseOperation.getClass().getSimpleName());
|
||||
asyncTrace.recordRpcName(ServiceType.ARCUS, serviceName, baseOperation.getClass().getSimpleName());
|
||||
|
||||
String cmd = getCommand(baseOperation);
|
||||
asyncTrace.recordAttibute("arcus.command", cmd);
|
||||
|
||||
@@ -72,7 +72,7 @@ public class DriverConnectInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
return;
|
||||
}
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
|
||||
trace.recordApi(descriptor, new Object[]{args[0]});
|
||||
trace.recordException(result);
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class PreparedStatementCreateInterceptor implements StaticAroundIntercept
|
||||
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class PreparedStatementExecuteQueryInterceptor implements StaticAroundInt
|
||||
try {
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
String sql = getSql.invoke(target);
|
||||
trace.recordAttribute("PreparedStatement", sql);
|
||||
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class StatementExecuteQueryInterceptor implements StaticAroundInterceptor
|
||||
*/
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
// if (args.length > 0) {
|
||||
// trace.recordAttribute("Statement", args[0]);
|
||||
// }
|
||||
|
||||
+2
-2
@@ -45,12 +45,12 @@ public class StatementExecuteUpdateInterceptor implements StaticAroundIntercepto
|
||||
if (args.length > 0) {
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
trace.recordAttribute("Query", args[0]);
|
||||
} else {
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
trace.recordAttribute("Query", "args size is 0");
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
|
||||
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
}
|
||||
|
||||
private void afterStartTransaction(Trace trace, Connection target, Object[] arg, Object result) {
|
||||
@@ -124,7 +124,7 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
|
||||
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
// trace.record(Annotation.ClientSend);
|
||||
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
|
||||
try {
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
|
||||
trace.recordApi(descriptor);
|
||||
trace.recordException(result);
|
||||
@@ -164,7 +164,7 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
|
||||
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
}
|
||||
|
||||
private void afterRollback(Trace trace, Connection target, Object result) {
|
||||
@@ -172,7 +172,7 @@ public class TransactionInterceptor implements StaticAroundInterceptor, ByteCode
|
||||
|
||||
DatabaseInfo databaseInfo = (DatabaseInfo) this.getUrl.invoke(target);
|
||||
trace.recordRpcName(databaseInfo.getType(), databaseInfo.getDatabaseId(), databaseInfo.getUrl());
|
||||
trace.recordTerminalEndPoint(databaseInfo.getUrl());
|
||||
trace.recordEndPoint(databaseInfo.getUrl());
|
||||
|
||||
trace.recordApi(descriptor);
|
||||
trace.recordException(result);
|
||||
|
||||
Reference in New Issue
Block a user