Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
润土的好友猹
SkyWalking
提交
d37dbc8d
S
SkyWalking
项目概览
润土的好友猹
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
9
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,发现更多精彩内容 >>
提交
d37dbc8d
编写于
7月 03, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FInish codes about TraceSegment to UpstreamSegment
上级
4310daf6
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
161 addition
and
43 deletion
+161
-43
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
...ing/apm/agent/core/context/trace/AbstractTracingSpan.java
+36
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java
...rg/skywalking/apm/agent/core/context/trace/EntrySpan.java
+3
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/ExitSpan.java
...org/skywalking/apm/agent/core/context/trace/ExitSpan.java
+11
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java
...rg/skywalking/apm/agent/core/context/trace/LocalSpan.java
+6
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java
...kywalking/apm/agent/core/context/trace/LogDataEntity.java
+10
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/SpanLayer.java
...rg/skywalking/apm/agent/core/context/trace/SpanLayer.java
+14
-4
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java
...skywalking/apm/agent/core/context/trace/TraceSegment.java
+40
-22
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java
...walking/apm/agent/core/context/trace/TraceSegmentRef.java
+20
-7
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/KeyValuePair.java
.../skywalking/apm/agent/core/context/util/KeyValuePair.java
+9
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java
...king/apm/agent/core/remote/TraceSegmentServiceClient.java
+12
-10
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
浏览文件 @
d37dbc8d
...
...
@@ -5,6 +5,8 @@ import java.util.List;
import
org.skywalking.apm.agent.core.context.util.KeyValuePair
;
import
org.skywalking.apm.agent.core.context.util.ThrowableTransformer
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
import
org.skywalking.apm.network.proto.SpanObject
;
import
org.skywalking.apm.network.proto.SpanType
;
import
org.skywalking.apm.network.trace.component.Component
;
/**
...
...
@@ -152,4 +154,38 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
this
.
componentName
=
componentName
;
return
this
;
}
public
SpanObject
.
Builder
transform
(){
SpanObject
.
Builder
spanBuilder
=
SpanObject
.
newBuilder
();
spanBuilder
.
setSpanId
(
this
.
spanId
);
spanBuilder
.
setParentSpanId
(
parentSpanId
);
spanBuilder
.
setStartTime
(
startTime
);
spanBuilder
.
setEndTime
(
endTime
);
if
(
operationId
==
DictionaryUtil
.
nullValue
())
{
spanBuilder
.
setOperationNameId
(
operationId
);
}
else
{
spanBuilder
.
setOperationName
(
operationName
);
}
spanBuilder
.
setSpanType
(
SpanType
.
Entry
);
spanBuilder
.
setSpanLayerValue
(
this
.
layer
.
getCode
());
if
(
componentId
==
DictionaryUtil
.
nullValue
())
{
spanBuilder
.
setComponentId
(
componentId
);
}
else
{
spanBuilder
.
setComponent
(
componentName
);
}
spanBuilder
.
setIsError
(
errorOccurred
);
if
(
this
.
tags
!=
null
)
{
for
(
KeyValuePair
tag
:
this
.
tags
)
{
spanBuilder
.
addTags
(
tag
.
transform
());
}
}
if
(
this
.
logs
!=
null
)
{
for
(
LogDataEntity
log
:
this
.
logs
)
{
spanBuilder
.
addLogs
(
log
.
transform
());
}
}
return
spanBuilder
;
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/EntrySpan.java
浏览文件 @
d37dbc8d
package
org.skywalking.apm.agent.core.context.trace
;
import
org.skywalking.apm.agent.core.context.util.KeyValuePair
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
import
org.skywalking.apm.network.proto.SpanObject
;
import
org.skywalking.apm.network.proto.SpanType
;
import
org.skywalking.apm.network.trace.component.Component
;
/**
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/ExitSpan.java
浏览文件 @
d37dbc8d
package
org.skywalking.apm.agent.core.context.trace
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
import
org.skywalking.apm.network.proto.SpanObject
;
import
org.skywalking.apm.network.trace.component.Component
;
/**
...
...
@@ -102,6 +103,16 @@ public class ExitSpan extends AbstractTracingSpan {
return
this
;
}
@Override
public
SpanObject
.
Builder
transform
()
{
SpanObject
.
Builder
spanBuilder
=
super
.
transform
();
if
(
peerId
==
DictionaryUtil
.
nullValue
())
{
spanBuilder
.
setPeerId
(
peerId
);
}
else
{
spanBuilder
.
setPeer
(
peer
);
}
return
spanBuilder
;
}
public
int
getPeerId
()
{
return
peerId
;
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LocalSpan.java
浏览文件 @
d37dbc8d
package
org.skywalking.apm.agent.core.context.trace
;
import
org.skywalking.apm.network.proto.SpanObject
;
/**
* The <code>LocalSpan</code> represents a normal tracing point, such as a local method.
*
...
...
@@ -27,6 +29,10 @@ public class LocalSpan extends AbstractTracingSpan {
return
this
;
}
@Override
public
SpanObject
transform
()
{
return
null
;
}
@Override
public
boolean
isEntry
()
{
return
false
;
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/LogDataEntity.java
浏览文件 @
d37dbc8d
...
...
@@ -3,6 +3,8 @@ package org.skywalking.apm.agent.core.context.trace;
import
java.util.LinkedList
;
import
java.util.List
;
import
org.skywalking.apm.agent.core.context.util.KeyValuePair
;
import
org.skywalking.apm.network.proto.KeyWithStringValue
;
import
org.skywalking.apm.network.proto.LogMessage
;
/**
* The <code>LogDataEntity</code> represents a collection of {@link KeyValuePair},
...
...
@@ -39,4 +41,12 @@ public class LogDataEntity {
return
new
LogDataEntity
(
logs
);
}
}
public
LogMessage
transform
()
{
LogMessage
.
Builder
logMessageBuilder
=
LogMessage
.
newBuilder
();
for
(
KeyValuePair
log
:
logs
)
{
logMessageBuilder
.
addData
(
log
.
transform
());
}
return
logMessageBuilder
.
build
();
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/SpanLayer.java
浏览文件 @
d37dbc8d
...
...
@@ -4,10 +4,20 @@ package org.skywalking.apm.agent.core.context.trace;
* @author wusheng
*/
public
enum
SpanLayer
{
DB
,
RPC_FRAMEWORK
,
HTTP
,
MQ
;
DB
(
0
),
RPC_FRAMEWORK
(
1
),
HTTP
(
2
),
MQ
(
3
);
private
int
code
;
SpanLayer
(
int
code
)
{
this
.
code
=
code
;
}
public
int
getCode
()
{
return
code
;
}
public
static
void
asDB
(
AbstractSpan
span
)
{
span
.
setLayer
(
SpanLayer
.
DB
);
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java
浏览文件 @
d37dbc8d
...
...
@@ -3,6 +3,7 @@ package org.skywalking.apm.agent.core.context.trace;
import
java.util.LinkedList
;
import
java.util.List
;
import
org.skywalking.apm.agent.core.conf.Config
;
import
org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig
;
import
org.skywalking.apm.agent.core.context.ids.DistributedTraceId
;
import
org.skywalking.apm.agent.core.context.ids.DistributedTraceIds
;
import
org.skywalking.apm.agent.core.context.ids.GlobalIdGenerator
;
...
...
@@ -11,6 +12,9 @@ import org.skywalking.apm.agent.core.dictionary.DictionaryManager;
import
org.skywalking.apm.agent.core.dictionary.PossibleFound
;
import
org.skywalking.apm.logging.ILog
;
import
org.skywalking.apm.logging.LogManager
;
import
org.skywalking.apm.network.proto.TraceSegmentObject
;
import
org.skywalking.apm.network.proto.TraceSegmentReference
;
import
org.skywalking.apm.network.proto.UpstreamSegment
;
/**
* {@link TraceSegment} is a segment or fragment of the distributed trace.
...
...
@@ -33,16 +37,6 @@ public class TraceSegment {
*/
private
String
traceSegmentId
;
/**
* The start time of this trace segment.
*/
private
long
startTime
;
/**
* The end time of this trace segment.
*/
private
long
endTime
;
/**
* The refs of parent trace segments, except the primary one.
* For most RPC call, {@link #refs} contains only one element,
...
...
@@ -103,7 +97,6 @@ public class TraceSegment {
}
}
);
this
.
startTime
=
System
.
currentTimeMillis
();
this
.
traceSegmentId
=
GlobalIdGenerator
.
generate
(
ID_TYPE
);
this
.
spans
=
new
LinkedList
<
AbstractTracingSpan
>();
this
.
relatedGlobalTraces
=
new
DistributedTraceIds
();
...
...
@@ -154,7 +147,6 @@ public class TraceSegment {
* return this, for chaining
*/
public
TraceSegment
finish
()
{
this
.
endTime
=
System
.
currentTimeMillis
();
return
this
;
}
...
...
@@ -162,14 +154,6 @@ public class TraceSegment {
return
traceSegmentId
;
}
public
long
getStartTime
()
{
return
startTime
;
}
public
long
getEndTime
()
{
return
endTime
;
}
public
int
getApplicationId
()
{
return
applicationId
;
}
...
...
@@ -198,12 +182,46 @@ public class TraceSegment {
this
.
ignore
=
ignore
;
}
/**
* This is a high CPU cost method, only called when sending to collector or test cases.
*
* @return the segment as GRPC service parameter
*/
public
UpstreamSegment
transform
()
{
UpstreamSegment
.
Builder
upstreamBuilder
=
UpstreamSegment
.
newBuilder
();
for
(
DistributedTraceId
distributedTraceId
:
getRelatedGlobalTraces
())
{
upstreamBuilder
=
upstreamBuilder
.
addGlobalTraceIds
(
distributedTraceId
.
get
());
}
TraceSegmentObject
.
Builder
traceSegmentBuilder
=
TraceSegmentObject
.
newBuilder
();
/**
* Trace Segment
*/
traceSegmentBuilder
.
setTraceSegmentId
(
this
.
traceSegmentId
);
// TraceSegmentReference
if
(
this
.
refs
!=
null
)
{
for
(
TraceSegmentRef
ref
:
this
.
refs
)
{
traceSegmentBuilder
.
addRefs
(
ref
.
transform
());
}
}
// globalTraceIds
for
(
DistributedTraceId
distributedTraceId
:
getRelatedGlobalTraces
())
{
traceSegmentBuilder
.
addGlobalTraceIds
(
distributedTraceId
.
get
());
}
// SpanObject
for
(
AbstractTracingSpan
span
:
this
.
spans
)
{
traceSegmentBuilder
.
addSpans
(
span
.
transform
());
}
traceSegmentBuilder
.
setApplicationId
(
this
.
applicationId
);
traceSegmentBuilder
.
setApplicationInstanceId
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_ID
);
upstreamBuilder
.
setSegment
(
traceSegmentBuilder
.
build
().
toByteString
());
return
upstreamBuilder
.
build
();
}
@Override
public
String
toString
()
{
return
"TraceSegment{"
+
"traceSegmentId='"
+
traceSegmentId
+
'\''
+
", startTime="
+
startTime
+
", endTime="
+
endTime
+
", refs="
+
refs
+
", spans="
+
spans
+
", applicationId='"
+
applicationId
+
'\''
+
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java
浏览文件 @
d37dbc8d
...
...
@@ -4,6 +4,8 @@ import java.util.List;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.skywalking.apm.agent.core.context.ids.DistributedTraceId
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
import
org.skywalking.apm.network.proto.TraceSegmentReference
;
import
org.skywalking.apm.network.proto.UpstreamSegment
;
/**
* {@link TraceSegmentRef} is like a pointer, which ref to another {@link TraceSegment},
...
...
@@ -26,11 +28,6 @@ public class TraceSegmentRef {
private
int
operationId
=
DictionaryUtil
.
nullValue
();
/**
* {@link DistributedTraceId}
*/
private
List
<
DistributedTraceId
>
distributedTraceIds
;
/**
* Transform a {@link ContextCarrier} to the <code>TraceSegmentRef</code>
*
...
...
@@ -52,8 +49,6 @@ public class TraceSegmentRef {
}
else
{
this
.
operationId
=
Integer
.
parseInt
(
entryOperationName
);
}
this
.
distributedTraceIds
=
carrier
.
getDistributedTraceIds
();
}
public
String
getOperationName
()
{
...
...
@@ -64,6 +59,24 @@ public class TraceSegmentRef {
return
operationId
;
}
public
TraceSegmentReference
transform
()
{
TraceSegmentReference
.
Builder
refBuilder
=
TraceSegmentReference
.
newBuilder
();
refBuilder
.
setParentTraceSegmentId
(
traceSegmentId
);
refBuilder
.
setParentSpanId
(
spanId
);
refBuilder
.
setParentApplicationId
(
applicationId
);
if
(
peerId
==
DictionaryUtil
.
nullValue
())
{
refBuilder
.
setNetworkAddress
(
peerHost
);
}
else
{
refBuilder
.
setNetworkAddressId
(
peerId
);
}
if
(
operationId
==
DictionaryUtil
.
nullValue
())
{
refBuilder
.
setEntryServiceName
(
operationName
);
}
else
{
refBuilder
.
setEntryServiceId
(
operationId
);
}
return
refBuilder
.
build
();
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/util/KeyValuePair.java
浏览文件 @
d37dbc8d
package
org.skywalking.apm.agent.core.context.util
;
import
org.skywalking.apm.network.proto.KeyWithStringValue
;
/**
* The <code>KeyValuePair</code> represents a object which contains a string key and a string value.
*
...
...
@@ -21,4 +23,11 @@ public class KeyValuePair {
public
String
getValue
()
{
return
value
;
}
public
KeyWithStringValue
transform
()
{
KeyWithStringValue
.
Builder
keyValueBuilder
=
KeyWithStringValue
.
newBuilder
();
keyValueBuilder
.
setKey
(
key
);
keyValueBuilder
.
setValue
(
value
);
return
keyValueBuilder
.
build
();
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java
浏览文件 @
d37dbc8d
...
...
@@ -13,9 +13,9 @@ import org.skywalking.apm.agent.core.datacarrier.buffer.BufferStrategy;
import
org.skywalking.apm.agent.core.datacarrier.consumer.IConsumer
;
import
org.skywalking.apm.logging.ILog
;
import
org.skywalking.apm.logging.LogManager
;
import
org.skywalking.apm.network.
collecor.
proto.Downstream
;
import
org.skywalking.apm.network.
trace.
proto.TraceSegmentServiceGrpc
;
import
org.skywalking.apm.network.
trace.
proto.UpstreamSegment
;
import
org.skywalking.apm.network.proto.Downstream
;
import
org.skywalking.apm.network.proto.TraceSegmentServiceGrpc
;
import
org.skywalking.apm.network.proto.UpstreamSegment
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
conf
.
Config
.
Buffer
.
BUFFER_SIZE
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
conf
.
Config
.
Buffer
.
CHANNEL_SIZE
;
...
...
@@ -78,14 +78,13 @@ public class TraceSegmentServiceClient implements BootService, IConsumer<TraceSe
}
});
try
{
for
(
TraceSegment
segment
:
data
)
{
//TODO
// segment to PROTOBUFF object
upstreamSegmentStreamObserver
.
onNext
(
null
);
for
(
TraceSegment
segment
:
data
)
{
try
{
UpstreamSegment
upstreamSegment
=
segment
.
transform
();
upstreamSegmentStreamObserver
.
onNext
(
upstreamSegment
);
}
catch
(
Throwable
t
)
{
logger
.
error
(
t
,
"Transform and send UpstreamSegment to collector fail."
);
}
}
catch
(
Throwable
t
)
{
logger
.
error
(
t
,
"Send UpstreamSegment to collector fail."
);
}
upstreamSegmentStreamObserver
.
onCompleted
();
...
...
@@ -113,6 +112,9 @@ public class TraceSegmentServiceClient implements BootService, IConsumer<TraceSe
@Override
public
void
afterFinished
(
TraceSegment
traceSegment
)
{
if
(
traceSegment
.
isIgnore
())
{
return
;
}
if
(!
carrier
.
produce
(
traceSegment
))
{
if
(
logger
.
isDebugEnable
())
{
logger
.
debug
(
"One trace segment has been abandoned, cause by buffer is full."
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录