Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
6d2ab563
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 1 年多
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
6d2ab563
编写于
7月 01, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish codes of grpc segment client about channel control.
上级
34a0a0b4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
86 addition
and
5 deletion
+86
-5
apm-network/src/test/java/org/skywalking/apm/network/trace/proto/GRPCNoServerTest.java
.../skywalking/apm/network/trace/proto/GRPCNoServerTest.java
+47
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelManager.java
.../skywalking/apm/agent/core/remote/GRPCChannelManager.java
+35
-4
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java
...king/apm/agent/core/remote/TraceSegmentServiceClient.java
+4
-1
未找到文件。
apm-network/src/test/java/org/skywalking/apm/network/trace/proto/GRPCNoServerTest.java
0 → 100644
浏览文件 @
6d2ab563
package
org.skywalking.apm.network.trace.proto
;
import
io.grpc.ManagedChannel
;
import
io.grpc.ManagedChannelBuilder
;
import
io.grpc.Status
;
import
io.grpc.StatusRuntimeException
;
import
io.grpc.internal.DnsNameResolverProvider
;
import
io.grpc.netty.NettyChannelBuilder
;
import
io.grpc.stub.StreamObserver
;
import
org.junit.Assert
;
import
org.skywalking.apm.network.collecor.proto.Downstream
;
/**
* @author wusheng
*/
public
class
GRPCNoServerTest
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
ManagedChannelBuilder
<?>
channelBuilder
=
NettyChannelBuilder
.
forAddress
(
"127.0.0.1"
,
8080
)
.
nameResolverFactory
(
new
DnsNameResolverProvider
())
.
maxInboundMessageSize
(
1024
*
1024
*
50
)
.
usePlaintext
(
true
);
ManagedChannel
channel
=
channelBuilder
.
build
();
TraceSegmentServiceGrpc
.
TraceSegmentServiceStub
serviceStub
=
TraceSegmentServiceGrpc
.
newStub
(
channel
);
final
Status
[]
status
=
{
null
};
StreamObserver
<
UpstreamSegment
>
streamObserver
=
serviceStub
.
collect
(
new
StreamObserver
<
Downstream
>()
{
@Override
public
void
onNext
(
Downstream
value
)
{
}
@Override
public
void
onError
(
Throwable
t
)
{
status
[
0
]
=
((
StatusRuntimeException
)
t
).
getStatus
();
}
@Override
public
void
onCompleted
()
{
}
});
streamObserver
.
onNext
(
null
);
streamObserver
.
onCompleted
();
Thread
.
sleep
(
2
*
1000
);
Assert
.
assertEquals
(
status
[
0
].
getCode
(),
Status
.
UNAVAILABLE
.
getCode
());
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/GRPCChannelManager.java
浏览文件 @
6d2ab563
...
...
@@ -2,6 +2,8 @@ package org.skywalking.apm.agent.core.remote;
import
io.grpc.ManagedChannel
;
import
io.grpc.ManagedChannelBuilder
;
import
io.grpc.Status
;
import
io.grpc.StatusRuntimeException
;
import
io.grpc.internal.DnsNameResolverProvider
;
import
io.grpc.netty.NettyChannelBuilder
;
import
java.util.Collections
;
...
...
@@ -32,7 +34,7 @@ public class GRPCChannelManager implements BootService, Runnable {
@Override
public
void
boot
()
throws
Throwable
{
this
.
startup
InBackground
(
false
);
this
.
connect
InBackground
(
false
);
}
@Override
...
...
@@ -40,7 +42,7 @@ public class GRPCChannelManager implements BootService, Runnable {
}
private
void
startup
InBackground
(
boolean
forceStart
)
{
private
void
connect
InBackground
(
boolean
forceStart
)
{
if
(
channelManagerThread
==
null
||
!
channelManagerThread
.
isAlive
())
{
synchronized
(
this
)
{
if
(
forceStart
)
{
...
...
@@ -106,8 +108,37 @@ public class GRPCChannelManager implements BootService, Runnable {
return
managedChannel
;
}
public
void
reportError
()
{
this
.
startupInBackground
(
true
);
/**
* If the given expcetion is triggered by network problem, connect in background.
* @param throwable
*/
public
void
reportError
(
Throwable
throwable
)
{
if
(
isNetworkError
(
throwable
))
{
this
.
connectInBackground
(
true
);
}
}
private
boolean
isNetworkError
(
Throwable
throwable
)
{
if
(
throwable
instanceof
StatusRuntimeException
)
{
StatusRuntimeException
statusRuntimeException
=
(
StatusRuntimeException
)
throwable
;
return
statusEquals
(
statusRuntimeException
.
getStatus
(),
Status
.
UNAVAILABLE
,
Status
.
PERMISSION_DENIED
,
Status
.
UNAUTHENTICATED
,
Status
.
RESOURCE_EXHAUSTED
,
Status
.
UNKNOWN
);
}
return
false
;
}
private
boolean
statusEquals
(
Status
sourceStatus
,
Status
...
potentialStatus
)
{
for
(
Status
status
:
potentialStatus
)
{
if
(
sourceStatus
.
getCode
()
==
status
.
getCode
())
{
return
true
;
}
}
return
false
;
}
private
void
resetNextStartTime
()
{
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/remote/TraceSegmentServiceClient.java
浏览文件 @
6d2ab563
...
...
@@ -66,7 +66,10 @@ public class TraceSegmentServiceClient implements BootService, IConsumer<TraceSe
@Override
public
void
onError
(
Throwable
throwable
)
{
status
.
finished
();
ServiceManager
.
INSTANCE
.
findService
(
GRPCChannelManager
.
class
).
reportError
();
if
(
logger
.
isErrorEnable
())
{
logger
.
error
(
throwable
,
"Send UpstreamSegment to collector fail with a grpc internal exception."
);
}
ServiceManager
.
INSTANCE
.
findService
(
GRPCChannelManager
.
class
).
reportError
(
throwable
);
}
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录