Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
山不在高_有仙则灵
SkyWalking
提交
329f2247
S
SkyWalking
项目概览
山不在高_有仙则灵
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
12
Star
0
Fork
2
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
329f2247
编写于
7月 20, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New id mechanism, need to be tested.
上级
76ceb363
变更
19
展开全部
隐藏空白更改
内联
并排
Showing
19 changed file
with
1380 addition
and
84 deletion
+1380
-84
apm-network/src/main/proto/TraceSegmentService.proto
apm-network/src/main/proto/TraceSegmentService.proto
+7
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/AbstractTracerContext.java
...walking/apm/agent/core/context/AbstractTracerContext.java
+1
-1
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextCarrier.java
...org/skywalking/apm/agent/core/context/ContextCarrier.java
+7
-6
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java
...org/skywalking/apm/agent/core/context/ContextManager.java
+1
-1
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java
...rg/skywalking/apm/agent/core/context/ContextSnapshot.java
+4
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoredTracerContext.java
...ywalking/apm/agent/core/context/IgnoredTracerContext.java
+1
-1
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java
...org/skywalking/apm/agent/core/context/TracingContext.java
+2
-2
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceId.java
...alking/apm/agent/core/context/ids/DistributedTraceId.java
+20
-5
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java
...lking/apm/agent/core/context/ids/DistributedTraceIds.java
+0
-37
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java
...walking/apm/agent/core/context/ids/GlobalIdGenerator.java
+32
-14
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/ID.java
...in/java/org/skywalking/apm/agent/core/context/ids/ID.java
+114
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java
...ing/apm/agent/core/context/ids/NewDistributedTraceId.java
+1
-3
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Base64.java
.../skywalking/apm/agent/core/context/ids/base64/Base64.java
+973
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Objects.java
...skywalking/apm/agent/core/context/ids/base64/Objects.java
+157
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/StandardCharsets.java
...g/apm/agent/core/context/ids/base64/StandardCharsets.java
+44
-0
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
+6
-5
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
+3
-2
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java
...ng/apm/agent/core/remote/AppAndServiceRegisterClient.java
+3
-0
pom.xml
pom.xml
+4
-1
未找到文件。
apm-network/src/main/proto/TraceSegmentService.proto
浏览文件 @
329f2247
...
...
@@ -12,12 +12,16 @@ service TraceSegmentService {
}
message
UpstreamSegment
{
repeated
string
globalTraceIds
=
1
;
repeated
UniqueId
globalTraceIds
=
1
;
bytes
segment
=
2
;
// the byte array of TraceSegmentObject
}
message
UniqueId
{
repeated
int64
idParts
=
1
;
}
message
TraceSegmentObject
{
string
traceSegmentId
=
1
;
UniqueId
traceSegmentId
=
1
;
repeated
TraceSegmentReference
refs
=
2
;
repeated
SpanObject
spans
=
3
;
int32
applicationId
=
4
;
...
...
@@ -26,7 +30,7 @@ message TraceSegmentObject {
message
TraceSegmentReference
{
RefType
refType
=
1
;
string
parentTraceSegmentId
=
2
;
UniqueId
parentTraceSegmentId
=
2
;
int32
parentSpanId
=
3
;
int32
parentApplicationInstanceId
=
4
;
string
networkAddress
=
5
;
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/AbstractTracerContext.java
浏览文件 @
329f2247
...
...
@@ -55,7 +55,7 @@ public interface AbstractTracerContext {
* @return the string represents the id.
* @see {@link TracingContext} and {@link IgnoredTracerContext}
*/
String
getGlobalTraceId
();
String
get
Readable
GlobalTraceId
();
/**
* Create an entry span
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextCarrier.java
浏览文件 @
329f2247
...
...
@@ -3,6 +3,7 @@ package org.skywalking.apm.agent.core.context;
import
java.io.Serializable
;
import
java.util.List
;
import
org.skywalking.apm.agent.core.context.ids.DistributedTraceId
;
import
org.skywalking.apm.agent.core.context.ids.ID
;
import
org.skywalking.apm.agent.core.context.ids.PropagatedTraceId
;
import
org.skywalking.apm.agent.core.context.trace.TraceSegment
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
...
...
@@ -18,7 +19,7 @@ public class ContextCarrier implements Serializable {
/**
* {@link TraceSegment#traceSegmentId}
*/
private
String
traceSegmentId
;
private
ID
traceSegmentId
;
private
int
spanId
=
-
1
;
...
...
@@ -44,7 +45,7 @@ public class ContextCarrier implements Serializable {
public
String
serialize
()
{
if
(
this
.
isValid
())
{
return
StringUtil
.
join
(
'|'
,
this
.
getTraceSegmentId
(),
this
.
getTraceSegmentId
()
.
toBase64
()
,
this
.
getSpanId
()
+
""
,
this
.
getApplicationInstanceId
()
+
""
,
this
.
getPeerHost
(),
...
...
@@ -66,7 +67,7 @@ public class ContextCarrier implements Serializable {
String
[]
parts
=
text
.
split
(
"\\|"
,
7
);
if
(
parts
.
length
==
7
)
{
try
{
this
.
traceSegmentId
=
parts
[
0
]
;
this
.
traceSegmentId
=
new
ID
(
parts
[
0
])
;
this
.
spanId
=
Integer
.
parseInt
(
parts
[
1
]);
this
.
applicationInstanceId
=
Integer
.
parseInt
(
parts
[
2
]);
this
.
peerHost
=
parts
[
3
];
...
...
@@ -87,7 +88,7 @@ public class ContextCarrier implements Serializable {
* @return true for unbroken {@link ContextCarrier} or no-initialized. Otherwise, false;
*/
public
boolean
isValid
()
{
return
!
StringUtil
.
isEmpty
(
traceSegmentId
)
return
traceSegmentId
!=
null
&&
getSpanId
()
>
-
1
&&
applicationInstanceId
!=
DictionaryUtil
.
nullValue
()
&&
!
StringUtil
.
isEmpty
(
peerHost
)
...
...
@@ -116,7 +117,7 @@ public class ContextCarrier implements Serializable {
this
.
parentOperationName
=
parentOperationId
+
""
;
}
public
String
getTraceSegmentId
()
{
public
ID
getTraceSegmentId
()
{
return
traceSegmentId
;
}
...
...
@@ -124,7 +125,7 @@ public class ContextCarrier implements Serializable {
return
spanId
;
}
void
setTraceSegmentId
(
String
traceSegmentId
)
{
void
setTraceSegmentId
(
ID
traceSegmentId
)
{
this
.
traceSegmentId
=
traceSegmentId
;
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextManager.java
浏览文件 @
329f2247
...
...
@@ -76,7 +76,7 @@ public class ContextManager implements TracingContextListener, BootService, Igno
if
(
segment
==
null
)
{
return
"N/A"
;
}
else
{
return
segment
.
getGlobalTraceId
();
return
segment
.
get
Readable
GlobalTraceId
();
}
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java
浏览文件 @
329f2247
...
...
@@ -2,6 +2,7 @@ package org.skywalking.apm.agent.core.context;
import
java.util.List
;
import
org.skywalking.apm.agent.core.context.ids.DistributedTraceId
;
import
org.skywalking.apm.agent.core.context.ids.ID
;
import
org.skywalking.apm.util.StringUtil
;
/**
...
...
@@ -14,7 +15,7 @@ public class ContextSnapshot {
/**
* trace segment id of the parent trace segment.
*/
private
String
traceSegmentId
;
private
ID
traceSegmentId
;
/**
* span id of the parent span, in parent trace segment.
...
...
@@ -30,7 +31,7 @@ public class ContextSnapshot {
*/
private
DistributedTraceId
primaryDistributedTraceId
;
ContextSnapshot
(
String
traceSegmentId
,
int
spanId
,
ContextSnapshot
(
ID
traceSegmentId
,
int
spanId
,
List
<
DistributedTraceId
>
distributedTraceIds
)
{
this
.
traceSegmentId
=
traceSegmentId
;
this
.
spanId
=
spanId
;
...
...
@@ -59,7 +60,7 @@ public class ContextSnapshot {
return
primaryDistributedTraceId
;
}
public
String
getTraceSegmentId
()
{
public
ID
getTraceSegmentId
()
{
return
traceSegmentId
;
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/IgnoredTracerContext.java
浏览文件 @
329f2247
...
...
@@ -41,7 +41,7 @@ public class IgnoredTracerContext implements AbstractTracerContext {
}
@Override
public
String
getGlobalTraceId
()
{
public
String
get
Readable
GlobalTraceId
()
{
return
"[Ignored Trace]"
;
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java
浏览文件 @
329f2247
...
...
@@ -184,8 +184,8 @@ public class TracingContext implements AbstractTracerContext {
* @return the first global trace id.
*/
@Override
public
String
getGlobalTraceId
()
{
return
segment
.
getRelatedGlobalTraces
().
get
(
0
).
get
();
public
String
get
Readable
GlobalTraceId
()
{
return
segment
.
getRelatedGlobalTraces
().
get
(
0
).
toString
();
}
/**
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceId.java
浏览文件 @
329f2247
package
org.skywalking.apm.agent.core.context.ids
;
import
org.skywalking.apm.network.proto.UniqueId
;
/**
* The <code>DistributedTraceId</code> presents a distributed call chain.
* <p>
...
...
@@ -14,14 +16,27 @@ package org.skywalking.apm.agent.core.context.ids;
* @author wusheng
*/
public
abstract
class
DistributedTraceId
{
private
String
id
;
private
ID
id
;
public
DistributedTraceId
(
String
id
)
{
public
DistributedTraceId
(
ID
id
)
{
this
.
id
=
id
;
}
public
String
get
()
{
return
id
;
public
DistributedTraceId
(
String
id
)
{
this
.
id
=
new
ID
(
id
);
}
public
String
toBase64
()
{
return
id
.
toBase64
();
}
@Override
public
String
toString
()
{
return
id
.
toString
();
}
public
UniqueId
toUniqueId
()
{
return
id
.
transform
();
}
/**
...
...
@@ -38,7 +53,7 @@ public abstract class DistributedTraceId {
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
DistributedTraceId
id1
=
(
DistributedTraceId
)
o
;
DistributedTraceId
id1
=
(
DistributedTraceId
)
o
;
return
id
!=
null
?
id
.
equals
(
id1
.
id
)
:
id1
.
id
==
null
;
}
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/DistributedTraceIds.java
浏览文件 @
329f2247
package
org.skywalking.apm.agent.core.context.ids
;
import
com.google.gson.TypeAdapter
;
import
com.google.gson.annotations.JsonAdapter
;
import
com.google.gson.stream.JsonReader
;
import
com.google.gson.stream.JsonWriter
;
import
java.io.IOException
;
import
java.util.Collections
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -12,7 +7,6 @@ import java.util.List;
/**
* @author wusheng
*/
@JsonAdapter
(
DistributedTraceIds
.
Serializer
.
class
)
public
class
DistributedTraceIds
{
private
LinkedList
<
DistributedTraceId
>
relatedGlobalTraces
;
...
...
@@ -32,35 +26,4 @@ public class DistributedTraceIds {
relatedGlobalTraces
.
add
(
distributedTraceId
);
}
}
public
static
class
Serializer
extends
TypeAdapter
<
DistributedTraceIds
>
{
@Override
public
void
write
(
JsonWriter
out
,
DistributedTraceIds
value
)
throws
IOException
{
List
<
DistributedTraceId
>
globalTraces
=
value
.
getRelatedGlobalTraces
();
if
(
globalTraces
.
size
()
>
0
)
{
out
.
beginArray
();
for
(
DistributedTraceId
trace
:
globalTraces
)
{
out
.
value
(
trace
.
get
());
}
out
.
endArray
();
}
}
@Override
public
DistributedTraceIds
read
(
JsonReader
in
)
throws
IOException
{
DistributedTraceIds
distributedTraceIds
=
new
DistributedTraceIds
();
in
.
beginArray
();
try
{
while
(
in
.
hasNext
())
{
PropagatedTraceId
traceId
=
new
PropagatedTraceId
(
in
.
nextString
());
distributedTraceIds
.
append
(
traceId
);
}
}
finally
{
in
.
endArray
();
}
return
distributedTraceIds
;
}
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java
浏览文件 @
329f2247
package
org.skywalking.apm.agent.core.context.ids
;
import
java.util.UUID
;
import
org.skywalking.apm.util.MachineInfo
;
import
org.skywalking.apm.util.StringUtil
;
import
org.skywalking.apm.agent.core.conf.RemoteDownstreamConfig
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
public
final
class
GlobalIdGenerator
{
private
static
final
ThreadLocal
<
Integer
>
THREAD_ID_SEQUENCE
=
new
ThreadLocal
<
Integer
>()
{
...
...
@@ -12,23 +11,42 @@ public final class GlobalIdGenerator {
}
};
private
static
final
int
PROCESS_UUID
;
static
{
String
uuid
=
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
PROCESS_UUID
=
uuid
.
substring
(
uuid
.
length
()
-
7
).
hashCode
();
}
private
GlobalIdGenerator
()
{
}
public
static
String
generate
(
String
type
)
{
/**
* Generate a new id, combined by three long numbers.
*
* The first one represents application instance id. (most likely just an integer value, would be helpful in
* protobuf)
*
* The second one represents thread id. (most likely just an integer value, would be helpful in protobuf)
*
* The third one also has two parts,<br/>
* 1) a timestamp, measured in milliseconds<br/>
* 2) a seq, in current thread, between 0(included) and 9999(included)
*
* Notice, a long costs 8 bytes, three longs cost 24 bytes. And at the same time, a char costs 2 bytes. So
* sky-walking's old global and segment id like this: "S.1490097253214.-866187727.57515.1.1" which costs at least 72
* bytes.
*
* @return an array contains three long numbers, which represents a unique id.
*/
public
static
ID
generate
()
{
if
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_INSTANCE_ID
==
DictionaryUtil
.
nullValue
())
{
throw
new
IllegalStateException
();
}
Integer
seq
=
THREAD_ID_SEQUENCE
.
get
();
seq
++;
if
(
seq
>
9999
)
{
seq
=
0
;
}
THREAD_ID_SEQUENCE
.
set
(
seq
);
return
StringUtil
.
join
(
'.'
,
type
+
""
,
System
.
currentTimeMillis
()
+
""
,
PROCESS_UUID
+
""
,
MachineInfo
.
getProcessNo
()
+
""
,
Thread
.
currentThread
().
getId
()
+
""
,
seq
+
""
);
return
new
ID
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_INSTANCE_ID
,
Thread
.
currentThread
().
getId
(),
System
.
currentTimeMillis
()
*
10000
+
seq
);
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/ID.java
0 → 100644
浏览文件 @
329f2247
package
org.skywalking.apm.agent.core.context.ids
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
org.skywalking.apm.agent.core.context.ids.base64.Base64
;
import
org.skywalking.apm.network.proto.UniqueId
;
/**
* @author wusheng
*/
public
class
ID
{
private
static
final
Base64
.
Encoder
ENCODER
=
Base64
.
getEncoder
();
private
static
final
Base64
.
Decoder
DECODER
=
Base64
.
getDecoder
();
private
long
part1
;
private
long
part2
;
private
long
part3
;
public
ID
(
long
part1
,
long
part2
,
long
part3
)
{
this
.
part1
=
part1
;
this
.
part2
=
part2
;
this
.
part3
=
part3
;
}
public
ID
(
String
base64String
)
{
int
index
=
0
;
for
(
int
part
=
0
;
part
<
3
;
part
++)
{
String
encodedString
;
char
potentialTypeChar
=
base64String
.
charAt
(
index
);
long
value
;
if
(
potentialTypeChar
==
'#'
)
{
encodedString
=
base64String
.
substring
(
index
+
1
,
index
+
5
);
index
+=
5
;
value
=
ByteBuffer
.
wrap
(
DECODER
.
decode
(
encodedString
)).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
asShortBuffer
().
get
(
0
);
}
else
if
(
potentialTypeChar
==
'$'
)
{
encodedString
=
base64String
.
substring
(
index
+
1
,
index
+
9
);
index
+=
8
;
value
=
ByteBuffer
.
wrap
(
DECODER
.
decode
(
encodedString
)).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
asIntBuffer
().
get
(
0
);
}
else
{
encodedString
=
base64String
.
substring
(
index
+
1
,
index
+
13
);
index
+=
12
;
value
=
ByteBuffer
.
wrap
(
DECODER
.
decode
(
encodedString
)).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
asLongBuffer
().
get
(
0
);
}
if
(
part
==
0
)
{
part1
=
part
;
}
else
if
(
part
==
1
)
{
part2
=
part
;
}
else
{
part3
=
part
;
}
}
}
public
String
toBase64
()
{
return
long2Base64
(
part1
)
+
long2Base64
(
part2
)
+
long2Base64
(
part3
);
}
private
String
long2Base64
(
long
partN
)
{
if
(
partN
<
0
)
{
throw
new
IllegalArgumentException
(
"negative value."
);
}
if
(
partN
<
32768
)
{
// 0 - 32767
// "#" as a prefix of a short value with base64 encoding.
byte
[]
data
=
new
byte
[
2
];
ByteBuffer
.
wrap
(
data
).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
asShortBuffer
().
put
((
short
)
partN
);
return
'#'
+
ENCODER
.
encodeToString
(
data
);
}
else
if
(
partN
<=
2147483647
)
{
// 32768 - 2147483647
// "$" as a prefix of an integer value (greater than a short) with base64 encoding.
byte
[]
data
=
new
byte
[
4
];
ByteBuffer
.
wrap
(
data
).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
asIntBuffer
().
put
((
int
)
partN
);
return
'$'
+
ENCODER
.
encodeToString
(
data
);
}
else
{
// > 2147483647
// a long value (greater than an integer)
byte
[]
data
=
new
byte
[
8
];
ByteBuffer
.
wrap
(
data
).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
asLongBuffer
().
put
(
partN
);
return
ENCODER
.
encodeToString
(
data
);
}
}
@Override
public
String
toString
()
{
return
part1
+
"."
+
part2
+
'.'
+
part3
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
ID
id
=
(
ID
)
o
;
if
(
part1
!=
id
.
part1
)
return
false
;
if
(
part2
!=
id
.
part2
)
return
false
;
return
part3
==
id
.
part3
;
}
@Override
public
int
hashCode
()
{
int
result
=
(
int
)(
part1
^
(
part1
>>>
32
));
result
=
31
*
result
+
(
int
)(
part2
^
(
part2
>>>
32
));
result
=
31
*
result
+
(
int
)(
part3
^
(
part3
>>>
32
));
return
result
;
}
public
UniqueId
transform
()
{
return
UniqueId
.
newBuilder
().
addIdParts
(
part1
).
addIdParts
(
part2
).
addIdParts
(
part3
).
build
();
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/NewDistributedTraceId.java
浏览文件 @
329f2247
...
...
@@ -6,9 +6,7 @@ package org.skywalking.apm.agent.core.context.ids;
* @author wusheng
*/
public
class
NewDistributedTraceId
extends
DistributedTraceId
{
private
static
final
String
ID_TYPE
=
"T"
;
public
NewDistributedTraceId
()
{
super
(
GlobalIdGenerator
.
generate
(
ID_TYPE
));
super
(
GlobalIdGenerator
.
generate
());
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Base64.java
0 → 100644
浏览文件 @
329f2247
此差异已折叠。
点击以展开。
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/Objects.java
0 → 100644
浏览文件 @
329f2247
package
org.skywalking.apm.agent.core.context.ids.base64
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.List
;
/**
* This class consists of {@code static} utility methods for operating
* on objects. These utilities include {@code null}-safe or {@code
* null}-tolerant methods for computing the hash code of an object,
* returning a string for an object, and comparing two objects.
*
* @since 1.7
*/
public
final
class
Objects
{
private
Objects
()
{
throw
new
AssertionError
(
"No java.util.Objects instances for you!"
);
}
/**
* Returns {@code true} if the arguments are equal to each other
* and {@code false} otherwise.
* Consequently, if both arguments are {@code null}, {@code true}
* is returned and if exactly one argument is {@code null}, {@code
* false} is returned. Otherwise, equality is determined by using
* the {@link Object#equals equals} method of the first
* argument.
*
* @param a an object
* @param b an object to be compared with {@code a} for equality
* @return {@code true} if the arguments are equal to each other
* and {@code false} otherwise
* @see Object#equals(Object)
*/
public
static
boolean
equals
(
Object
a
,
Object
b
)
{
return
(
a
==
b
)
||
(
a
!=
null
&&
a
.
equals
(
b
));
}
/**
* Returns the hash code of a non-{@code null} argument and 0 for
* a {@code null} argument.
*
* @param o an object
* @return the hash code of a non-{@code null} argument and 0 for
* a {@code null} argument
* @see Object#hashCode
*/
public
static
int
hashCode
(
Object
o
)
{
return
o
!=
null
?
o
.
hashCode
()
:
0
;
}
/**
* Generates a hash code for a sequence of input values. The hash
* code is generated as if all the input values were placed into an
* array, and that array were hashed by calling {@link
* Arrays#hashCode(Object[])}.
*
* <p>This method is useful for implementing {@link
* Object#hashCode()} on objects containing multiple fields. For
* example, if an object that has three fields, {@code x}, {@code
* y}, and {@code z}, one could write:
*
* <blockquote><pre>
* @Override public int hashCode() {
* return Objects.hash(x, y, z);
* }
* </pre></blockquote>
*
* <b>Warning: When a single object reference is supplied, the returned
* value does not equal the hash code of that object reference.</b> This
* value can be computed by calling {@link #hashCode(Object)}.
*
* @param values the values to be hashed
* @return a hash value of the sequence of input values
* @see Arrays#hashCode(Object[])
* @see List#hashCode
*/
public
static
int
hash
(
Object
...
values
)
{
return
Arrays
.
hashCode
(
values
);
}
/**
* Returns the result of calling {@code toString} for a non-{@code
* null} argument and {@code "null"} for a {@code null} argument.
*
* @param o an object
* @return the result of calling {@code toString} for a non-{@code
* null} argument and {@code "null"} for a {@code null} argument
* @see Object#toString
* @see String#valueOf(Object)
*/
public
static
String
toString
(
Object
o
)
{
return
String
.
valueOf
(
o
);
}
/**
* Returns the result of calling {@code toString} on the first
* argument if the first argument is not {@code null} and returns
* the second argument otherwise.
*
* @param o an object
* @param nullDefault string to return if the first argument is
* {@code null}
* @return the result of calling {@code toString} on the first
* argument if it is not {@code null} and the second argument
* otherwise.
*/
public
static
String
toString
(
Object
o
,
String
nullDefault
)
{
return
(
o
!=
null
)
?
o
.
toString
()
:
nullDefault
;
}
/**
* Returns 0 if the arguments are identical and {@code
* c.compare(a, b)} otherwise.
* Consequently, if both arguments are {@code null} 0
* is returned.
*
* <p>Note that if one of the arguments is {@code null}, a {@code
* NullPointerException} may or may not be thrown depending on
* what ordering policy, if any, the {@link Comparator Comparator}
* chooses to have for {@code null} values.
*
* @param <T> the type of the objects being compared
* @param a an object
* @param b an object to be compared with {@code a}
* @param c the {@code Comparator} to compare the first two arguments
* @return 0 if the arguments are identical and {@code
* c.compare(a, b)} otherwise.
* @see Comparable
* @see Comparator
*/
public
static
<
T
>
int
compare
(
T
a
,
T
b
,
Comparator
<?
super
T
>
c
)
{
return
(
a
==
b
)
?
0
:
c
.
compare
(
a
,
b
);
}
/**
* Checks that the specified object reference is not {@code null}. This
* method is designed primarily for doing parameter validation in methods
* and constructors, as demonstrated below:
* <blockquote><pre>
* public Foo(Bar bar) {
* this.bar = Objects.requireNonNull(bar);
* }
* </pre></blockquote>
*
* @param obj the object reference to check for nullity
* @param <T> the type of the reference
* @return {@code obj} if not {@code null}
* @throws NullPointerException if {@code obj} is {@code null}
*/
public
static
<
T
>
T
requireNonNull
(
T
obj
)
{
if
(
obj
==
null
)
throw
new
NullPointerException
();
return
obj
;
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ids/base64/StandardCharsets.java
0 → 100644
浏览文件 @
329f2247
package
org.skywalking.apm.agent.core.context.ids.base64
;
import
java.nio.charset.Charset
;
/**
* Constant definitions for the standard {@link Charset Charsets}. These
* charsets are guaranteed to be available on every implementation of the Java
* platform.
*
* @see <a href="Charset#standard">Standard Charsets</a>
* @since 1.7
*/
public
final
class
StandardCharsets
{
private
StandardCharsets
()
{
throw
new
AssertionError
(
"No java.nio.charset.StandardCharsets instances for you!"
);
}
/**
* Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the
* Unicode character set
*/
public
static
final
Charset
US_ASCII
=
Charset
.
forName
(
"US-ASCII"
);
/**
* ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
*/
public
static
final
Charset
ISO_8859_1
=
Charset
.
forName
(
"ISO-8859-1"
);
/**
* Eight-bit UCS Transformation Format
*/
public
static
final
Charset
UTF_8
=
Charset
.
forName
(
"UTF-8"
);
/**
* Sixteen-bit UCS Transformation Format, big-endian byte order
*/
public
static
final
Charset
UTF_16BE
=
Charset
.
forName
(
"UTF-16BE"
);
/**
* Sixteen-bit UCS Transformation Format, little-endian byte order
*/
public
static
final
Charset
UTF_16LE
=
Charset
.
forName
(
"UTF-16LE"
);
/**
* Sixteen-bit UCS Transformation Format, byte order identified by an
* optional byte-order mark
*/
public
static
final
Charset
UTF_16
=
Charset
.
forName
(
"UTF-16"
);
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegment.java
浏览文件 @
329f2247
...
...
@@ -6,6 +6,7 @@ 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
;
import
org.skywalking.apm.agent.core.context.ids.ID
;
import
org.skywalking.apm.agent.core.context.ids.NewDistributedTraceId
;
import
org.skywalking.apm.logging.ILog
;
import
org.skywalking.apm.logging.LogManager
;
...
...
@@ -31,7 +32,7 @@ public class TraceSegment {
* The id of this trace segment.
* Every segment has its unique-global-id.
*/
private
String
traceSegmentId
;
private
ID
traceSegmentId
;
/**
* The refs of parent trace segments, except the primary one.
...
...
@@ -71,7 +72,7 @@ public class TraceSegment {
* and generate a new segment id.
*/
public
TraceSegment
()
{
this
.
traceSegmentId
=
GlobalIdGenerator
.
generate
(
ID_TYPE
);
this
.
traceSegmentId
=
GlobalIdGenerator
.
generate
();
this
.
spans
=
new
LinkedList
<
AbstractTracingSpan
>();
this
.
relatedGlobalTraces
=
new
DistributedTraceIds
();
this
.
relatedGlobalTraces
.
append
(
new
NewDistributedTraceId
());
...
...
@@ -117,7 +118,7 @@ public class TraceSegment {
return
this
;
}
public
String
getTraceSegmentId
()
{
public
ID
getTraceSegmentId
()
{
return
traceSegmentId
;
}
...
...
@@ -157,13 +158,13 @@ public class TraceSegment {
public
UpstreamSegment
transform
()
{
UpstreamSegment
.
Builder
upstreamBuilder
=
UpstreamSegment
.
newBuilder
();
for
(
DistributedTraceId
distributedTraceId
:
getRelatedGlobalTraces
())
{
upstreamBuilder
=
upstreamBuilder
.
addGlobalTraceIds
(
distributedTraceId
.
get
());
upstreamBuilder
=
upstreamBuilder
.
addGlobalTraceIds
(
distributedTraceId
.
toUniqueId
());
}
TraceSegmentObject
.
Builder
traceSegmentBuilder
=
TraceSegmentObject
.
newBuilder
();
/**
* Trace Segment
*/
traceSegmentBuilder
.
setTraceSegmentId
(
this
.
traceSegmentId
);
traceSegmentBuilder
.
setTraceSegmentId
(
this
.
traceSegmentId
.
transform
()
);
// TraceSegmentReference
if
(
this
.
refs
!=
null
)
{
for
(
TraceSegmentRef
ref
:
this
.
refs
)
{
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/TraceSegmentRef.java
浏览文件 @
329f2247
...
...
@@ -2,6 +2,7 @@ package org.skywalking.apm.agent.core.context.trace;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.skywalking.apm.agent.core.context.ContextSnapshot
;
import
org.skywalking.apm.agent.core.context.ids.ID
;
import
org.skywalking.apm.agent.core.dictionary.DictionaryUtil
;
import
org.skywalking.apm.network.proto.RefType
;
import
org.skywalking.apm.network.proto.TraceSegmentReference
;
...
...
@@ -15,7 +16,7 @@ import org.skywalking.apm.network.proto.TraceSegmentReference;
public
class
TraceSegmentRef
{
private
SegmentRefType
type
;
private
String
traceSegmentId
;
private
ID
traceSegmentId
;
private
int
spanId
=
-
1
;
...
...
@@ -103,7 +104,7 @@ public class TraceSegmentRef {
refBuilder
.
setRefType
(
RefType
.
CrossThread
);
}
refBuilder
.
setParentTraceSegmentId
(
traceSegmentId
);
refBuilder
.
setParentTraceSegmentId
(
traceSegmentId
.
transform
()
);
refBuilder
.
setParentSpanId
(
spanId
);
if
(
entryOperationId
==
DictionaryUtil
.
nullValue
())
{
refBuilder
.
setEntryServiceName
(
entryOperationName
);
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java
浏览文件 @
329f2247
package
org.skywalking.apm.agent.core.remote
;
import
io.grpc.ManagedChannel
;
import
java.util.UUID
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -33,6 +34,7 @@ import static org.skywalking.apm.agent.core.remote.GRPCChannelStatus.CONNECTED;
*/
public
class
AppAndServiceRegisterClient
implements
BootService
,
GRPCChannelListener
,
Runnable
,
TracingContextListener
{
private
static
final
ILog
logger
=
LogManager
.
getLogger
(
AppAndServiceRegisterClient
.
class
);
private
static
final
String
PROCESS_UUID
=
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
private
volatile
GRPCChannelStatus
status
=
GRPCChannelStatus
.
DISCONNECT
;
private
volatile
ApplicationRegisterServiceGrpc
.
ApplicationRegisterServiceBlockingStub
applicationRegisterServiceBlockingStub
;
...
...
@@ -100,6 +102,7 @@ public class AppAndServiceRegisterClient implements BootService, GRPCChannelList
ApplicationInstanceMapping
instanceMapping
=
instanceDiscoveryServiceBlockingStub
.
register
(
ApplicationInstance
.
newBuilder
()
.
setApplicationId
(
RemoteDownstreamConfig
.
Agent
.
APPLICATION_ID
)
.
setAgentUUID
(
PROCESS_UUID
)
.
setRegisterTime
(
System
.
currentTimeMillis
())
.
build
());
if
(
instanceMapping
.
getApplicationInstanceId
()
!=
DictionaryUtil
.
nullValue
())
{
...
...
pom.xml
浏览文件 @
329f2247
...
...
@@ -174,6 +174,7 @@
<excludes>
<exclude>
org/skywalking/apm/network/**/*.class
</exclude>
<exclude>
org/skywalking/apm/collector/remote/grpc/**/*.class
</exclude>
<exclude>
org/skywalking/apm/agent/core/context/ids/base64/*.class
</exclude>
</excludes>
</instrumentation>
</configuration>
...
...
@@ -199,7 +200,9 @@
<consoleOutput>
true
</consoleOutput>
<failsOnError>
true
</failsOnError>
<excludes>
org/skywalking/apm/network/**/*.java,
org/skywalking/apm/collector/remote/grpc/**/*.java
</excludes>
org/skywalking/apm/collector/remote/grpc/**/*.java,
org/skywalking/apm/agent/core/context/ids/base64/*.java
</excludes>
</configuration>
<goals>
<goal>
check
</goal>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录