提交 4f7372c4 编写于 作者: A ascrutae

Merge remote-tracking branch 'origin/master'

......@@ -29,7 +29,7 @@ public class Span extends SpanData {
}
public Span(String originData) {
String[] fieldValues = originData.split(SPAN_FIELD_SPILT_PATTERN);
String[] fieldValues = originData.split(SPAN_FIELD_SEPARATOR);
int index = 0;
while (this.setValueByIndex(fieldValues, index)) {
......@@ -67,7 +67,7 @@ public class Span extends SpanData {
break;
case 8:
exceptionStack = fieldValues[8].trim().replaceAll(
SPAN_ATTR_SPILT_CHARACTER, NEW_LINE_CHARACTER_PATTERN);
NEW_LINE_PLACEHOLDER, OS_NEW_LINE);
break;
case 9:
spanType = fieldValues[9];
......@@ -77,7 +77,7 @@ public class Span extends SpanData {
break;
case 11:
businessKey = fieldValues[11].trim().replaceAll(
SPAN_ATTR_SPILT_CHARACTER, NEW_LINE_CHARACTER_PATTERN);
NEW_LINE_PLACEHOLDER, OS_NEW_LINE);
break;
case 12:
processNo = fieldValues[12].trim();
......@@ -104,76 +104,76 @@ public class Span extends SpanData {
@Override
public String toString() {
StringBuilder toStringValue = new StringBuilder();
toStringValue.append(traceId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(traceId + SPAN_FIELD_SEPARATOR);
if (isNonBlank(parentLevel)) {
toStringValue.append(parentLevel + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(parentLevel + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(levelId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(levelId + SPAN_FIELD_SEPARATOR);
if (isNonBlank(viewPointId)) {
toStringValue.append(viewPointId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(viewPointId + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(startDate + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(cost + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(startDate + SPAN_FIELD_SEPARATOR);
toStringValue.append(cost + SPAN_FIELD_SEPARATOR);
if (isNonBlank(address)) {
toStringValue.append(address + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(address + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(statusCode + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(statusCode + SPAN_FIELD_SEPARATOR);
if (isNonBlank(exceptionStack)) {
// 换行符在各个系统中表现不一致,
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue.append(exceptionStack.replaceAll(
CARRIAGE_RETURN_CHARACTER_PATTERN, "").replaceAll(
NEW_LINE_CHARACTER_PATTERN, SPAN_ATTR_SPILT_CHARACTER)
+ SPAN_FIELD_SPILT_PATTERN);
WINDOWS_OS_NEW_LINE_REDUNDANT_CHAR, "").replaceAll(
OS_NEW_LINE, NEW_LINE_PLACEHOLDER)
+ SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(spanType + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(isReceiver + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(spanType + SPAN_FIELD_SEPARATOR);
toStringValue.append(isReceiver + SPAN_FIELD_SEPARATOR);
if (isNonBlank(businessKey)) {
// 换行符在各个系统中表现不一致,
// windows平台的换行符为/r/n
// linux平台的换行符为/n
toStringValue.append(businessKey.replaceAll(
CARRIAGE_RETURN_CHARACTER_PATTERN, "").replaceAll(
NEW_LINE_CHARACTER_PATTERN, SPAN_ATTR_SPILT_CHARACTER)
+ SPAN_FIELD_SPILT_PATTERN);
WINDOWS_OS_NEW_LINE_REDUNDANT_CHAR, "").replaceAll(
OS_NEW_LINE, NEW_LINE_PLACEHOLDER)
+ SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
if (isNonBlank(processNo)) {
toStringValue.append(processNo + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(processNo + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
if (isNonBlank(applicationId)) {
toStringValue.append(applicationId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(applicationId + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
if (isNonBlank(userId)) {
toStringValue.append(userId + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(userId + SPAN_FIELD_SEPARATOR);
} else {
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
toStringValue.append(" " + SPAN_FIELD_SEPARATOR);
}
toStringValue.append(callType);
......
package com.ai.cloud.skywalking.protocol;
public abstract class SpanData {
protected static final String SPAN_FIELD_SPILT_PATTERN = "@~";
protected static final String SPAN_ATTR_SPILT_CHARACTER = "#~";
protected static final String NEW_LINE_CHARACTER_PATTERN = "\n";
protected static final String CARRIAGE_RETURN_CHARACTER_PATTERN = "\r";
/**
* Span在序列中,各字段间的分隔符
*/
protected static final String SPAN_FIELD_SEPARATOR = "@~";
/**
* Span在序列化中,新的换行符
*/
protected static final String NEW_LINE_PLACEHOLDER = "#~";
/**
* 字符串中的换行符
*/
protected static final String OS_NEW_LINE = "\n";
/**
* windows操作系统的多余换行字符
*/
protected static final String WINDOWS_OS_NEW_LINE_REDUNDANT_CHAR = "\r";
/**
* tid,调用链的全局唯一标识
*/
protected String traceId;
/**
* 当前调用链的上级描述<br/>
* 如当前序号为:0.1.0时,parentLevel=0.1
*/
protected String parentLevel;
/**
* 当前调用链的本机描述<br/>
* 如当前序号为:0.1.0时,levelId=0
*/
protected int levelId = 0;
/**
* 调用链中单个节点的入口描述<br/>
* 如:java方法名,调用的RPC地址等等
*/
protected String viewPointId = "";
/**
* 节点调用开始时间
*/
protected long startDate = System.currentTimeMillis();
/**
* 节点调用花费时间
*/
protected long cost = 0L;
/**
* 节点调用的发生机器描述<br/>
* 包含机器名 + IP地址
*/
protected String address = "";
/**
* 节点调用的状态<br/>
* 0:成功<br/>
* 1:异常<br/>
* 异常判断原则:代码产生exception,并且此exception不在忽略列表中
*/
protected byte statusCode = 0;
/**
* 节点调用的错误堆栈<br/>
* 堆栈以JAVA的exception为主要判断依据
*/
protected String exceptionStack;
/**
* 节点类型描述<br/>
* 已字符串的形式描述<br/>
* 如:java,dubbo等
*/
protected String spanType = "";
/**
* 节点调用类型描述<br/>
* @see com.ai.cloud.skywalking.protocol.CallType
*/
protected String callType = "";
/**
* 节点分布式类型<br/>
* 服务端/客户端
*/
protected boolean isReceiver = false;
/**
* 节点调用过程中的业务字段<br/>
* 如:业务系统设置的订单号,SQL语句等
*/
protected String businessKey = "";
/**
* 节点调用的所在进程号
*/
protected String processNo = "";
/**
* 节点调用所在的系统逻辑名称<br/>
* 由授权文件指定
*/
protected String applicationId = "";
/**
* 反序列化时,存储序列化前的字符串原文
*/
protected String originData = "";
/**
* 用户id<br/>
* 由授权文件指定
*/
protected String userId;
......
......@@ -20,7 +20,7 @@ public class HttpClientTracing {
httpRequest.setHeader(traceHearName,
"ContextData=" + sender.beforeSend(Identification.newBuilder()
.viewPoint(url)
.spanType(WEBBuriedPointType.instance())
.spanType(WebBuriedPointType.instance())
.build())
.toString());
return executor.execute();
......
......@@ -3,13 +3,13 @@ package com.ai.cloud.skywalking.plugin.httpclient.v42x;
import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.protocol.CallType;
public class WEBBuriedPointType implements IBuriedPointType {
public class WebBuriedPointType implements IBuriedPointType {
private static WEBBuriedPointType webBuriedPointType;
private static WebBuriedPointType webBuriedPointType;
public static IBuriedPointType instance() {
if (webBuriedPointType == null) {
webBuriedPointType = new WEBBuriedPointType();
webBuriedPointType = new WebBuriedPointType();
}
return webBuriedPointType;
......@@ -25,7 +25,7 @@ public class WEBBuriedPointType implements IBuriedPointType {
return CallType.SYNC;
}
private WEBBuriedPointType() {
private WebBuriedPointType() {
// Non
}
}
......@@ -20,7 +20,7 @@ public class HttpClientTracing {
httpRequest.setHeader(traceHearName,
"ContextData=" + sender.beforeSend(Identification.newBuilder()
.viewPoint(url)
.spanType(WEBBuriedPointType.instance())
.spanType(WebBuriedPointType.instance())
.build())
.toString());
return executor.execute();
......
......@@ -3,13 +3,13 @@ package com.ai.cloud.skywalking.plugin.httpclient.v43x;
import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.protocol.CallType;
public class WEBBuriedPointType implements IBuriedPointType {
public class WebBuriedPointType implements IBuriedPointType {
private static WEBBuriedPointType webBuriedPointType;
private static WebBuriedPointType webBuriedPointType;
public static IBuriedPointType instance() {
if (webBuriedPointType == null) {
webBuriedPointType = new WEBBuriedPointType();
webBuriedPointType = new WebBuriedPointType();
}
return webBuriedPointType;
......@@ -25,7 +25,7 @@ public class WEBBuriedPointType implements IBuriedPointType {
return CallType.SYNC;
}
private WEBBuriedPointType() {
private WebBuriedPointType() {
// Non
}
}
......@@ -70,7 +70,7 @@ public class SkyWalkingFilter implements Filter {
private Identification generateIdentification(HttpServletRequest request) {
return Identification.newBuilder()
.viewPoint(request.getRequestURL().toString())
.spanType(WEBBuriedPointType.instance())
.spanType(WebBuriedPointType.instance())
.build();
}
......
......@@ -3,13 +3,13 @@ package com.ai.cloud.skywalking.plugin.web;
import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.protocol.CallType;
public class WEBBuriedPointType implements IBuriedPointType {
public class WebBuriedPointType implements IBuriedPointType {
private static WEBBuriedPointType webBuriedPointType;
private static WebBuriedPointType webBuriedPointType;
public static IBuriedPointType instance() {
if (webBuriedPointType == null) {
webBuriedPointType = new WEBBuriedPointType();
webBuriedPointType = new WebBuriedPointType();
}
return webBuriedPointType;
......@@ -25,7 +25,7 @@ public class WEBBuriedPointType implements IBuriedPointType {
return CallType.SYNC;
}
private WEBBuriedPointType() {
private WebBuriedPointType() {
// Non
}
}
......@@ -3,21 +3,11 @@
*/
package com.ai.cloud.util.common;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import com.ai.cloud.dao.impl.BuriedPointSDAO;
import com.ai.cloud.util.Constants;
import com.ai.cloud.vo.mvo.TraceLogEntry;
......@@ -73,118 +63,4 @@ public class SortUtil {
return false;
}
}
/**
* 测试读取hbase 测试自动补充父级节点 测试排序
*
* @throws IOException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalAccessException
*
*/
@Test
public void testSelectByTraceId() throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
BuriedPointSDAO sdao = new BuriedPointSDAO();
Map<String, TraceLogEntry> bpe = sdao.queryLogByTraceId(Constants.TABLE_NAME_CHAIN,
"71e28364128847b3a12626966b60fd8f123");
List<TraceLogEntry> keyList = new ArrayList<TraceLogEntry>();
keyList.addAll(bpe.values());
Collections.sort(keyList, new Comparator<TraceLogEntry>() {
@Override
public int compare(TraceLogEntry arg0, TraceLogEntry arg1) {
return arg0.getColId().compareTo(arg1.getColId());
}
});
int m = 1;
for (TraceLogEntry tmpEntry : keyList) {
logger.info("sort result level:{} : {}", m++, tmpEntry);
}
}
/***
* 深度补全测试
*
* @throws IOException
*/
@Test
public void testGenTreeMapKey() throws IOException {
StringBuffer sb = new StringBuffer("0");
/***
* 深度测试 level 5 [ 11ms ] level 10[ 11ms ] level 15[ 11ms ] level 20[
* 12ms ] level 50[ 12ms ] level 100[ 12ms ] level 500[ 12ms ] level
* 1000[ 16ms ] level 2000[ 28ms ] level 5000[ 144ms ] level10000[ 445ms
* ]
*/
for (int i = 1; i < 10000; i++) {
sb.append(".0");
}
String colId = sb.toString();
TraceLogEntry tmpEntry = null;
Map<String, TraceLogEntry> reMap = new HashMap<String, TraceLogEntry>();
long startTime = System.currentTimeMillis();
logger.info("start time : {}", startTime);
addCurNodeTreeMapKey(reMap, colId, tmpEntry);
long endTime = System.currentTimeMillis();
logger.info("end time : {}", endTime);
logger.info("run time : {} ms", (endTime - startTime));
// List<String> keyList = new ArrayList<String>();
// keyList.addAll(reMap.keySet());
// Collections.sort(keyList);
// int m = 1;
// for (String str : keyList) {
// logger.info("sort result level:{} : {}", m++, str);
// }
}
/***
* collection sort 性能测试
*
* @param args
*/
@Test
public void testSortList() {
List<String> StrList = new ArrayList<String>();
Random random = new Random(System.currentTimeMillis());
StrList.add("0");
/***
* Collections.sort(StrList)性能 1000条/19 ms 10000条/42 ms 100000条/129 ms
* 1000000条/1070 ms
*/
for (int m = 0; m < 1000; m++) {
String radNum = "" + Math.abs(random.nextLong());
StringBuffer tmpBf = new StringBuffer("0");
for (int n = 0; n < radNum.length(); n++) {
tmpBf.append(".").append(radNum.charAt(n));
}
StrList.add(tmpBf.toString());
}
long startTime = System.currentTimeMillis();
logger.info("start time : {}", startTime);
Collections.sort(StrList);
long endTime = System.currentTimeMillis();
logger.info("end time : {}", endTime);
logger.info("run time : {} ms", (endTime - startTime));
// int i = 1;
// for (String tmpStr : StrList) {
// logger.info("sort {} : {}", i++, tmpStr);
// }
}
}
package com.ai.cloud.util.common;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import com.ai.cloud.dao.impl.BuriedPointSDAO;
import com.ai.cloud.util.Constants;
import com.ai.cloud.vo.mvo.TraceLogEntry;
public class SortTest {
private static Logger logger = LogManager.getLogger(SortUtil.class);
/**
* 测试读取hbase 测试自动补充父级节点 测试排序
*
* @throws IOException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalAccessException
*
*/
@Test
public void testSelectByTraceId() throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
BuriedPointSDAO sdao = new BuriedPointSDAO();
Map<String, TraceLogEntry> bpe = sdao.queryLogByTraceId(Constants.TABLE_NAME_CHAIN,
"71e28364128847b3a12626966b60fd8f123");
List<TraceLogEntry> keyList = new ArrayList<TraceLogEntry>();
keyList.addAll(bpe.values());
Collections.sort(keyList, new Comparator<TraceLogEntry>() {
@Override
public int compare(TraceLogEntry arg0, TraceLogEntry arg1) {
return arg0.getColId().compareTo(arg1.getColId());
}
});
int m = 1;
for (TraceLogEntry tmpEntry : keyList) {
logger.info("sort result level:{} : {}", m++, tmpEntry);
}
}
/***
* 深度补全测试
*
* @throws IOException
*/
@Test
public void testGenTreeMapKey() throws IOException {
StringBuffer sb = new StringBuffer("0");
/***
* 深度测试 level 5 [ 11ms ] level 10[ 11ms ] level 15[ 11ms ] level 20[
* 12ms ] level 50[ 12ms ] level 100[ 12ms ] level 500[ 12ms ] level
* 1000[ 16ms ] level 2000[ 28ms ] level 5000[ 144ms ] level10000[ 445ms
* ]
*/
for (int i = 1; i < 10000; i++) {
sb.append(".0");
}
String colId = sb.toString();
TraceLogEntry tmpEntry = null;
Map<String, TraceLogEntry> reMap = new HashMap<String, TraceLogEntry>();
long startTime = System.currentTimeMillis();
logger.info("start time : {}", startTime);
SortUtil.addCurNodeTreeMapKey(reMap, colId, tmpEntry);
long endTime = System.currentTimeMillis();
logger.info("end time : {}", endTime);
logger.info("run time : {} ms", (endTime - startTime));
// List<String> keyList = new ArrayList<String>();
// keyList.addAll(reMap.keySet());
// Collections.sort(keyList);
// int m = 1;
// for (String str : keyList) {
// logger.info("sort result level:{} : {}", m++, str);
// }
}
/***
* collection sort 性能测试
*
* @param args
*/
@Test
public void testSortList() {
List<String> StrList = new ArrayList<String>();
Random random = new Random(System.currentTimeMillis());
StrList.add("0");
/***
* Collections.sort(StrList)性能 1000条/19 ms 10000条/42 ms 100000条/129 ms
* 1000000条/1070 ms
*/
for (int m = 0; m < 1000; m++) {
String radNum = "" + Math.abs(random.nextLong());
StringBuffer tmpBf = new StringBuffer("0");
for (int n = 0; n < radNum.length(); n++) {
tmpBf.append(".").append(radNum.charAt(n));
}
StrList.add(tmpBf.toString());
}
long startTime = System.currentTimeMillis();
logger.info("start time : {}", startTime);
Collections.sort(StrList);
long endTime = System.currentTimeMillis();
logger.info("end time : {}", endTime);
logger.info("run time : {} ms", (endTime - startTime));
// int i = 1;
// for (String tmpStr : StrList) {
// logger.info("sort {} : {}", i++, tmpStr);
// }
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册