[강운덕] [LUCYSUS-1744] span 으로 start, end time을 이동시킴.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-web/trunk@877 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Woonduk Kang
2012-11-20 04:53:00 +00:00
parent 86b9001e7a
commit 9fa274cae5
11 changed files with 348 additions and 370 deletions
@@ -26,8 +26,8 @@ public class SpanAligner {
private static final Comparator<SpanBo> timeComparator = new Comparator<SpanBo>() {
@Override
public int compare(SpanBo o1, SpanBo o2) {
long o1Timestamp = o1.getTimestamp();
long o2Timestamp = o2.getTimestamp();
long o1Timestamp = o1.getStartTime();
long o2Timestamp = o2.getStartTime();
if (o1Timestamp > o2Timestamp) {
return 1;
}
@@ -23,5 +23,6 @@ public interface TraceDao {
List<List<SpanBo>> selectSpans(Set<TraceId> traceIds);
@Deprecated
List<List<SpanBo>> selectSpansAndAnnotation(Set<TraceId> traceIds);
}
@@ -26,74 +26,74 @@ import com.profiler.common.util.BytesUtils;
@Repository
public class HbaseTraceDao implements TraceDao {
private final byte[] COLFAM_SPAN = HBaseTables.TRACES_CF_SPAN;
private final byte[] COLFAM_SPAN = HBaseTables.TRACES_CF_SPAN;
private final byte[] COLFAM_ANNOTATION = HBaseTables.TRACES_CF_ANNOTATION;
private final byte[] COLFAM_ANNOTATION = HBaseTables.TRACES_CF_ANNOTATION;
private Logger logger = LoggerFactory.getLogger(this.getClass());
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private HbaseOperations2 template2;
@Autowired
private HbaseOperations2 template2;
@Autowired
@Qualifier("spanMapper")
private RowMapper<List<SpanBo>> spanMapper;
@Autowired
@Qualifier("spanMapper")
private RowMapper<List<SpanBo>> spanMapper;
@Autowired
@Qualifier("spanAnnotationMapper")
private RowMapper<List<SpanBo>> spanAnnotationMapper;
@Autowired
@Qualifier("spanAnnotationMapper")
private RowMapper<List<SpanBo>> spanAnnotationMapper;
@Override
public List<SpanBo> selectSpan(UUID traceId) {
byte[] uuidBytes = BytesUtils.longLongToBytes(traceId.getMostSignificantBits(), traceId.getLeastSignificantBits());
return template2.get(HBaseTables.TRACES, uuidBytes, COLFAM_SPAN, spanMapper);
}
@Override
public List<SpanBo> selectSpan(UUID traceId) {
byte[] uuidBytes = BytesUtils.longLongToBytes(traceId.getMostSignificantBits(), traceId.getLeastSignificantBits());
return template2.get(HBaseTables.TRACES, uuidBytes, COLFAM_SPAN, spanMapper);
}
public List<SpanBo> selectSpanAndAnnotation(UUID traceId) {
byte[] uuidBytes = BytesUtils.longLongToBytes(traceId.getMostSignificantBits(), traceId.getLeastSignificantBits());
Get get = new Get(uuidBytes);
get.addFamily(COLFAM_SPAN);
get.addFamily(COLFAM_ANNOTATION);
return template2.get(HBaseTables.TRACES, get, spanAnnotationMapper);
}
public List<SpanBo> selectSpanAndAnnotation(UUID traceId) {
byte[] uuidBytes = BytesUtils.longLongToBytes(traceId.getMostSignificantBits(), traceId.getLeastSignificantBits());
Get get = new Get(uuidBytes);
get.addFamily(COLFAM_SPAN);
get.addFamily(COLFAM_ANNOTATION);
return template2.get(HBaseTables.TRACES, get, spanAnnotationMapper);
}
@Override
public List<SpanBo> selectSpan(long traceIdMost, long traceIdLeast) {
byte[] uuidBytes = BytesUtils.longLongToBytes(traceIdMost, traceIdLeast);
return template2.get(HBaseTables.TRACES, uuidBytes, COLFAM_SPAN, spanMapper);
}
@Override
public List<SpanBo> selectSpan(long traceIdMost, long traceIdLeast) {
byte[] uuidBytes = BytesUtils.longLongToBytes(traceIdMost, traceIdLeast);
return template2.get(HBaseTables.TRACES, uuidBytes, COLFAM_SPAN, spanMapper);
}
@Override
public List<List<SpanBo>> selectSpans(List<UUID> traceIds) {
List<Get> gets = new ArrayList<Get>(traceIds.size());
for (UUID traceId : traceIds) {
byte[] uuidBytes = BytesUtils.longLongToBytes(traceId.getMostSignificantBits(), traceId.getLeastSignificantBits());
Get get = new Get(uuidBytes);
get.addFamily(COLFAM_SPAN);
gets.add(get);
}
return template2.get(HBaseTables.TRACES, gets, spanMapper);
}
@Override
public List<List<SpanBo>> selectSpans(List<UUID> traceIds) {
List<Get> gets = new ArrayList<Get>(traceIds.size());
for (UUID traceId : traceIds) {
byte[] uuidBytes = BytesUtils.longLongToBytes(traceId.getMostSignificantBits(), traceId.getLeastSignificantBits());
Get get = new Get(uuidBytes);
get.addFamily(COLFAM_SPAN);
gets.add(get);
}
return template2.get(HBaseTables.TRACES, gets, spanMapper);
}
@Override
public List<List<SpanBo>> selectSpans(Set<TraceId> traceIds) {
List<Get> gets = new ArrayList<Get>(traceIds.size());
for (TraceId traceId : traceIds) {
Get get = new Get(traceId.getBytes());
get.addFamily(COLFAM_SPAN);
gets.add(get);
}
return template2.get(HBaseTables.TRACES, gets, spanMapper);
}
@Override
public List<List<SpanBo>> selectSpans(Set<TraceId> traceIds) {
List<Get> gets = new ArrayList<Get>(traceIds.size());
for (TraceId traceId : traceIds) {
Get get = new Get(traceId.getBytes());
get.addFamily(COLFAM_SPAN);
gets.add(get);
}
return template2.get(HBaseTables.TRACES, gets, spanMapper);
}
public List<List<SpanBo>> selectSpansAndAnnotation(Set<TraceId> traceIds) {
List<Get> gets = new ArrayList<Get>(traceIds.size());
for (TraceId traceId : traceIds) {
Get get = new Get(traceId.getBytes());
get.addFamily(COLFAM_SPAN);
get.addFamily(COLFAM_ANNOTATION);
gets.add(get);
}
return template2.get(HBaseTables.TRACES, gets, spanAnnotationMapper);
}
public List<List<SpanBo>> selectSpansAndAnnotation(Set<TraceId> traceIds) {
List<Get> gets = new ArrayList<Get>(traceIds.size());
for (TraceId traceId : traceIds) {
Get get = new Get(traceId.getBytes());
get.addFamily(COLFAM_SPAN);
get.addFamily(COLFAM_ANNOTATION);
gets.add(get);
}
return template2.get(HBaseTables.TRACES, gets, spanAnnotationMapper);
}
}
@@ -51,8 +51,6 @@ public class SpanMapper implements RowMapper<List<SpanBo>> {
spanBo.setLeastTraceId(least);
spanBo.setSpanID(Bytes.toLong(kv.getBuffer(), kv.getQualifierOffset()));
spanBo.setSpanID(Bytes.toLong(kv.getQualifier()));
spanBo.setTimestamp(kv.getTimestamp());
spanBo.readValue(kv.getBuffer(), kv.getValueOffset());
if (logger.isTraceEnabled()) {
logger.trace("read span :{}", spanBo);
@@ -33,170 +33,170 @@ import com.profiler.common.hbase.HBaseTables;
@Service
public class FlowChartServiceImpl implements FlowChartService {
private Logger logger = LoggerFactory.getLogger(this.getClass());
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
@Qualifier("hbaseClient")
HBaseClient client;
@Autowired
@Qualifier("hbaseClient")
HBaseClient client;
@Autowired
private TraceDao traceDao;
@Autowired
private TraceDao traceDao;
@Autowired
private RootTraceIndexDao rootTraceIndexDao;
@Autowired
private RootTraceIndexDao rootTraceIndexDao;
@Autowired
private TraceIndexDao traceIndexDao;
@Autowired
private TraceIndexDao traceIndexDao;
@Autowired
private ApplicationIndexDao applicationIndexDao;
@Autowired
private ApplicationIndexDao applicationIndexDao;
@Autowired
private ApplicationTraceIndexDao applicationTraceIndexDao;
@Autowired
private ApplicationTraceIndexDao applicationTraceIndexDao;
@Override
public List<String> selectAllApplicationNames() {
return applicationIndexDao.selectAllApplicationNames();
}
@Override
public List<String> selectAllApplicationNames() {
return applicationIndexDao.selectAllApplicationNames();
}
@Override
public String[] selectAgentIdsFromApplicationName(String applicationName) {
return applicationIndexDao.selectAgentIds(applicationName);
}
@Override
public String[] selectAgentIdsFromApplicationName(String applicationName) {
return applicationIndexDao.selectAgentIds(applicationName);
}
@Override
public Set<TraceId> selectTraceIdsFromTraceIndex(String[] agentIds, long from, long to) {
if (agentIds == null) {
throw new NullPointerException("agentIds");
}
@Override
public Set<TraceId> selectTraceIdsFromTraceIndex(String[] agentIds, long from, long to) {
if (agentIds == null) {
throw new NullPointerException("agentIds");
}
if (agentIds.length == 1) {
// single scan
if (logger.isTraceEnabled()) {
logger.trace("scan {}, {}, {}", new Object[] { agentIds[0], from, to });
}
List<byte[]> bytes = this.traceIndexDao.scanTraceIndex(agentIds[0], from, to);
Set<TraceId> result = new HashSet<TraceId>();
for (byte[] traceId : bytes) {
TraceId tid = new TraceId(traceId);
result.add(tid);
logger.trace("traceid:{}", tid);
}
return result;
} else {
// multi scan 가능한 동일 open htable 에서 액세스함.
List<List<byte[]>> multiScan = this.traceIndexDao.multiScanTraceIndex(agentIds, from, to);
Set<TraceId> result = new HashSet<TraceId>();
for (List<byte[]> scan : multiScan) {
for (byte[] traceId : scan) {
result.add(new TraceId(traceId));
}
}
return result;
}
}
if (agentIds.length == 1) {
// single scan
if (logger.isTraceEnabled()) {
logger.trace("scan {}, {}, {}", new Object[]{agentIds[0], from, to});
}
List<byte[]> bytes = this.traceIndexDao.scanTraceIndex(agentIds[0], from, to);
Set<TraceId> result = new HashSet<TraceId>();
for (byte[] traceId : bytes) {
TraceId tid = new TraceId(traceId);
result.add(tid);
logger.trace("traceid:{}", tid);
}
return result;
} else {
// multi scan 가능한 동일 open htable 에서 액세스함.
List<List<byte[]>> multiScan = this.traceIndexDao.multiScanTraceIndex(agentIds, from, to);
Set<TraceId> result = new HashSet<TraceId>();
for (List<byte[]> scan : multiScan) {
for (byte[] traceId : scan) {
result.add(new TraceId(traceId));
}
}
return result;
}
}
@Override
public RPCCallTree selectRPCCallTree(Set<TraceId> traceIds) {
final RPCCallTree tree = new RPCCallTree();
List<List<SpanBo>> traces = this.traceDao.selectSpans(traceIds);
for (List<SpanBo> transaction : traces) {
for (SpanBo eachTransaction : transaction) {
tree.addSpan(eachTransaction);
}
}
return tree.build();
}
@Override
public RPCCallTree selectRPCCallTree(Set<TraceId> traceIds) {
final RPCCallTree tree = new RPCCallTree();
List<List<SpanBo>> traces = this.traceDao.selectSpans(traceIds);
for (List<SpanBo> transaction : traces) {
for (SpanBo eachTransaction : transaction) {
tree.addSpan(eachTransaction);
}
}
return tree.build();
}
@Override
public ServerCallTree selectServerCallTree(Set<TraceId> traceIds) {
final ServerCallTree tree = new ServerCallTree();
@Override
public ServerCallTree selectServerCallTree(Set<TraceId> traceIds) {
final ServerCallTree tree = new ServerCallTree();
List<List<SpanBo>> traces = this.traceDao.selectSpansAndAnnotation(traceIds);
List<List<SpanBo>> traces = this.traceDao.selectSpans(traceIds);
for (List<SpanBo> transaction : traces) {
List<SpanBo> processed = refine(transaction);
markRecursiveCall(processed);
for (SpanBo eachTransaction : processed) {
tree.addSpan(eachTransaction);
}
}
return tree.build();
}
for (List<SpanBo> transaction : traces) {
List<SpanBo> processed = refine(transaction);
markRecursiveCall(processed);
for (SpanBo eachTransaction : processed) {
tree.addSpan(eachTransaction);
}
}
return tree.build();
}
private List<SpanBo> refine(List<SpanBo> list) {
SpanBo removeSpan = null;
boolean rescan = true;
private List<SpanBo> refine(List<SpanBo> list) {
SpanBo removeSpan = null;
boolean rescan = true;
for (int i = 0; i < list.size(); i++) {
SpanBo span = list.get(i);
String svcName = span.getServiceName();
for (int i = 0; i < list.size(); i++) {
SpanBo span = list.get(i);
String svcName = span.getServiceName();
if (removeSpan != null) {
if (span.getParentSpanId() == removeSpan.getSpanId()) {
logger.debug("modify span for removed span. before {}", span);
if (removeSpan != null) {
if (span.getParentSpanId() == removeSpan.getSpanId()) {
logger.debug("modify span for removed span. before {}", span);
span.setParentSpanId(removeSpan.getParentSpanId());
span.getAnnotationBoList().addAll(removeSpan.getAnnotationBoList());
span.setParentSpanId(removeSpan.getParentSpanId());
span.getAnnotationBoList().addAll(removeSpan.getAnnotationBoList());
logger.debug("modify span for removed span. after {}", span);
logger.debug("modify span for removed span. after {}", span);
removeSpan = null;
}
}
removeSpan = null;
}
}
// TODO 임시로 HTTP/1.1을 확인하게 해두었음. merge해야하는 span 확인 방법을 바꿔야함.
if ("HTTP/1.1".equals(svcName)) {
removeSpan = list.get(i);
logger.debug("Remove span. {}", removeSpan);
list.remove(i);
}
// TODO 임시로 HTTP/1.1을 확인하게 해두었음. merge해야하는 span 확인 방법을 바꿔야함.
if ("HTTP/1.1".equals(svcName)) {
removeSpan = list.get(i);
logger.debug("Remove span. {}", removeSpan);
list.remove(i);
}
if (removeSpan != null && i == list.size() - 1 && rescan) {
logger.debug("modify span not found. scan again. {}", removeSpan);
i = -1;
rescan = false;
continue;
}
}
if (removeSpan != null && i == list.size() - 1 && rescan) {
logger.debug("modify span not found. scan again. {}", removeSpan);
i = -1;
rescan = false;
continue;
}
}
return list;
}
private void markRecursiveCall(final List<SpanBo> list) {
for (int i = 0; i < list.size(); i++) {
SpanBo a = list.get(i);
for (int j = 0; j < list.size(); j++) {
if (i == j)
continue;
SpanBo b = list.get(j);
if (a.getServiceName().equals(b.getServiceName()) && a.getSpanId() == b.getParentSpanId()) {
a.increaseRecursiveCallCount();
}
}
}
}
return list;
}
@Override
public Set<TraceId> selectTraceIdsFromApplicationTraceIndex(String applicationName, long from, long to) {
if (applicationName == null) {
throw new NullPointerException("applicationName");
}
private void markRecursiveCall(final List<SpanBo> list) {
for (int i = 0; i < list.size(); i++) {
SpanBo a = list.get(i);
for (int j = 0; j < list.size(); j++) {
if (i == j)
continue;
SpanBo b = list.get(j);
if (a.getServiceName().equals(b.getServiceName()) && a.getSpanId() == b.getParentSpanId()) {
a.increaseRecursiveCallCount();
}
}
}
}
@Override
public Set<TraceId> selectTraceIdsFromApplicationTraceIndex(String applicationName, long from, long to) {
if (applicationName == null) {
throw new NullPointerException("applicationName");
}
if (logger.isTraceEnabled()) {
logger.trace("scan {}, {}, {}", new Object[]{applicationName, from, to});
}
List<byte[]> bytes = this.applicationTraceIndexDao.scanTraceIndex(applicationName, from, to);
Set<TraceId> result = new HashSet<TraceId>();
for (byte[] traceId : bytes) {
TraceId tid = new TraceId(traceId);
result.add(tid);
logger.trace("traceid:{}", tid);
}
return result;
}
if (logger.isTraceEnabled()) {
logger.trace("scan {}, {}, {}", new Object[] { applicationName, from, to });
}
List<byte[]> bytes = this.applicationTraceIndexDao.scanTraceIndex(applicationName, from, to);
Set<TraceId> result = new HashSet<TraceId>();
for (byte[] traceId : bytes) {
TraceId tid = new TraceId(traceId);
result.add(tid);
logger.trace("traceid:{}", tid);
}
return result;
}
@Override
public String[] selectAgentIds(String[] hosts) {
List<HbaseColumn> column = new ArrayList<HBaseQuery.HbaseColumn>();
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import com.profiler.common.bo.AnnotationBo;
import com.profiler.common.bo.SpanBo;
public class BusinessTransaction {
@@ -19,45 +18,28 @@ public class BusinessTransaction {
public BusinessTransaction(SpanBo span) {
this.name = span.getName();
List<AnnotationBo> annotations = span.getAnnotationBoList();
long begin = 0;
long end = 0;
for (AnnotationBo a : annotations) {
if (a.getKey().equals("SR") || a.getKey().equals("CS")) {
begin = a.getTimestamp();
}
if (a.getKey().equals("SS") || a.getKey().equals("CR")) {
end = a.getTimestamp();
}
}
long begin = span.getStartTime();
long end = span.getEndTime();
long elapsed = end - begin;
totalTime = maxTime = minTime = elapsed;
this.traces.add(new Trace(new UUID(span.getMostTraceId(), span.getLeastTraceId()).toString(), elapsed, span.getTimestamp()));
this.traces.add(new Trace(new UUID(span.getMostTraceId(), span.getLeastTraceId()).toString(), elapsed, span.getStartTime()));
calls++;
}
public void add(SpanBo span) {
List<AnnotationBo> annotations = span.getAnnotationBoList();
long begin = 0;
long end = 0;
for (AnnotationBo a : annotations) {
if (a.getKey().equals("SR") || a.getKey().equals("CS")) {
begin = a.getTimestamp();
}
if (a.getKey().equals("SS") || a.getKey().equals("CR")) {
end = a.getTimestamp();
}
}
long begin = span.getStartTime();
long end = span.getEndTime();
long elapsed = end - begin;
totalTime += elapsed;
if (maxTime < elapsed)
maxTime = elapsed;
if (minTime > elapsed)
minTime = elapsed;
this.traces.add(new Trace(new UUID(span.getMostTraceId(), span.getLeastTraceId()).toString(), elapsed, span.getTimestamp()));
this.traces.add(new Trace(new UUID(span.getMostTraceId(), span.getLeastTraceId()).toString(), elapsed, span.getStartTime()));
if (span.getParentSpanId() == -1) {
calls++;
}
+17 -17
View File
@@ -2,25 +2,25 @@ package com.nhn.hippo.web.vo;
public class Trace {
private final String traceId;
private final long executionTime;
private final long timestamp;
private final String traceId;
private final long executionTime;
private final long startTime;
public Trace(String traceId, long executionTime, long timestamp) {
this.traceId = traceId;
this.executionTime = executionTime;
this.timestamp = timestamp;
}
public Trace(String traceId, long executionTime, long startTime) {
this.traceId = traceId;
this.executionTime = executionTime;
this.startTime = startTime;
}
public String getTraceId() {
return traceId;
}
public String getTraceId() {
return traceId;
}
public long getExecutionTime() {
return executionTime;
}
public long getExecutionTime() {
return executionTime;
}
public long getTimestamp() {
return timestamp;
}
public long getStartTime() {
return startTime;
}
}