[유치수] [NOBTS] add exception property to span

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-commons/trunk@1068 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Chisu Yu
2012-12-27 09:37:36 +00:00
parent d52a540d12
commit 4dffeb09c8
16 changed files with 12843 additions and 12811 deletions
@@ -0,0 +1,9 @@
package com.profiler.common;
public class AnnotationNames {
public static final String API = "API";
public static final String API_ID = "API-ID";
public static final String EXCEPTION = "Exception";
}
@@ -1,11 +1,12 @@
package com.profiler.common.bo;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.profiler.common.ServiceType;
import com.profiler.common.dto.thrift.Annotation;
import com.profiler.common.dto.thrift.Span;
import com.profiler.common.dto.thrift.SubSpan;
import com.profiler.common.util.Buffer;
import com.profiler.common.util.BytesUtils;
@@ -45,7 +46,9 @@ public class SpanBo implements com.profiler.common.bo.Span {
private int recursiveCallCount = 0;
public SpanBo(Span span) {
private boolean exception = false;
public SpanBo(Span span) {
this.agentId = span.getAgentId();
this.mostTraceId = span.getMostTraceId();
@@ -63,6 +66,8 @@ public class SpanBo implements com.profiler.common.bo.Span {
this.endPoint = span.getEndPoint();
this.flag = span.getFlag();
this.exception = span.isErr();
setAnnotationList(span.getAnnotations());
}
@@ -234,10 +239,18 @@ public class SpanBo implements com.profiler.common.bo.Span {
public void setServiceType(ServiceType serviceType) {
this.serviceType = serviceType;
}
public boolean isException() {
return exception;
}
public void setException(boolean exception) {
this.exception = exception;
}
private int getBufferLength(int a, int b, int c, int d) {
int size = a + b + c + d;
size += 1 + 1 + 1 + 1 + VERSION_SIZE; // chunk size chunk
size += 1 + 1 + 1 + 1 + 1 + VERSION_SIZE; // chunk size chunk
// size = size + TIMESTAMP + MOSTTRACEID + LEASTTRACEID + SPANID +
// PARENTSPANID + FLAG + TERMINAL;
size += PARENTSPANID + SERVICETYPE;
@@ -276,7 +289,9 @@ public class SpanBo implements com.profiler.common.bo.Span {
buffer.put1PrefixedBytes(serviceNameBytes);
buffer.put(serviceType.getCode());
buffer.put1PrefixedBytes(endPointBytes);
buffer.put(exception);
// 공간 절약을 위해서 flag는 무조껀 마지막에 넣어야 한다.
if (flag != 0) {
buffer.put(flag);
@@ -305,6 +320,9 @@ public class SpanBo implements com.profiler.common.bo.Span {
this.serviceName = buffer.read1UnsignedPrefixedString();
this.serviceType = ServiceType.parse(buffer.readShort());
this.endPoint = buffer.read1UnsignedPrefixedString();
this.exception = buffer.readBoolean();
// flag는 무조껀 마지막에 넣어야 한다.
if (buffer.limit() == 2) {
this.flag = buffer.readShort();
@@ -1,323 +1,334 @@
package com.profiler.common.bo;
import java.util.ArrayList;
import java.util.List;
import com.profiler.common.ServiceType;
import com.profiler.common.dto.thrift.Annotation;
import com.profiler.common.dto.thrift.SubSpan;
import com.profiler.common.util.Buffer;
import com.profiler.common.util.BytesUtils;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
public class SubSpanBo implements Span {
private static final int VERSION_SIZE = 1;
// version 0 = prefix의 사이즈를 int로
private static final int VERSION_SIZE = 1;
// version 0 = prefix의 사이즈를 int로
private byte version = 0;
private byte version = 0;
// private static final int MOSTTRACEID = 8;
// private static final int LEASTTRACEID = 8;
// private static final int SPANID = 8;
private static final int PARENTSPANID = 8;
// private static final int TIMESTAMP = 8;
private static final int SERVICETYPE = 2;
private static final int FLAG = 2;
// private static final int MOSTTRACEID = 8;
// private static final int LEASTTRACEID = 8;
// private static final int SPANID = 8;
private static final int PARENTSPANID = 8;
// private static final int TIMESTAMP = 8;
private static final int SERVICETYPE = 2;
private static final int FLAG = 2;
private String agentId;
private long mostTraceId;
private long leastTraceId;
private String agentId;
private long mostTraceId;
private long leastTraceId;
private long spanId;
private short sequence;
private long spanId;
private short sequence;
private int startElapsed;
private int endElapsed;
private int startElapsed;
private int endElapsed;
private String rpc;
private String serviceName;
private ServiceType serviceType;
private String endPoint;
private List<AnnotationBo> annotationBoList;
private String rpc;
private String serviceName;
private ServiceType serviceType;
private String endPoint;
private List<AnnotationBo> annotationBoList;
public SubSpanBo() {
}
private boolean exception = false;
public SubSpanBo(com.profiler.common.dto.thrift.Span tSpan, SubSpan tSubSpan) {
this.agentId = tSpan.getAgentId();
public SubSpanBo() {
}
this.mostTraceId = tSpan.getMostTraceId();
this.leastTraceId = tSpan.getLeastTraceId();
public SubSpanBo(com.profiler.common.dto.thrift.Span tSpan, SubSpan tSubSpan) {
this.agentId = tSpan.getAgentId();
this.spanId = tSpan.getSpanId();
this.sequence = tSubSpan.getSequence();
this.mostTraceId = tSpan.getMostTraceId();
this.leastTraceId = tSpan.getLeastTraceId();
this.startElapsed = tSubSpan.getStartElapsed();
this.endElapsed = tSubSpan.getEndElapsed();
this.spanId = tSpan.getSpanId();
this.sequence = tSubSpan.getSequence();
this.rpc = tSubSpan.getRpc();
this.serviceName = tSubSpan.getServiceName();
this.serviceType = ServiceType.parse(tSubSpan.getServiceType());
this.startElapsed = tSubSpan.getStartElapsed();
this.endElapsed = tSubSpan.getEndElapsed();
this.endPoint = tSubSpan.getEndPoint();
setAnnotationBoList(tSubSpan.getAnnotations());
}
this.rpc = tSubSpan.getRpc();
this.serviceName = tSubSpan.getServiceName();
this.serviceType = ServiceType.parse(tSubSpan.getServiceType());
public SubSpanBo(com.profiler.common.dto.thrift.SubSpanList subSpanList, SubSpan subSpan) {
this.agentId = subSpanList.getAgentId();
this.endPoint = tSubSpan.getEndPoint();
this.exception = tSubSpan.isErr();
setAnnotationBoList(tSubSpan.getAnnotations());
}
this.mostTraceId = subSpanList.getMostTraceId();
this.leastTraceId = subSpanList.getLeastTraceId();
public SubSpanBo(com.profiler.common.dto.thrift.SubSpanList subSpanList, SubSpan subSpan) {
this.agentId = subSpanList.getAgentId();
this.spanId = subSpanList.getSpanId();
this.sequence = subSpan.getSequence();
this.mostTraceId = subSpanList.getMostTraceId();
this.leastTraceId = subSpanList.getLeastTraceId();
this.startElapsed = subSpan.getStartElapsed();
this.endElapsed = subSpan.getEndElapsed();
this.spanId = subSpanList.getSpanId();
this.sequence = subSpan.getSequence();
this.rpc = subSpan.getRpc();
this.serviceName = subSpan.getServiceName();
this.serviceType = ServiceType.parse(subSpan.getServiceType());
this.startElapsed = subSpan.getStartElapsed();
this.endElapsed = subSpan.getEndElapsed();
this.endPoint = subSpan.getEndPoint();
setAnnotationBoList(subSpan.getAnnotations());
}
this.rpc = subSpan.getRpc();
this.serviceName = subSpan.getServiceName();
this.serviceType = ServiceType.parse(subSpan.getServiceType());
public SubSpanBo(SubSpan subSpan) {
this.agentId = subSpan.getAgentId();
this.endPoint = subSpan.getEndPoint();
setAnnotationBoList(subSpan.getAnnotations());
}
this.mostTraceId = subSpan.getMostTraceId();
this.leastTraceId = subSpan.getLeastTraceId();
public SubSpanBo(SubSpan subSpan) {
this.agentId = subSpan.getAgentId();
this.spanId = subSpan.getSpanId();
this.sequence = subSpan.getSequence();
this.mostTraceId = subSpan.getMostTraceId();
this.leastTraceId = subSpan.getLeastTraceId();
this.startElapsed = subSpan.getStartElapsed();
this.endElapsed = subSpan.getEndElapsed();
this.spanId = subSpan.getSpanId();
this.sequence = subSpan.getSequence();
this.rpc = subSpan.getRpc();
this.serviceName = subSpan.getServiceName();
this.serviceType = ServiceType.parse(subSpan.getServiceType());
this.startElapsed = subSpan.getStartElapsed();
this.endElapsed = subSpan.getEndElapsed();
this.endPoint = subSpan.getEndPoint();
setAnnotationBoList(subSpan.getAnnotations());
}
this.rpc = subSpan.getRpc();
this.serviceName = subSpan.getServiceName();
this.serviceType = ServiceType.parse(subSpan.getServiceType());
public byte getVersion() {
return version;
}
this.endPoint = subSpan.getEndPoint();
setAnnotationBoList(subSpan.getAnnotations());
}
public void setVersion(byte version) {
this.version = version;
}
public byte getVersion() {
return version;
}
public String getAgentId() {
return agentId;
}
public void setVersion(byte version) {
this.version = version;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public String getAgentId() {
return agentId;
}
public long getMostTraceId() {
return mostTraceId;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public void setMostTraceId(long mostTraceId) {
this.mostTraceId = mostTraceId;
}
public long getMostTraceId() {
return mostTraceId;
}
public long getLeastTraceId() {
return leastTraceId;
}
public void setMostTraceId(long mostTraceId) {
this.mostTraceId = mostTraceId;
}
public void setLeastTraceId(long leastTraceId) {
this.leastTraceId = leastTraceId;
}
public long getLeastTraceId() {
return leastTraceId;
}
public void setSpanId(long spanId) {
this.spanId = spanId;
}
public void setLeastTraceId(long leastTraceId) {
this.leastTraceId = leastTraceId;
}
public long getSpanId() {
return this.spanId;
}
public void setSpanId(long spanId) {
this.spanId = spanId;
}
public short getSequence() {
return sequence;
}
public long getSpanId() {
return this.spanId;
}
public void setSequence(short sequence) {
this.sequence = sequence;
}
public short getSequence() {
return sequence;
}
public int getStartElapsed() {
return startElapsed;
}
public void setSequence(short sequence) {
this.sequence = sequence;
}
public void setStartElapsed(int startElapsed) {
this.startElapsed = startElapsed;
}
public int getStartElapsed() {
return startElapsed;
}
public int getEndElapsed() {
return endElapsed;
}
public void setStartElapsed(int startElapsed) {
this.startElapsed = startElapsed;
}
public void setEndElapsed(int endElapsed) {
this.endElapsed = endElapsed;
}
public int getEndElapsed() {
return endElapsed;
}
public String getRpc() {
return rpc;
}
public void setEndElapsed(int endElapsed) {
this.endElapsed = endElapsed;
}
public void setRpc(String rpc) {
this.rpc = rpc;
}
public String getRpc() {
return rpc;
}
public String getServiceName() {
return serviceName;
}
public void setRpc(String rpc) {
this.rpc = rpc;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public ServiceType getServiceType() {
return serviceType;
}
public void setServiceType(ServiceType serviceType) {
this.serviceType = serviceType;
}
public String getEndPoint() {
return endPoint;
}
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}
public List<AnnotationBo> getAnnotationBoList() {
return annotationBoList;
}
private void setAnnotationBoList(List<Annotation> annotations) {
List<AnnotationBo> boList = new ArrayList<AnnotationBo>(annotations.size());
for (Annotation ano : annotations) {
boList.add(new AnnotationBo(ano));
}
this.annotationBoList = boList;
}
private int getBufferLength(int a, int b, int c, int d) {
int size = a + b + c + d;
size += 1 + 1 + 1 + 1 + VERSION_SIZE; // chunk size chunk
// size = size + TIMESTAMP + MOSTTRACEID + LEASTTRACEID + SPANID +
// PARENTSPANID + FLAG + TERMINAL;
size += SERVICETYPE;
// startTime 4, elapsed 4
size += 8;
return size;
}
public byte[] writeValue() {
byte[] agentIDBytes = BytesUtils.getBytes(agentId);
byte[] rpcBytes = BytesUtils.getBytes(rpc);
byte[] serviceNameBytes = BytesUtils.getBytes(serviceName);
byte[] endPointBytes = BytesUtils.getBytes(endPoint);
int bufferLength = getBufferLength(agentIDBytes.length, rpcBytes.length, serviceNameBytes.length, endPointBytes.length);
int annotationSize = getAnnotationBufferSize(annotationBoList);
Buffer buffer = new Buffer(bufferLength + annotationSize);
buffer.put(version);
// buffer.put(mostTraceID);
// buffer.put(leastTraceID);
buffer.put1PrefixedBytes(agentIDBytes);
buffer.put(startElapsed);
buffer.put(endElapsed);
// Qualifier에서 읽어서 set하므로 필요 없음.
// buffer.put(sequence);
buffer.put1PrefixedBytes(rpcBytes);
buffer.put1PrefixedBytes(serviceNameBytes);
buffer.put(serviceType.getCode());
buffer.put1PrefixedBytes(endPointBytes);
writeAnnotation(buffer);
return buffer.getBuffer();
}
private void writeAnnotation(Buffer buffer) {
buffer.put(annotationBoList.size());
for (AnnotationBo annotation : annotationBoList) {
annotation.writeValue(buffer);
}
}
private int getAnnotationBufferSize(List<AnnotationBo> boList) {
int size = 0;
for (AnnotationBo ano : boList) {
size += ano.getBufferSize();
}
// size
size += 4;
return size;
}
public int readValue(byte[] bytes, int offset) {
Buffer buffer = new Buffer(bytes, offset);
this.version = buffer.readByte();
// this.mostTraceID = buffer.readLong();
// this.leastTraceID = buffer.readLong();
this.agentId = buffer.read1PrefixedString();
this.startElapsed = buffer.readInt();
this.endElapsed = buffer.readInt();
// Qualifier에서 읽어서 가져오므로 하지 않아도 됨.
// this.sequence = buffer.readShort();
this.rpc = buffer.read1UnsignedPrefixedString();
this.serviceName = buffer.read1UnsignedPrefixedString();
this.serviceType = ServiceType.parse(buffer.readShort());
this.endPoint = buffer.read1UnsignedPrefixedString();
this.annotationBoList = readAnnotation(buffer);
return buffer.getOffset();
}
private List<AnnotationBo> readAnnotation(Buffer buffer) {
int count = buffer.readInt();
List<AnnotationBo> list = new ArrayList<AnnotationBo>();
for (int i = 0; i < count; i++) {
AnnotationBo bo = new AnnotationBo();
bo.readValue(buffer);
list.add(bo);
}
return list;
}
@Override
public String toString() {
return "SubSpanBo{" + "agentId='" + agentId + '\'' + ", startElapsed=" + startElapsed + ", endElapsed=" + endElapsed
+ ", mostTraceId=" + mostTraceId + ", leastTraceId=" + leastTraceId + ", rpc='" + rpc + '\''
+ ", serviceName='" + serviceName + '\'' + ", spanID=" + spanId + ", sequence=" + sequence
+ ", endPoint='" + endPoint + ", serviceType=" + serviceType + "}";
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public ServiceType getServiceType() {
return serviceType;
}
public void setServiceType(ServiceType serviceType) {
this.serviceType = serviceType;
}
public String getEndPoint() {
return endPoint;
}
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}
public List<AnnotationBo> getAnnotationBoList() {
return annotationBoList;
}
public boolean isException() {
return exception;
}
public void setException(boolean exception) {
this.exception = exception;
}
private void setAnnotationBoList(List<Annotation> annotations) {
List<AnnotationBo> boList = new ArrayList<AnnotationBo>(annotations.size());
for (Annotation ano : annotations) {
boList.add(new AnnotationBo(ano));
}
this.annotationBoList = boList;
}
private int getBufferLength(int a, int b, int c, int d) {
int size = a + b + c + d;
size += 1 + 1 + 1 + 1 + 1+ VERSION_SIZE; // chunk size chunk
// size = size + TIMESTAMP + MOSTTRACEID + LEASTTRACEID + SPANID +
// PARENTSPANID + FLAG + TERMINAL;
size += SERVICETYPE;
// startTime 4, elapsed 4
size += 8;
return size;
}
public byte[] writeValue() {
byte[] agentIDBytes = BytesUtils.getBytes(agentId);
byte[] rpcBytes = BytesUtils.getBytes(rpc);
byte[] serviceNameBytes = BytesUtils.getBytes(serviceName);
byte[] endPointBytes = BytesUtils.getBytes(endPoint);
int bufferLength = getBufferLength(agentIDBytes.length, rpcBytes.length, serviceNameBytes.length, endPointBytes.length);
int annotationSize = getAnnotationBufferSize(annotationBoList);
Buffer buffer = new Buffer(bufferLength + annotationSize);
buffer.put(version);
// buffer.put(mostTraceID);
// buffer.put(leastTraceID);
buffer.put1PrefixedBytes(agentIDBytes);
buffer.put(startElapsed);
buffer.put(endElapsed);
// Qualifier에서 읽어서 set하므로 필요 없음.
// buffer.put(sequence);
buffer.put1PrefixedBytes(rpcBytes);
buffer.put1PrefixedBytes(serviceNameBytes);
buffer.put(serviceType.getCode());
buffer.put1PrefixedBytes(endPointBytes);
buffer.put(exception);
writeAnnotation(buffer);
return buffer.getBuffer();
}
private void writeAnnotation(Buffer buffer) {
buffer.put(annotationBoList.size());
for (AnnotationBo annotation : annotationBoList) {
annotation.writeValue(buffer);
}
}
private int getAnnotationBufferSize(List<AnnotationBo> boList) {
int size = 0;
for (AnnotationBo ano : boList) {
size += ano.getBufferSize();
}
// size
size += 4;
return size;
}
public int readValue(byte[] bytes, int offset) {
Buffer buffer = new Buffer(bytes, offset);
this.version = buffer.readByte();
// this.mostTraceID = buffer.readLong();
// this.leastTraceID = buffer.readLong();
this.agentId = buffer.read1PrefixedString();
this.startElapsed = buffer.readInt();
this.endElapsed = buffer.readInt();
// Qualifier에서 읽어서 가져오므로 하지 않아도 됨.
// this.sequence = buffer.readShort();
this.rpc = buffer.read1UnsignedPrefixedString();
this.serviceName = buffer.read1UnsignedPrefixedString();
this.serviceType = ServiceType.parse(buffer.readShort());
this.endPoint = buffer.read1UnsignedPrefixedString();
this.exception = buffer.readBoolean();
this.annotationBoList = readAnnotation(buffer);
return buffer.getOffset();
}
private List<AnnotationBo> readAnnotation(Buffer buffer) {
int count = buffer.readInt();
List<AnnotationBo> list = new ArrayList<AnnotationBo>();
for (int i = 0; i < count; i++) {
AnnotationBo bo = new AnnotationBo();
bo.readValue(buffer);
list.add(bo);
}
return list;
}
@Override
public String toString() {
return "SubSpanBo{" + "agentId='" + agentId + '\'' + ", startElapsed=" + startElapsed + ", endElapsed=" + endElapsed + ", mostTraceId=" + mostTraceId + ", leastTraceId=" + leastTraceId + ", rpc='" + rpc + '\'' + ", serviceName='" + serviceName + '\'' + ", spanID=" + spanId + ", sequence=" + sequence + ", endPoint='" + endPoint + ", serviceType=" + serviceType + "}";
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -19,10 +19,31 @@ public class ServerRegister implements Register {
private static final ClassMapping BlocHttpHandler = new ClassMapping(BlocHttpHandlerCode, "com.nhncorp.lucy.bloc.handler.HTTPHandler$BlocAdapter",
new MethodMapping("invoke", new String[]{"external.org.apache.coyote.Request", "external.org.apache.coyote.Response"}, new String[]{"request", "response"})
);
public static final int SpringServletHandlerCode = 5020;
private static final ClassMapping frameworkServlet = new ClassMapping(SpringServletHandlerCode, "org.springframework.web.servlet.FrameworkServlet",
new MethodMapping("doDelete", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[]{"request", "response"}),
new MethodMapping("doGet", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" }),
new MethodMapping("doPost", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" }),
new MethodMapping("doPut", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" })
);
public static final int HttpServletHandlerCode = 5030;
private static final ClassMapping httpServlet = new ClassMapping(HttpServletHandlerCode, "javax.servlet.http.HttpServlet",
new MethodMapping("doDelete", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" }),
new MethodMapping("doGet", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" }),
new MethodMapping("doHead", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" }),
new MethodMapping("doOptions", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" }),
new MethodMapping("doPost", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" }),
new MethodMapping("doPut", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" }),
new MethodMapping("doTrace", new String[] { "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse" }, new String[] { "request", "response" })
);
@Override
public void register(ApiMappingTable apiMappingTable, int startRange, int endRange) {
apiMappingTable.put(TomcatStandardHostValve);
apiMappingTable.put(BlocHttpHandler);
apiMappingTable.put(frameworkServlet);
apiMappingTable.put(httpServlet);
}
}
@@ -92,7 +92,7 @@ public class Buffer {
public boolean readBoolean() {
byte b = readByte();
if (b == BOOLEAN_FALSE) {
if (b == BOOLEAN_TRUE) {
return true;
} else {
return false;
+6 -2
View File
@@ -34,7 +34,9 @@ struct SubSpan {
10: i16 serviceType
11: string endPoint
12: list<Annotation> annotations
12: bool err
13: list<Annotation> annotations
}
struct Span {
@@ -57,7 +59,9 @@ struct Span {
12: list<Annotation> annotations
13: optional i16 flag = 0
14: optional list<SubSpan> subSpanList
14: bool err
15: optional list<SubSpan> subSpanList
}