Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿信在这里
SkyWalking
提交
6f08371c
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,发现更多精彩内容 >>
提交
6f08371c
编写于
3月 02, 2016
作者:
A
ascrutae
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1. 添加TraceSpanTree序列化方法
2. 将Mapper的Keyout对象修改成TraceSpanTree
上级
06445fc5
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
433 addition
and
390 deletion
+433
-390
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/ChainBuildMapper.java
...loud/skywalking/analysis/chainbuild/ChainBuildMapper.java
+41
-41
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/entity/TraceSpanNode.java
.../skywalking/analysis/chainbuild/entity/TraceSpanNode.java
+217
-214
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/entity/TraceSpanTree.java
.../skywalking/analysis/chainbuild/entity/TraceSpanTree.java
+175
-135
未找到文件。
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/ChainBuildMapper.java
浏览文件 @
6f08371c
package
com.ai.cloud.skywalking.analysis.chainbuild
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.ai.cloud.skywalking.analysis.chainbuild.entity.TraceSpanTree
;
import
com.ai.cloud.skywalking.analysis.chainbuild.util.VersionIdentifier
;
import
com.ai.cloud.skywalking.analysis.config.ConfigInitializer
;
import
com.ai.cloud.skywalking.protocol.Span
;
import
org.apache.hadoop.hbase.Cell
;
import
org.apache.hadoop.hbase.client.Result
;
import
org.apache.hadoop.hbase.io.ImmutableBytesWritable
;
...
...
@@ -13,12 +13,11 @@ import org.apache.hadoop.io.Text;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.ai.cloud.skywalking.analysis.chainbuild.entity.TraceSpanTree
;
import
com.ai.cloud.skywalking.analysis.chainbuild.util.VersionIdentifier
;
import
com.ai.cloud.skywalking.analysis.config.ConfigInitializer
;
import
com.ai.cloud.skywalking.protocol.Span
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
ChainBuildMapper
extends
TableMapper
<
Text
,
T
ext
>
{
public
class
ChainBuildMapper
extends
TableMapper
<
Text
,
T
raceSpanTree
>
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ChainBuildMapper
.
class
);
...
...
@@ -31,7 +30,7 @@ public class ChainBuildMapper extends TableMapper<Text, Text> {
@Override
protected
void
map
(
ImmutableBytesWritable
key
,
Result
value
,
Context
context
)
throws
IOException
,
InterruptedException
{
if
(!
VersionIdentifier
.
enableAnaylsis
(
Bytes
.
toString
(
key
.
get
())))
{
if
(!
VersionIdentifier
.
enableAnaylsis
(
Bytes
.
toString
(
key
.
get
())))
{
return
;
}
...
...
@@ -46,6 +45,7 @@ public class ChainBuildMapper extends TableMapper<Text, Text> {
TraceSpanTree
tree
=
new
TraceSpanTree
();
tree
.
build
(
spanList
);
context
.
write
(
new
Text
(
tree
.
getTreeRoot
().
getNodeRefToken
()),
tree
);
}
catch
(
Throwable
e
)
{
logger
.
error
(
"Failed to mapper call chain["
+
key
.
toString
()
+
"]"
,
e
);
...
...
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/entity/TraceSpanNode.java
浏览文件 @
6f08371c
package
com.ai.cloud.skywalking.analysis.chainbuild.entity
;
import
java.util.List
;
import
com.ai.cloud.skywalking.analysis.chainbuild.exception.TraceSpanTreeSerializeException
;
import
com.ai.cloud.skywalking.analysis.chainbuild.util.StringUtil
;
import
com.ai.cloud.skywalking.analysis.chainbuild.util.TokenGenerator
;
import
com.ai.cloud.skywalking.protocol.CallType
;
import
com.ai.cloud.skywalking.protocol.Span
;
import
java.util.List
;
public
class
TraceSpanNode
{
protected
TraceSpanNode
prev
=
null
;
...
...
@@ -79,9 +80,9 @@ public class TraceSpanNode {
this
.
cost
=
span
.
getCost
();
this
.
callTimes
=
1
;
this
.
statusCode
=
span
.
getStatusCode
();
if
(
span
.
isReceiver
())
{
if
(
span
.
isReceiver
())
{
this
.
exceptionStack
=
"server stack:"
;
}
else
{
}
else
{
this
.
exceptionStack
=
"client stack:"
;
}
this
.
exceptionStack
+=
span
.
getExceptionStack
();
...
...
@@ -89,61 +90,63 @@ public class TraceSpanNode {
this
.
businessKey
=
span
.
getBusinessKey
();
this
.
applicationId
=
span
.
getApplicationId
();
//TODO: to set nodeToken
//nodeToken : MD5(parentLevelId + levelId + viewpoint)
nodeRefToken
=
TokenGenerator
.
generateNodeToken
(
parentLevel
+
"-"
+
levelId
+
"-"
+
viewPointId
);
}
protected
TraceSpanNode
(
TraceSpanNode
parent
,
TraceSpanNode
sub
,
TraceSpanNode
prev
,
TraceSpanNode
next
,
List
<
TraceSpanNode
>
spanContainer
)
{
protected
TraceSpanNode
(
TraceSpanNode
parent
,
TraceSpanNode
sub
,
TraceSpanNode
prev
,
TraceSpanNode
next
,
List
<
TraceSpanNode
>
spanContainer
)
{
this
.
visualNode
=
true
;
this
.
setParent
(
parent
);
if
(
parent
!=
null
)
{
if
(
parent
!=
null
)
{
parent
.
setSub
(
this
);
}
this
.
setSub
(
sub
);
if
(
sub
!=
null
)
{
if
(
sub
!=
null
)
{
sub
.
setParent
(
this
);
}
this
.
setPrev
(
prev
);
if
(
prev
!=
null
)
{
if
(
prev
!=
null
)
{
prev
.
setNext
(
this
);
}
this
.
setNext
(
next
);
if
(
next
!=
null
)
{
if
(
next
!=
null
)
{
next
.
setPrev
(
this
);
}
spanContainer
.
add
(
this
);
}
protected
TraceSpanNode
(
TraceSpanNode
parent
,
TraceSpanNode
sub
,
TraceSpanNode
prev
,
TraceSpanNode
next
,
String
parentLevelId
,
int
levelId
,
List
<
TraceSpanNode
>
spanContainer
)
{
protected
TraceSpanNode
(
TraceSpanNode
parent
,
TraceSpanNode
sub
,
TraceSpanNode
prev
,
TraceSpanNode
next
,
String
parentLevelId
,
int
levelId
,
List
<
TraceSpanNode
>
spanContainer
)
{
this
(
parent
,
sub
,
prev
,
next
,
spanContainer
);
this
.
parentLevel
=
parentLevelId
;
this
.
levelId
=
levelId
;
this
.
callTimes
=
0
;
}
boolean
hasNext
()
{
if
(
this
.
next
!=
null
)
{
boolean
hasNext
()
{
if
(
this
.
next
!=
null
)
{
return
true
;
}
else
{
}
else
{
return
false
;
}
}
boolean
hasSub
()
{
if
(
this
.
sub
!=
null
)
{
boolean
hasSub
()
{
if
(
this
.
sub
!=
null
)
{
return
true
;
}
else
{
}
else
{
return
false
;
}
}
void
mergeSpan
(
Span
span
)
{
if
(
CallType
.
convert
(
span
.
getCallType
())
==
CallType
.
ASYNC
)
{
void
mergeSpan
(
Span
span
)
{
if
(
CallType
.
convert
(
span
.
getCallType
())
==
CallType
.
ASYNC
)
{
this
.
cost
+=
span
.
getCost
();
}
if
(
span
.
getStatusCode
()
!=
0
&&
!
StringUtil
.
isBlank
(
span
.
getExceptionStack
()))
{
if
(
span
.
isReceiver
())
{
if
(
span
.
getStatusCode
()
!=
0
&&
!
StringUtil
.
isBlank
(
span
.
getExceptionStack
()))
{
if
(
span
.
isReceiver
())
{
this
.
exceptionStack
+=
"server stack:"
;
}
else
{
}
else
{
this
.
exceptionStack
+=
"client stack:"
;
}
this
.
exceptionStack
+=
span
.
getExceptionStack
();
...
...
@@ -223,23 +226,23 @@ public class TraceSpanNode {
}
public
String
getNodeRefToken
()
throws
TraceSpanTreeSerializeException
{
if
(
StringUtil
.
isBlank
(
nodeRefToken
))
{
if
(
StringUtil
.
isBlank
(
nodeRefToken
))
{
throw
new
TraceSpanTreeSerializeException
(
"parentLevel="
+
parentLevel
+
", levelId="
+
levelId
+
", viewPointId="
+
viewPointId
+
", node ref token is null."
);
}
return
nodeRefToken
;
}
void
serializeRef
()
throws
TraceSpanTreeSerializeException
{
if
(
prev
!=
null
)
{
void
serializeRef
()
throws
TraceSpanTreeSerializeException
{
if
(
prev
!=
null
)
{
prevNodeRefToken
=
prev
.
getNodeRefToken
();
}
if
(
parent
!=
null
)
{
if
(
parent
!=
null
)
{
parentNodeRefToken
=
parent
.
getNodeRefToken
();
}
if
(
next
!=
null
)
{
if
(
next
!=
null
)
{
nextNodeRefToken
=
next
.
getNodeRefToken
();
}
if
(
sub
!=
null
)
{
if
(
sub
!=
null
)
{
subNodeRefToken
=
sub
.
getNodeRefToken
();
}
}
...
...
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/entity/TraceSpanTree.java
浏览文件 @
6f08371c
package
com.ai.cloud.skywalking.analysis.chainbuild.entity
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.ai.cloud.skywalking.analysis.chainbuild.exception.BuildTraceSpanTreeException
;
import
com.ai.cloud.skywalking.analysis.chainbuild.exception.TraceSpanTreeSerializeException
;
import
com.ai.cloud.skywalking.analysis.chainbuild.util.StringUtil
;
import
com.ai.cloud.skywalking.analysis.chainbuild.util.TokenGenerator
;
import
com.ai.cloud.skywalking.protocol.Span
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
com.google.gson.reflect.TypeToken
;
import
org.apache.hadoop.io.Writable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.DataInput
;
import
java.io.DataOutput
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
public
class
TraceSpanTree
{
public
class
TraceSpanTree
implements
Writable
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
TraceSpanTree
.
class
);
private
String
userId
=
null
;
...
...
@@ -136,10 +143,43 @@ public class TraceSpanTree {
}
private
void
beforeSerialize
()
throws
TraceSpanTreeSerializeException
{
for
(
TraceSpanNode
treeNode
:
spanContainer
)
{
private
void
beforeSerialize
()
throws
TraceSpanTreeSerializeException
{
for
(
TraceSpanNode
treeNode
:
spanContainer
)
{
treeNode
.
serializeRef
();
}
}
public
String
serialize
()
throws
TraceSpanTreeSerializeException
{
beforeSerialize
();
return
new
Gson
().
toJson
(
this
);
}
@Override
public
void
write
(
DataOutput
out
)
throws
IOException
{
try
{
out
.
write
(
serialize
().
getBytes
());
}
catch
(
TraceSpanTreeSerializeException
e
)
{
logger
.
error
(
"Failed to serialize Chain Id["
+
cid
+
"]"
,
e
);
}
}
@Override
public
void
readFields
(
DataInput
in
)
throws
IOException
{
String
value
=
in
.
readLine
();
try
{
JsonObject
jsonObject
=
(
JsonObject
)
new
JsonParser
().
parse
(
value
);
userId
=
jsonObject
.
get
(
"userId"
).
getAsString
();
cid
=
jsonObject
.
get
(
"cid"
).
getAsString
();
treeRoot
=
new
Gson
().
fromJson
(
jsonObject
.
get
(
"treeRoot"
),
TraceSpanNode
.
class
);
spanContainer
=
new
Gson
().
fromJson
(
jsonObject
.
get
(
"spanContainer"
),
new
TypeToken
<
List
<
TraceSpanNode
>>()
{
}.
getType
());
}
catch
(
Exception
e
)
{
logger
.
error
(
"Failed to parse the value["
+
value
+
"] to TraceSpanTree Object"
,
e
);
}
}
public
TraceSpanNode
getTreeRoot
()
{
return
treeRoot
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录