解决调用链过长,导致页面崩溃的问题
This commit is contained in:
parent
e49909095f
commit
304b3fc51e
|
|
@ -7,6 +7,7 @@ public class TraceTreeInfo {
|
|||
private long beginTime;
|
||||
private long endTime;
|
||||
private List<TraceNodeInfo> nodes;
|
||||
private int nodeSize;
|
||||
|
||||
public TraceTreeInfo(String traceId, List<TraceNodeInfo> nodes) {
|
||||
this.traceId = traceId;
|
||||
|
|
@ -44,4 +45,12 @@ public class TraceTreeInfo {
|
|||
public void setNodes(List<TraceNodeInfo> nodes) {
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
public void setNodeSize(int nodeSize) {
|
||||
this.nodeSize = nodeSize;
|
||||
}
|
||||
|
||||
public int getNodeSize() {
|
||||
return nodeSize;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.ai.cloud.skywalking.web.dao.impl;
|
||||
|
||||
import com.ai.cloud.skywalking.web.bo.TraceNodeInfo;
|
||||
import com.ai.cloud.skywalking.web.bo.TraceTreeInfo;
|
||||
import com.ai.cloud.skywalking.web.dao.inter.ITraceNodeDao;
|
||||
import com.ai.cloud.skywalking.web.util.Constants;
|
||||
import com.ai.cloud.skywalking.web.util.HBaseUtils;
|
||||
|
|
@ -10,14 +11,18 @@ import org.apache.hadoop.hbase.Cell;
|
|||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.client.Get;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.client.Scan;
|
||||
import org.apache.hadoop.hbase.client.Table;
|
||||
import org.apache.hadoop.hbase.filter.ColumnCountGetFilter;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -33,28 +38,59 @@ public class TraceNodeDao implements ITraceNodeDao {
|
|||
|
||||
|
||||
@Override
|
||||
public Map<String, TraceNodeInfo> queryTraceNodesByTraceId(String traceId) throws IOException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
||||
public TraceTreeInfo queryTraceNodesByTraceId(String traceId) throws IOException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
|
||||
TraceTreeInfo traceTreeInfo = null;
|
||||
|
||||
Table table = hBaseUtils.getConnection().getTable(TableName.valueOf(CALL_CHAIN_TABLE_NAME));
|
||||
Get g = new Get(Bytes.toBytes(traceId));
|
||||
g.setFilter(new ColumnCountGetFilter(10001));
|
||||
Result r = table.get(g);
|
||||
Map<String, TraceNodeInfo> traceLogMap = new HashMap<String, TraceNodeInfo>();
|
||||
Map<String, TraceNodeInfo> rpcMap = new HashMap<String, TraceNodeInfo>();
|
||||
for (Cell cell : r.rawCells()) {
|
||||
if (cell.getValueArray().length > 0) {
|
||||
String colId = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(),
|
||||
cell.getQualifierLength());
|
||||
TraceNodeInfo tmpEntry = TraceNodeInfo.convert(
|
||||
Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()), colId);
|
||||
// 特殊处理RPC的服务端信息
|
||||
if (colId.endsWith(Constants.RPC_END_FLAG)) {
|
||||
rpcMap.put(colId.substring(0, colId.lastIndexOf(Constants.RPC_END_FLAG)), tmpEntry);
|
||||
} else {
|
||||
SortUtil.addCurNodeTreeMapKey(traceLogMap, colId, tmpEntry);
|
||||
int totalSize = 10001;
|
||||
if (r.rawCells().length < 10000) {
|
||||
for (Cell cell : r.rawCells()) {
|
||||
if (cell.getValueArray().length > 0) {
|
||||
dealSingleSpanCell(traceLogMap, rpcMap, cell);
|
||||
}
|
||||
}
|
||||
totalSize = r.rawCells().length;
|
||||
} else {
|
||||
g = new Get(Bytes.toBytes(traceId));
|
||||
g.addColumn("call-chain".getBytes(), "0".getBytes());
|
||||
g.addColumn("call-chain".getBytes(), "0.0".getBytes());
|
||||
r = table.get(g);
|
||||
//获取0和0.0两个节点
|
||||
Cell cell = r.getColumnLatestCell("call-chain".getBytes(), "0".getBytes());
|
||||
dealSingleSpanCell(traceLogMap, rpcMap, cell);
|
||||
cell = r.getColumnLatestCell("call-chain".getBytes(), "0.0".getBytes());
|
||||
dealSingleSpanCell(traceLogMap, rpcMap, cell);
|
||||
}
|
||||
computeRPCInfo(rpcMap, traceLogMap);
|
||||
return traceLogMap;
|
||||
|
||||
if (traceLogMap != null && traceLogMap.size() > 0) {
|
||||
List<TraceNodeInfo> nodes = new ArrayList<TraceNodeInfo>();
|
||||
nodes.addAll(traceLogMap.values());
|
||||
traceTreeInfo = new TraceTreeInfo(traceId, nodes);
|
||||
traceTreeInfo.setNodeSize(totalSize);
|
||||
}
|
||||
|
||||
return traceTreeInfo;
|
||||
}
|
||||
|
||||
private void dealSingleSpanCell(Map<String, TraceNodeInfo> traceLogMap, Map<String, TraceNodeInfo> rpcMap, Cell cell) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
|
||||
if (cell.getValueArray().length == 0)
|
||||
return;
|
||||
String colId = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(),
|
||||
cell.getQualifierLength());
|
||||
TraceNodeInfo tmpEntry = TraceNodeInfo.convert(
|
||||
Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()), colId);
|
||||
// 特殊处理RPC的服务端信息
|
||||
if (colId.endsWith(Constants.RPC_END_FLAG)) {
|
||||
rpcMap.put(colId.substring(0, colId.lastIndexOf(Constants.RPC_END_FLAG)), tmpEntry);
|
||||
} else {
|
||||
SortUtil.addCurNodeTreeMapKey(traceLogMap, colId, tmpEntry);
|
||||
}
|
||||
}
|
||||
|
||||
private void computeRPCInfo(Map<String, TraceNodeInfo> rpcMap, Map<String, TraceNodeInfo> traceLogMap) {
|
||||
|
|
@ -76,7 +112,7 @@ public class TraceNodeDao implements ITraceNodeDao {
|
|||
clientLog.setAddress(serverLog.getAddress());
|
||||
if (StringUtil.isBlank(clientLog.getExceptionStack())) {
|
||||
clientLog.setExceptionStack(serverLog.getExceptionStack());
|
||||
}else{
|
||||
} else {
|
||||
clientLog.setServerExceptionStr(serverLog.getServerExceptionStr());
|
||||
}
|
||||
System.out.println("1");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.ai.cloud.skywalking.web.dao.inter;
|
||||
|
||||
import com.ai.cloud.skywalking.web.bo.TraceNodeInfo;
|
||||
import com.ai.cloud.skywalking.web.bo.TraceTreeInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
|
@ -11,5 +12,5 @@ import java.util.Map;
|
|||
*/
|
||||
public interface ITraceNodeDao {
|
||||
|
||||
Map<String, TraceNodeInfo> queryTraceNodesByTraceId(String traceId) throws IOException, IllegalAccessException, NoSuchMethodException, InvocationTargetException;
|
||||
TraceTreeInfo queryTraceNodesByTraceId(String traceId) throws IOException, IllegalAccessException, NoSuchMethodException, InvocationTargetException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,10 @@ public class TraceTreeService implements ITraceTreeService {
|
|||
|
||||
@Override
|
||||
public TraceTreeInfo queryTraceTreeByTraceId(String traceId) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, IOException {
|
||||
TraceTreeInfo traceTreeInfo = null;
|
||||
|
||||
Map<String, TraceNodeInfo> traceLogMap = traceTreeDao.queryTraceNodesByTraceId(traceId);
|
||||
if (traceLogMap != null && traceLogMap.size() > 0) {
|
||||
List<TraceNodeInfo> nodes = new ArrayList<TraceNodeInfo>();
|
||||
nodes.addAll(traceLogMap.values());
|
||||
TraceTreeInfo traceTreeInfo = traceTreeDao.queryTraceNodesByTraceId(traceId);
|
||||
if (traceTreeInfo != null) {
|
||||
List<TraceNodeInfo> nodes = traceTreeInfo.getNodes();
|
||||
final List<Long> endTime = new ArrayList<Long>();
|
||||
endTime.add(0, nodes.get(0).getEndDate());
|
||||
Collections.sort(nodes, new Comparator<TraceNodeInfo>() {
|
||||
|
|
@ -43,7 +41,6 @@ public class TraceTreeService implements ITraceTreeService {
|
|||
}
|
||||
});
|
||||
long beginTime = nodes.get(0).getStartDate();
|
||||
traceTreeInfo = new TraceTreeInfo(traceId, nodes);
|
||||
traceTreeInfo.setBeginTime(beginTime);
|
||||
traceTreeInfo.setEndTime(endTime.get(0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ function changeData(data) {
|
|||
var totalTime = result.traceTree.totalTime;
|
||||
result.traceTree.startTime = data.beginTime;
|
||||
result.traceTree.endTime = data.endTime;
|
||||
result.traceTree.totalSize = data.nodes.length;
|
||||
result.traceTree.totalSize = data.nodeSize;
|
||||
result.traceTree.startTimeStr = convertDate(new Date(result.traceTree.startTime));
|
||||
result.traceTree.callIP = data.nodes[0].address;
|
||||
var tmpNode;
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@
|
|||
<div class="row">
|
||||
<h5>
|
||||
{{>traceId}}</br>
|
||||
调度入口IP:{{>callIP}},开始时间:{{>startTimeStr}},{{>totalSize}}条调用记录,消耗总时长:{{>totalTime}}ms。
|
||||
调度入口IP:{{>callIP}},开始时间:{{>startTimeStr}},{{if totalSize > 10000}}<strong>调用记录大于10000条,无法展示全部</strong>,{{else}}{{>totalSize}}条调用记录,{{/if}}消耗总时长:{{>totalTime}}ms。
|
||||
</h5>
|
||||
</div>
|
||||
<ul id="myTab" class="nav nav-tabs">
|
||||
|
|
|
|||
Loading…
Reference in New Issue