提交 d2dd8004 编写于 作者: wu-sheng's avatar wu-sheng

Merge branch 'master' of https://github.com/wu-sheng/sky-walking

# By ascrutae
# Via ascrutae
* 'master' of https://github.com/wu-sheng/sky-walking:
  1.  新增TreeID和CID对应关系的表 2.  修改WEBUI的排序的方法
......@@ -6,6 +6,7 @@ import com.ai.cloud.skywalking.analysis.chainbuild.filter.SpanNodeProcessFilter;
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainInfo;
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainNode;
import com.ai.cloud.skywalking.analysis.chainbuild.po.SummaryType;
import com.ai.cloud.skywalking.analysis.chainbuild.util.HBaseUtil;
import com.ai.cloud.skywalking.analysis.chainbuild.util.SubLevelSpanCostCounter;
import com.ai.cloud.skywalking.analysis.chainbuild.util.TokenGenerator;
import com.ai.cloud.skywalking.analysis.chainbuild.util.VersionIdentifier;
......@@ -63,6 +64,8 @@ public class ChainBuildMapper extends TableMapper<Text, Text> {
chainInfo = spanToChainInfo(Bytes.toString(key.get()), spanList);
logger.debug("convert tid[" + Bytes.toString(key.get())
+ "] to chain with cid[" + chainInfo.getCID() + "].");
HBaseUtil.saveTraceIdAndTreeIdMapping(Bytes.toString(key.get()), chainInfo.getCID());
if (chainInfo.getCallEntrance() != null && chainInfo.getCallEntrance().length() > 0) {
for (ChainNode chainNode : chainInfo.getNodes()) {
context.write(new Text(SummaryType.HOUR.getValue() + "-" + hourSimpleDateFormat.format(
......
......@@ -37,7 +37,7 @@ public class ChainBuildReducer extends Reducer<Text, Text, Text, IntWritable> {
if (index == -1) {
return;
}
String summaryTypeAndDateStr = reduceKey.substring(0, index - 1);
String summaryTypeAndDateStr = reduceKey.substring(0, index);
String entryKey = reduceKey.substring(index + 1);
logger.debug("begin to reduce for key: {}", reduceKey);
......
......@@ -32,6 +32,9 @@ public class HBaseUtil {
createTableIfNeed(HBaseTableMetaData.TABLE_CALL_CHAIN_TREE_ID_AND_CID_MAPPING.TABLE_NAME,
HBaseTableMetaData.TABLE_CALL_CHAIN_TREE_ID_AND_CID_MAPPING.COLUMN_FAMILY_NAME);
createTableIfNeed(HBaseTableMetaData.TABLE_TRACE_ID_AND_CID_MAPPING.TABLE_NAME,
HBaseTableMetaData.TABLE_TRACE_ID_AND_CID_MAPPING.COLUMN_FAMILY_NAME);
createTableIfNeed(HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY.TABLE_NAME,
HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY.COLUMN_FAMILY_NAME);
......@@ -231,4 +234,12 @@ public class HBaseUtil {
}
public static void saveTraceIdAndTreeIdMapping(String traceId, String cid) throws IOException {
Put put = new Put(traceId.getBytes());
put.addColumn(HBaseTableMetaData.TABLE_TRACE_ID_AND_CID_MAPPING.COLUMN_FAMILY_NAME.getBytes(),
HBaseTableMetaData.TABLE_TRACE_ID_AND_CID_MAPPING.COLUMN_NAME.getBytes(),
cid.getBytes());
Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_TRACE_ID_AND_CID_MAPPING.TABLE_NAME));
table.put(put);
}
}
......@@ -26,23 +26,24 @@ public class TokenGenerator {
}
private static String generate(String originData) {
StringBuilder result = new StringBuilder();
if (originData != null) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte bytes[] = md.digest(originData.getBytes());
for (int i = 0; i < bytes.length; i++) {
String str = Integer.toHexString(bytes[i] & 0xFF);
if (str.length() == 1) {
str += "F";
}
result.append(str);
}
} catch (NoSuchAlgorithmException e) {
logger.error("Cannot found algorithm.", e);
System.exit(-1);
}
}
return result.toString().toUpperCase();
// StringBuilder result = new StringBuilder();
// if (originData != null) {
// try {
// MessageDigest md = MessageDigest.getInstance("MD5");
// byte bytes[] = md.digest(originData.getBytes());
// for (int i = 0; i < bytes.length; i++) {
// String str = Integer.toHexString(bytes[i] & 0xFF);
// if (str.length() == 1) {
// str += "F";
// }
// result.append(str);
// }
// } catch (NoSuchAlgorithmException e) {
// logger.error("Cannot found algorithm.", e);
// System.exit(-1);
// }
// }
// return result.toString().toUpperCase();
return originData;
}
}
\ No newline at end of file
......@@ -78,4 +78,17 @@ public class HBaseTableMetaData {
public static final String COLUMN_NAME = "been_merged_cid";
}
/**
* 用于存放TraceID和CID的映射关系
*
* @author zhangxin
*/
public final static class TABLE_TRACE_ID_AND_CID_MAPPING {
public static final String TABLE_NAME = "sw-traceId-cid-mapping";
public static final String COLUMN_FAMILY_NAME = "cid";
public static final String COLUMN_NAME = "cid";
}
}
......@@ -5,6 +5,7 @@ import com.ai.cloud.skywalking.analysis.chainbuild.ChainBuildMapper;
import com.ai.cloud.skywalking.analysis.chainbuild.ChainBuildReducer;
import com.ai.cloud.skywalking.analysis.chainbuild.action.IStatisticsAction;
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainInfo;
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainNode;
import com.ai.cloud.skywalking.analysis.chainbuild.po.SummaryType;
import com.ai.cloud.skywalking.analysis.chainbuild.util.TokenGenerator;
import com.ai.cloud.skywalking.analysis.config.ConfigInitializer;
......@@ -33,7 +34,7 @@ public class CallChainMapperTest {
private static String ZK_QUORUM = "10.1.235.197,10.1.235.198,10.1.235.199";
// private static String ZK_QUORUM = "10.1.241.18,10.1.241.19,10.1.241.20";
private static String ZK_CLIENT_PORT = "29181";
private static String chain_Id = "1.0a2.1453123911750.b3d7400.13582.96.2";
private static String chain_Id = "1.0b.1461569643178.5b468e7.23292.118.68";
//private static String chain_Id = "1.0a2.1453429608422.2701d43.6468.56.1";
private static Configuration configuration = null;
......@@ -48,23 +49,42 @@ public class CallChainMapperTest {
public static void main(String[] args) throws Exception {
ConfigInitializer.initialize();
initHBaseClient();
List<Span> spanList = selectByTraceId(chain_Id);
ChainInfo chainInfo = ChainBuildMapper.spanToChainInfo(chain_Id, spanList);
List<Text> chainNodeInfo = new ArrayList<>();
chainNodeInfo.add(new Text(new Gson().toJson(chainInfo)));
Text key = new Text(SummaryType.RELATIONSHIP + "-" + TokenGenerator.generateTreeToken(chainInfo.getCallEntrance())
+ ":" + chainInfo.getCallEntrance());
String reduceKey = Bytes.toString(key.getBytes());
int index = reduceKey.indexOf(":");
if (index == -1) {
return;
// 2016-04-22/23:57:03 to 2016-05-02/23:47:03
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss");
Date startDate = simpleDateFormat.parse("2016-04-22/23:57:03");
Date endDate = simpleDateFormat.parse("2016-05-02/23:47:03");
Scan scan = new Scan();
scan.setTimeRange(startDate.getTime(), endDate.getTime());
Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CALL_CHAIN.TABLE_NAME));
ResultScanner result = table.getScanner(scan);
int count = 0;
for (Result result1 : result){
count++;
}
String summaryTypeAndDateStr = reduceKey.substring(0, index - 1);
String entryKey = reduceKey.substring(index + 1);
IStatisticsAction summaryAction = SummaryType.chooseSummaryAction(summaryTypeAndDateStr, entryKey);
new ChainBuildReducer().doReduceAction(reduceKey, summaryAction, chainNodeInfo.iterator());
System.out.println(count);
// List<Span> spanList = selectByTraceId(chain_Id);
// ChainInfo chainInfo = ChainBuildMapper.spanToChainInfo(chain_Id, spanList);
// List<Text> chainNodeInfo = new ArrayList<>();
// for (ChainNode chainNode : chainInfo.getNodes()) {
// List<Text> value1 = new ArrayList<Text>();
// Text key =new Text(SummaryType.YEAR.getValue() + "-" + yearSimpleDateFormat.format(
// new Date(chainNode.getStartDate())
// ) + ":" + chainInfo.getCallEntrance());
// value1.add(new Text(new Gson().toJson(chainNode)));
//
// String reduceKey = Bytes.toString(key.getBytes());
// int index = reduceKey.indexOf(":");
// if (index == -1) {
// return;
// }
//
// String summaryTypeAndDateStr = reduceKey.substring(0, index);
// String entryKey = reduceKey.substring(index + 1);
// IStatisticsAction summaryAction = SummaryType.chooseSummaryAction(summaryTypeAndDateStr, entryKey);
//
// new ChainBuildReducer().doReduceAction(reduceKey, summaryAction, value1.iterator());
// }
}
public static List<Span> selectByTraceId(String traceId) throws IOException {
......
......@@ -35,7 +35,7 @@ public class SpanLevelIdComparators {
return spanTraceLevelId;
}
private static int descComparator(String levelId0, String levelId1) {
public static int descComparator(String levelId0, String levelId1) {
String[] levelId0Array = levelId0.split("\\.");
String[] levelId1Array = levelId1.split("\\.");
int result = -1;
......@@ -60,7 +60,7 @@ public class SpanLevelIdComparators {
}
private static int ascCompare(String levelId0, String levelId1) {
public static int ascCompare(String levelId0, String levelId1) {
String[] levelId0Array = levelId0.split("\\.");
String[] levelId1Array = levelId1.split("\\.");
int result = -1;
......
package com.ai.cloud.skywalking.web.service.impl;
import com.ai.cloud.skywalking.util.SpanLevelIdComparators;
import com.ai.cloud.skywalking.web.dao.inter.ICallChainTreeDao;
import com.ai.cloud.skywalking.web.dao.inter.ITypicalCallTreeDao;
import com.ai.cloud.skywalking.web.dto.CallChainTree;
......@@ -73,7 +74,7 @@ public class AnalysisResultService implements IAnalysisResultService {
Collections.sort(callChainTree.getCallChainTreeNodeList(), new Comparator<CallChainTreeNode>() {
@Override
public int compare(CallChainTreeNode o1, CallChainTreeNode o2) {
return o1.getTraceLevelId().compareTo(o2.getTraceLevelId());
return SpanLevelIdComparators.ascCompare(o1.getTraceLevelId(), o2.getTraceLevelId());
}
});
callChainTree.beautifulViewPointForShow();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册