Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿信在这里
SkyWalking
提交
37cc5a33
S
SkyWalking
项目概览
阿信在这里
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
37cc5a33
编写于
2月 23, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Alter ContextCarrier, add applicationCode and peerHost
上级
5902154a
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
95 addition
and
12 deletion
+95
-12
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java
...main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java
+36
-2
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java
...ce/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java
+1
-1
skywalking-commons/skywalking-trace/src/main/proto/trace.proto
...lking-commons/skywalking-trace/src/main/proto/trace.proto
+2
-0
skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java
...java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java
+6
-0
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java
...java/com/a/eye/skywalking/api/context/ContextCarrier.java
+33
-5
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java
.../java/com/a/eye/skywalking/api/context/TracerContext.java
+5
-0
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java
.../a/eye/skywalking/api/context/ContextCarrierTestCase.java
+7
-3
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/TracerContextTestCase.java
...m/a/eye/skywalking/api/context/TracerContextTestCase.java
+5
-1
未找到文件。
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java
浏览文件 @
37cc5a33
...
...
@@ -2,6 +2,7 @@ package com.a.eye.skywalking.trace;
import
com.a.eye.skywalking.messages.ISerializable
;
import
com.a.eye.skywalking.trace.messages.proto.SegmentRefMessage
;
import
com.a.eye.skywalking.trace.tag.Tags
;
/**
* {@link TraceSegmentRef} is like a pointer, which ref to another {@link TraceSegment},
...
...
@@ -20,6 +21,16 @@ public class TraceSegmentRef implements ISerializable<SegmentRefMessage> {
*/
private
int
spanId
=
-
1
;
/**
* {@link TraceSegment#applicationCode}
*/
private
String
applicationCode
;
/**
* {@link Tags#PEER_HOST}
*/
private
String
peerHost
;
/**
* Create a {@link TraceSegmentRef} instance, without any data.
*/
...
...
@@ -42,11 +53,28 @@ public class TraceSegmentRef implements ISerializable<SegmentRefMessage> {
this
.
spanId
=
spanId
;
}
@Override
public
String
toString
()
{
public
String
getApplicationCode
()
{
return
applicationCode
;
}
public
void
setApplicationCode
(
String
applicationCode
)
{
this
.
applicationCode
=
applicationCode
;
}
public
String
getPeerHost
()
{
return
peerHost
;
}
public
void
setPeerHost
(
String
peerHost
)
{
this
.
peerHost
=
peerHost
;
}
@Override
public
String
toString
()
{
return
"TraceSegmentRef{"
+
"traceSegmentId='"
+
traceSegmentId
+
'\''
+
", spanId="
+
spanId
+
", applicationCode='"
+
applicationCode
+
'\''
+
", peerHost='"
+
peerHost
+
'\''
+
'}'
;
}
...
...
@@ -55,6 +83,10 @@ public class TraceSegmentRef implements ISerializable<SegmentRefMessage> {
SegmentRefMessage
.
Builder
builder
=
SegmentRefMessage
.
newBuilder
();
builder
.
setTraceSegmentId
(
traceSegmentId
);
builder
.
setSpanId
(
spanId
);
builder
.
setApplicationCode
(
applicationCode
);
if
(
peerHost
!=
null
)
{
builder
.
setPeerHost
(
peerHost
);
}
return
builder
.
build
();
}
...
...
@@ -62,5 +94,7 @@ public class TraceSegmentRef implements ISerializable<SegmentRefMessage> {
public
void
deserialize
(
SegmentRefMessage
message
)
{
traceSegmentId
=
message
.
getTraceSegmentId
();
spanId
=
message
.
getSpanId
();
applicationCode
=
message
.
getApplicationCode
();
peerHost
=
message
.
getPeerHost
();
}
}
skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java
浏览文件 @
37cc5a33
...
...
@@ -102,7 +102,7 @@ public final class Tags {
public
static
final
BooleanTag
ERROR
=
new
BooleanTag
(
"error"
);
/**
* PEER_HOST records host address of the peer, maybe IPV4, IPV6 or hostname.
* PEER_HOST records host address
(ip:port, or ip1:port1,ip2:port2)
of the peer, maybe IPV4, IPV6 or hostname.
*/
public
static
final
StringTag
PEER_HOST
=
new
StringTag
(
"peer.host"
);
...
...
skywalking-commons/skywalking-trace/src/main/proto/trace.proto
浏览文件 @
37cc5a33
...
...
@@ -16,6 +16,8 @@ message SegmentMessage {
message
SegmentRefMessage
{
string
traceSegmentId
=
1
;
int32
spanId
=
2
;
string
applicationCode
=
3
;
string
peerHost
=
4
;
}
message
SpanMessage
{
...
...
skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java
浏览文件 @
37cc5a33
...
...
@@ -73,16 +73,22 @@ public class TraceSegmentTestCase {
TraceSegmentRef
ref1
=
new
TraceSegmentRef
();
ref1
.
setTraceSegmentId
(
"parent_trace_0"
);
ref1
.
setSpanId
(
1
);
ref1
.
setApplicationCode
(
"REMOTE_APP"
);
ref1
.
setPeerHost
(
"10.2.3.16:8080"
);
segment
.
ref
(
ref1
);
TraceSegmentRef
ref2
=
new
TraceSegmentRef
();
ref2
.
setTraceSegmentId
(
"parent_trace_1"
);
ref2
.
setSpanId
(
5
);
ref2
.
setApplicationCode
(
"REMOTE_APP"
);
ref2
.
setPeerHost
(
"10.2.3.16:8080"
);
segment
.
ref
(
ref2
);
TraceSegmentRef
ref3
=
new
TraceSegmentRef
();
ref3
.
setTraceSegmentId
(
"parent_trace_1"
);
ref3
.
setSpanId
(
5
);
ref3
.
setApplicationCode
(
"REMOTE_APP"
);
ref3
.
setPeerHost
(
"10.2.3.16:8080"
);
segment
.
ref
(
ref3
);
Span
span1
=
new
Span
(
1
,
"/serviceA"
);
...
...
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java
浏览文件 @
37cc5a33
...
...
@@ -2,8 +2,8 @@ package com.a.eye.skywalking.api.context;
import
com.a.eye.skywalking.trace.Span
;
import
com.a.eye.skywalking.trace.TraceSegment
;
import
com.a.eye.skywalking.trace.TraceSegmentRef
;
import
com.a.eye.skywalking.api.util.StringUtil
;
import
com.a.eye.skywalking.trace.tag.Tags
;
import
java.io.Serializable
;
/**
...
...
@@ -23,6 +23,16 @@ public class ContextCarrier implements Serializable {
*/
private
int
spanId
=
-
1
;
/**
* {@link TraceSegment#applicationCode}
*/
private
String
applicationCode
;
/**
* {@link Tags#PEER_HOST}
*/
private
String
peerHost
;
/**
* Serialize this {@link ContextCarrier} to a {@link String},
* with '|' split.
...
...
@@ -30,7 +40,7 @@ public class ContextCarrier implements Serializable {
* @return the serialization string.
*/
public
String
serialize
()
{
return
StringUtil
.
join
(
'|'
,
this
.
getTraceSegmentId
(),
this
.
getSpanId
()
+
""
);
return
StringUtil
.
join
(
'|'
,
this
.
getTraceSegmentId
(),
this
.
getSpanId
()
+
""
,
this
.
getApplicationCode
(),
this
.
getPeerHost
()
);
}
/**
...
...
@@ -40,11 +50,13 @@ public class ContextCarrier implements Serializable {
*/
public
ContextCarrier
deserialize
(
String
text
)
{
if
(
text
!=
null
){
String
[]
parts
=
text
.
split
(
"\\|"
);
if
(
parts
.
length
==
2
){
String
[]
parts
=
text
.
split
(
"\\|"
,
4
);
if
(
parts
.
length
==
4
){
try
{
setSpanId
(
Integer
.
parseInt
(
parts
[
1
]));
setTraceSegmentId
(
parts
[
0
]);
setApplicationCode
(
parts
[
2
]);
setPeerHost
(
parts
[
3
]);
}
catch
(
NumberFormatException
e
){
}
...
...
@@ -59,7 +71,7 @@ public class ContextCarrier implements Serializable {
* @return true for unbroken {@link ContextCarrier} or no-initialized. Otherwise, false;
*/
public
boolean
isValid
(){
return
!
StringUtil
.
isEmpty
(
getTraceSegmentId
())
&&
getSpanId
()
>
-
1
;
return
!
StringUtil
.
isEmpty
(
traceSegmentId
)
&&
getSpanId
()
>
-
1
&&
!
StringUtil
.
isEmpty
(
applicationCode
)
&&
!
StringUtil
.
isEmpty
(
peerHost
)
;
}
public
String
getTraceSegmentId
()
{
...
...
@@ -77,4 +89,20 @@ public class ContextCarrier implements Serializable {
public
void
setSpanId
(
int
spanId
)
{
this
.
spanId
=
spanId
;
}
public
String
getApplicationCode
()
{
return
applicationCode
;
}
public
void
setApplicationCode
(
String
applicationCode
)
{
this
.
applicationCode
=
applicationCode
;
}
public
String
getPeerHost
()
{
return
peerHost
;
}
public
void
setPeerHost
(
String
peerHost
)
{
this
.
peerHost
=
peerHost
;
}
}
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java
浏览文件 @
37cc5a33
...
...
@@ -5,6 +5,7 @@ import com.a.eye.skywalking.trace.Span;
import
com.a.eye.skywalking.trace.TraceSegment
;
import
com.a.eye.skywalking.api.util.TraceIdGenerator
;
import
com.a.eye.skywalking.trace.TraceSegmentRef
;
import
com.a.eye.skywalking.trace.tag.Tags
;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -116,6 +117,8 @@ public final class TracerContext {
public
void
inject
(
ContextCarrier
carrier
)
{
carrier
.
setTraceSegmentId
(
this
.
segment
.
getTraceSegmentId
());
carrier
.
setSpanId
(
this
.
activeSpan
().
getSpanId
());
carrier
.
setApplicationCode
(
Config
.
SkyWalking
.
APPLICATION_CODE
);
carrier
.
setPeerHost
(
Tags
.
PEER_HOST
.
get
(
activeSpan
()));
}
/**
...
...
@@ -128,6 +131,8 @@ public final class TracerContext {
TraceSegmentRef
ref
=
new
TraceSegmentRef
();
ref
.
setTraceSegmentId
(
carrier
.
getTraceSegmentId
());
ref
.
setSpanId
(
carrier
.
getSpanId
());
ref
.
setApplicationCode
(
carrier
.
getApplicationCode
());
ref
.
setPeerHost
(
carrier
.
getPeerHost
());
this
.
segment
.
ref
(
ref
);
}
...
...
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java
浏览文件 @
37cc5a33
...
...
@@ -12,17 +12,21 @@ public class ContextCarrierTestCase {
ContextCarrier
carrier
=
new
ContextCarrier
();
carrier
.
setTraceSegmentId
(
"trace_id_A"
);
carrier
.
setSpanId
(
100
);
carrier
.
setApplicationCode
(
"REMOTE_APP"
);
carrier
.
setPeerHost
(
"10.2.3.16:8080"
);
Assert
.
assertEquals
(
"trace_id_A|100"
,
carrier
.
serialize
());
Assert
.
assertEquals
(
"trace_id_A|100
|REMOTE_APP|10.2.3.16:8080
"
,
carrier
.
serialize
());
}
@Test
public
void
testDeserialize
(){
ContextCarrier
carrier
=
new
ContextCarrier
();
carrier
.
deserialize
(
"trace_id_A|100"
);
carrier
.
deserialize
(
"trace_id_A|100
|REMOTE_APP|10.2.3.16:8080
"
);
Assert
.
assertEquals
(
"trace_id_A"
,
carrier
.
getTraceSegmentId
());
Assert
.
assertEquals
(
100
,
carrier
.
getSpanId
());
Assert
.
assertEquals
(
"REMOTE_APP"
,
carrier
.
getApplicationCode
());
Assert
.
assertEquals
(
"10.2.3.16:8080"
,
carrier
.
getPeerHost
());
}
@Test
...
...
@@ -44,7 +48,7 @@ public class ContextCarrierTestCase {
Assert
.
assertFalse
(
carrier
.
isValid
());
carrier
=
new
ContextCarrier
();
carrier
.
deserialize
(
"trace_id|100"
);
carrier
.
deserialize
(
"trace_id|100
|REMOTE_APP|10.2.3.16:8080
"
);
Assert
.
assertTrue
(
carrier
.
isValid
());
}
}
skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/TracerContextTestCase.java
浏览文件 @
37cc5a33
...
...
@@ -2,6 +2,7 @@ package com.a.eye.skywalking.api.context;
import
com.a.eye.skywalking.trace.Span
;
import
com.a.eye.skywalking.trace.TraceSegment
;
import
com.a.eye.skywalking.trace.tag.Tags
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -56,11 +57,12 @@ public class TracerContextTestCase {
TracerContext
context
=
new
TracerContext
();
Span
serviceSpan
=
context
.
createSpan
(
"/serviceA"
);
Span
dbSpan
=
context
.
createSpan
(
"db/preparedStatement/execute"
);
Tags
.
PEER_HOST
.
set
(
dbSpan
,
"127.0.0.1:8080"
);
ContextCarrier
carrier
=
new
ContextCarrier
();
context
.
inject
(
carrier
);
Assert
.
assert
True
(
carrier
.
isValid
());
Assert
.
assert
Equals
(
"127.0.0.1:8080"
,
carrier
.
getPeerHost
());
Assert
.
assertEquals
(
1
,
carrier
.
getSpanId
());
}
...
...
@@ -69,6 +71,8 @@ public class TracerContextTestCase {
ContextCarrier
carrier
=
new
ContextCarrier
();
carrier
.
setTraceSegmentId
(
"trace_id_1"
);
carrier
.
setSpanId
(
5
);
carrier
.
setApplicationCode
(
"REMOTE_APP"
);
carrier
.
setPeerHost
(
"10.2.3.16:8080"
);
Assert
.
assertTrue
(
carrier
.
isValid
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录