将所有的分割符都换成明文字符。将分隔符分成三类,一种Span的分割符(#&),一种是Span属性的分隔符(@~),一种是Span属性值的分隔符(#~)
This commit is contained in:
parent
7f045e2102
commit
27fff772e8
|
|
@ -4,5 +4,5 @@ public class Constants {
|
|||
|
||||
public static final String HEALTH_DATA_SPILT_PATTERN = "^~";
|
||||
|
||||
public static final String DATA_SPILT = ",";
|
||||
public static final String DATA_SPILT = "#&";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ public class DataSenderFactory {
|
|||
|
||||
private static Logger logger = Logger.getLogger(DataSenderFactory.class.getName());
|
||||
|
||||
private static List<SocketAddress> socketAddresses = new ArrayList<SocketAddress>();
|
||||
private static List<SocketAddress> unUsedSocketAddresses = new ArrayList<SocketAddress>();
|
||||
private static Set<SocketAddress> socketAddresses = new HashSet<SocketAddress>();
|
||||
private static Set<SocketAddress> unUsedSocketAddresses = new HashSet<SocketAddress>();
|
||||
private static List<DataSender> availableSenders = new ArrayList<DataSender>();
|
||||
private static Object lock = new Object();
|
||||
|
||||
|
|
@ -31,17 +31,13 @@ public class DataSenderFactory {
|
|||
if (StringUtil.isEmpty(Config.Sender.SERVERS_ADDR)) {
|
||||
throw new IllegalArgumentException("Collection service configuration error.");
|
||||
}
|
||||
//过滤重复地址
|
||||
Set<SocketAddress> tmpSocktAddress = new HashSet<SocketAddress>();
|
||||
|
||||
for (String serverConfig : Config.Sender.SERVERS_ADDR.split(";")) {
|
||||
String[] server = serverConfig.split(":");
|
||||
if (server.length != 2)
|
||||
throw new IllegalArgumentException("Collection service configuration error.");
|
||||
tmpSocktAddress.add(new InetSocketAddress(server[0], Integer.valueOf(server[1])));
|
||||
socketAddresses.add(new InetSocketAddress(server[0], Integer.valueOf(server[1])));
|
||||
}
|
||||
|
||||
socketAddresses.addAll(tmpSocktAddress);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.ALL, "Collection service configuration error.", e);
|
||||
System.exit(-1);
|
||||
|
|
@ -76,18 +72,18 @@ public class DataSenderFactory {
|
|||
// 初始化DataSender
|
||||
List<SocketAddress> usedSocketAddress = new ArrayList<SocketAddress>();
|
||||
|
||||
int index;
|
||||
while (availableSenders.size() < availableSize) {
|
||||
// 随机获取服务器地址
|
||||
index = ThreadLocalRandom.current().nextInt(socketAddresses.size());
|
||||
for (SocketAddress socketAddress : socketAddresses) {
|
||||
if (availableSenders.size() >= availableSize) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
availableSenders.add(new DataSender(socketAddresses.get(index)));
|
||||
usedSocketAddress.add(socketAddresses.get(index));
|
||||
availableSenders.add(new DataSender(socketAddress));
|
||||
usedSocketAddress.add(socketAddress);
|
||||
} catch (IOException e) {
|
||||
unUsedSocketAddresses.add(socketAddresses.get(index));
|
||||
unUsedSocketAddresses.add(socketAddress);
|
||||
}
|
||||
}
|
||||
unUsedSocketAddresses = new ArrayList<SocketAddress>(socketAddresses);
|
||||
unUsedSocketAddresses = new HashSet<SocketAddress>(socketAddresses);
|
||||
unUsedSocketAddresses.removeAll(usedSocketAddress);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,12 +37,13 @@ public class Span extends SpanData {
|
|||
statusCode = Byte.valueOf(fieldValues[7].trim());
|
||||
//异常情况才会存在exceptionStack
|
||||
if (statusCode == 1) {
|
||||
exceptionStack = fieldValues[8].trim().replaceAll(SpanData.EXCEPTION_SPILT_PATTERN,
|
||||
SpanData.NEW_LINE_CHARACTER_PATTERN);
|
||||
exceptionStack = fieldValues[8].trim().replaceAll(SPAN_ATTR_SPILT_CHARACTER,
|
||||
NEW_LINE_CHARACTER_PATTERN);
|
||||
}
|
||||
spanType = fieldValues[9].charAt(0);
|
||||
isReceiver = Boolean.valueOf(fieldValues[10]);
|
||||
businessKey = fieldValues[11].trim().replaceAll(BUSINESSKEY_SPILT_PATTERN,
|
||||
|
||||
businessKey = fieldValues[11].trim().replaceAll(SPAN_ATTR_SPILT_CHARACTER,
|
||||
NEW_LINE_CHARACTER_PATTERN);
|
||||
processNo = fieldValues[12].trim();
|
||||
applicationId = fieldValues[13].trim();
|
||||
|
|
@ -81,7 +82,11 @@ public class Span extends SpanData {
|
|||
toStringValue.append(statusCode + SPAN_FIELD_SPILT_PATTERN);
|
||||
|
||||
if (isNonBlank(exceptionStack)) {
|
||||
toStringValue.append(exceptionStack.replaceAll(NEW_LINE_CHARACTER_PATTERN, EXCEPTION_SPILT_PATTERN)
|
||||
//换行符在各个系统中表现不一致,
|
||||
//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);
|
||||
} else {
|
||||
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
|
||||
|
|
@ -92,8 +97,12 @@ public class Span extends SpanData {
|
|||
|
||||
|
||||
if (isNonBlank(businessKey)) {
|
||||
toStringValue.append(businessKey.replaceAll(NEW_LINE_CHARACTER_PATTERN,
|
||||
BUSINESSKEY_SPILT_PATTERN) + SPAN_FIELD_SPILT_PATTERN);
|
||||
//换行符在各个系统中表现不一致,
|
||||
//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);
|
||||
} else {
|
||||
toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN);
|
||||
}
|
||||
|
|
@ -134,4 +143,5 @@ public class Span extends SpanData {
|
|||
}
|
||||
this.exceptionStack = expMessage.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package com.ai.cloud.skywalking.protocol;
|
|||
|
||||
public abstract class SpanData {
|
||||
|
||||
protected static final String SPAN_FIELD_SPILT_PATTERN = ".\u007F";
|
||||
protected static final String BUSINESSKEY_SPILT_PATTERN = "'\u007F";
|
||||
protected static final String NEW_LINE_CHARACTER_PATTERN = "\r\n";
|
||||
protected static final String EXCEPTION_SPILT_PATTERN = ";\u007F";
|
||||
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";
|
||||
|
||||
protected String traceId;
|
||||
protected String parentLevel;
|
||||
|
|
@ -123,4 +123,5 @@ public abstract class SpanData {
|
|||
public String getApplicationId() {
|
||||
return applicationId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
package com.ai.cloud.skywalking.reciever.conf;
|
||||
|
||||
public class Constants {
|
||||
public static final String spiltRegx = "\\^\\~";
|
||||
|
||||
public static final String HEALTH_DATA_SPILT_PATTERN = "^~";
|
||||
|
||||
public static final String DATA_SPILT = ",";
|
||||
public static final String DATA_SPILT = "#&";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue