Commit 304b3fc5 authored by ascrutae's avatar ascrutae
Browse files

解决调用链过长,导致页面崩溃的问题

parent e4990909
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+50 −14
Original line number Diff line number Diff line
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,14 +38,49 @@ 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>();
        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);

        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(
@@ -52,10 +92,6 @@ public class TraceNodeDao implements ITraceNodeDao {
            SortUtil.addCurNodeTreeMapKey(traceLogMap, colId, tmpEntry);
        }
    }
        }
        computeRPCInfo(rpcMap, traceLogMap);
        return traceLogMap;
    }

    private void computeRPCInfo(Map<String, TraceNodeInfo> rpcMap, Map<String, TraceNodeInfo> traceLogMap) {
        // 合并处理
+2 −1
Original line number Diff line number Diff line
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;
}
+3 −6
Original line number Diff line number Diff line
@@ -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));
        }
+1 −1
Original line number Diff line number Diff line
@@ -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;
Loading