Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
aa10ce79
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 搜索 >>
提交
aa10ce79
编写于
3月 08, 2017
作者:
wu-sheng
提交者:
GitHub
3月 08, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #98 from ascrutae/feature/3.0
fix issue
上级
507b6b06
21696f13
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
75 addition
and
184 deletion
+75
-184
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/assist/NoCocurrencyAceessObject.java
...i/plugin/interceptor/assist/NoCocurrencyAceessObject.java
+2
-0
skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java
...a/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java
+2
-2
skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java
...ng/plugin/httpClient/v4/HttpClientExecuteInterceptor.java
+22
-6
skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/test/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java
...lugin/httpClient/v4/HttpClientExecuteInterceptorTest.java
+2
-2
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerFetchRequestURLInterceptor.java
...plugin/motan/MotanConsumerFetchRequestURLInterceptor.java
+0
-40
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerInterceptor.java
...eye/skywalking/plugin/motan/MotanConsumerInterceptor.java
+18
-12
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptor.java
...eye/skywalking/plugin/motan/MotanProviderInterceptor.java
+15
-33
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanConsumerInstrumentation.java
...ing/plugin/motan/define/MotanConsumerInstrumentation.java
+5
-18
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanProviderInstrumentation.java
...ing/plugin/motan/define/MotanProviderInstrumentation.java
+5
-5
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanConsumerFetchRequestURLInterceptorTest.java
...in/motan/MotanConsumerFetchRequestURLInterceptorTest.java
+0
-54
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanConsumerInterceptorTest.java
...skywalking/plugin/motan/MotanConsumerInterceptorTest.java
+4
-3
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptorTest.java
...skywalking/plugin/motan/MotanProviderInterceptorTest.java
+0
-9
未找到文件。
skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/assist/NoCocurrencyAceessObject.java
浏览文件 @
aa10ce79
...
...
@@ -30,6 +30,7 @@ public abstract class NoCocurrencyAceessObject implements InstanceMethodsAroundI
if
(++
counter
==
1
){
runnable
.
run
();
}
context
.
set
(
invokeCounterKey
,
counter
);
}
public
void
whenExist
(
EnhancedClassInstanceContext
context
,
Runnable
runnable
)
{
...
...
@@ -42,5 +43,6 @@ public abstract class NoCocurrencyAceessObject implements InstanceMethodsAroundI
if
(--
counter
==
0
){
runnable
.
run
();
}
context
.
set
(
invokeCounterKey
,
counter
);
}
}
skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java
浏览文件 @
aa10ce79
...
...
@@ -54,11 +54,11 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
Span
span
=
ContextManager
.
INSTANCE
.
createSpan
(
generateOperationName
(
requestURL
,
invocation
));
Tags
.
URL
.
set
(
span
,
generateRequestURL
(
requestURL
,
invocation
));
Tags
.
COMPONENT
.
set
(
span
,
DUBBO_COMPONENT
);
Tags
.
PEER_HOST
.
set
(
span
,
requestURL
.
getHost
());
Tags
.
PEER_PORT
.
set
(
span
,
requestURL
.
getPort
());
Tags
.
SPAN_LAYER
.
asRPCFramework
(
span
);
if
(
isConsumer
)
{
Tags
.
PEER_HOST
.
set
(
span
,
requestURL
.
getHost
());
Tags
.
PEER_PORT
.
set
(
span
,
requestURL
.
getPort
());
Tags
.
SPAN_KIND
.
set
(
span
,
Tags
.
SPAN_KIND_CLIENT
);
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
ContextManager
.
INSTANCE
.
inject
(
contextCarrier
);
...
...
skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java
浏览文件 @
aa10ce79
...
...
@@ -16,6 +16,9 @@ import org.apache.http.HttpRequest;
import
org.apache.http.HttpResponse
;
import
org.apache.http.StatusLine
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
/**
* {@link HttpClientExecuteInterceptor} transport the trace context by call {@link HttpRequest#setHeader(Header)},
* The current span tag the {@link Tags#ERROR} if {@link StatusLine#getStatusCode()} is not equals 200.
...
...
@@ -24,7 +27,7 @@ import org.apache.http.StatusLine;
*/
public
class
HttpClientExecuteInterceptor
implements
InstanceMethodsAroundInterceptor
{
public
static
final
String
HEADER_NAME_OF_CONTEXT_DATA
=
"SWTraceContext"
;
private
static
final
String
COMPONENT_NAME
=
"Http"
;
private
static
final
String
COMPONENT_NAME
=
"Http
Client
"
;
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
...
...
@@ -36,13 +39,12 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
}
HttpHost
httpHost
=
(
HttpHost
)
allArguments
[
0
];
HttpRequest
httpRequest
=
(
HttpRequest
)
allArguments
[
1
];
Span
span
=
ContextManager
.
INSTANCE
.
createSpan
(
httpRequest
.
getRequestLine
().
getUri
());
Span
span
=
createSpan
(
httpRequest
);
Tags
.
PEER_PORT
.
set
(
span
,
httpHost
.
getPort
());
Tags
.
PEER_HOST
.
set
(
span
,
httpHost
.
getHostName
());
Tags
.
SPAN_KIND
.
set
(
span
,
Tags
.
SPAN_KIND_CLIENT
);
Tags
.
COMPONENT
.
set
(
span
,
COMPONENT_NAME
);
Tags
.
URL
.
set
(
span
,
generateURL
(
http
Host
,
http
Request
));
Tags
.
URL
.
set
(
span
,
generateURL
(
httpRequest
));
Tags
.
SPAN_LAYER
.
asHttp
(
span
);
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
...
...
@@ -55,8 +57,22 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
*
* @return request URL
*/
private
String
generateURL
(
HttpHost
httpHost
,
HttpRequest
httpRequest
)
{
return
httpHost
.
getSchemeName
()
+
"://"
+
httpHost
.
getHostName
()
+
":"
+
httpHost
.
getPort
()
+
httpRequest
.
getRequestLine
().
getUri
();
private
String
generateURL
(
HttpRequest
httpRequest
)
{
return
httpRequest
.
getRequestLine
().
getUri
();
}
/**
* Create span.
*/
private
Span
createSpan
(
HttpRequest
httpRequest
)
{
Span
span
;
try
{
URL
url
=
new
URL
(
httpRequest
.
getRequestLine
().
getUri
());
span
=
ContextManager
.
INSTANCE
.
createSpan
(
url
.
getPath
());
}
catch
(
MalformedURLException
e
)
{
span
=
ContextManager
.
INSTANCE
.
createSpan
(
httpRequest
.
getRequestLine
().
getUri
());
}
return
span
;
}
@Override
...
...
skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/test/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptorTest.java
浏览文件 @
aa10ce79
...
...
@@ -77,7 +77,7 @@ public class HttpClientExecuteInterceptorTest {
@Override
public
String
getUri
()
{
return
"/test-web/test"
;
return
"
http://127.0.0.1:8080
/test-web/test"
;
}
});
when
(
httpHost
.
getPort
()).
thenReturn
(
8080
);
...
...
@@ -151,7 +151,7 @@ public class HttpClientExecuteInterceptorTest {
private
void
assertHttpSpan
(
Span
span
)
{
assertThat
(
span
.
getOperationName
(),
is
(
"/test-web/test"
));
assertThat
(
Tags
.
COMPONENT
.
get
(
span
),
is
(
"Http"
));
assertThat
(
Tags
.
COMPONENT
.
get
(
span
),
is
(
"Http
Client
"
));
assertThat
(
Tags
.
PEER_HOST
.
get
(
span
),
is
(
"127.0.0.1"
));
assertThat
(
Tags
.
PEER_PORT
.
get
(
span
),
is
(
8080
));
assertThat
(
Tags
.
URL
.
get
(
span
),
is
(
"http://127.0.0.1:8080/test-web/test"
));
...
...
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerFetchRequestURLInterceptor.java
已删除
100644 → 0
浏览文件 @
507b6b06
package
com.a.eye.skywalking.plugin.motan
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult
;
/**
* {@link MotanConsumerFetchRequestURLInterceptor} record {@link com.weibo.api.motan.rpc.URL} to {@link EnhancedClassInstanceContext#context}
* for the operation name that create span need.
*
* @author zhangxin
*/
public
class
MotanConsumerFetchRequestURLInterceptor
implements
InstanceMethodsAroundInterceptor
{
private
static
final
String
CONTEXT_NAME_OF_REQUEST_URL
=
"REQUEST_URL"
;
/**
* Fetch the request url from the first param of all constructor, and put request
* url into {@link EnhancedClassInstanceContext#context}.
*
* @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance.
* @param interceptorContext method context, includes class name, method name, etc.
* @param result change this result, if you want to truncate the method.
*/
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
context
.
set
(
CONTEXT_NAME_OF_REQUEST_URL
,
interceptorContext
.
allArguments
()[
0
]);
}
@Override
public
Object
afterMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
Object
ret
)
{
return
ret
;
}
@Override
public
void
handleMethodException
(
Throwable
t
,
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
)
{
// do nothing
}
}
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerIn
vokeIn
terceptor.java
→
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerInterceptor.java
浏览文件 @
aa10ce79
...
...
@@ -3,6 +3,8 @@ package com.a.eye.skywalking.plugin.motan;
import
com.a.eye.skywalking.api.context.ContextCarrier
;
import
com.a.eye.skywalking.api.context.ContextManager
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult
;
...
...
@@ -12,38 +14,41 @@ import com.weibo.api.motan.rpc.Request;
import
com.weibo.api.motan.rpc.Response
;
import
com.weibo.api.motan.rpc.URL
;
/**
* {@link Motan
ConsumerInvoke
Interceptor} create span by fetch request url from
* {@link Motan
Provider
Interceptor} create span by fetch request url from
* {@link EnhancedClassInstanceContext#context} and transport serialized context
* data to provider side through {@link Request#setAttachment(String, String)}.
*
* @author zhangxin
*/
public
class
MotanConsumerIn
vokeInterceptor
implements
InstanceMethodsAroundInterceptor
{
public
class
MotanConsumerIn
terceptor
implements
InstanceConstructorInterceptor
,
InstanceMethodsAroundInterceptor
{
/**
*
Context name of request url in {@link EnhancedClassInstanceContext#context}.
*
The
*/
private
static
final
String
CONTEXT
_NAME_OF_REQUEST_URL
=
"REQUEST_URL"
;
private
static
final
String
KEY
_NAME_OF_REQUEST_URL
=
"REQUEST_URL"
;
/**
*
Attachment key of the serialized context data
.
*
The {@link Request#getAttachments()} key. It maps to the serialized {@link ContextCarrier}
.
*/
private
static
final
String
ATTACHMENT_KEY_OF_CONTEXT_DATA
=
"SWTraceContext"
;
/**
* Motan component
*/
private
static
final
String
MOTAN_COMPONENT
=
"Motan"
;
@Override
public
void
onConstruct
(
EnhancedClassInstanceContext
context
,
ConstructorInvokeContext
interceptorContext
)
{
context
.
set
(
KEY_NAME_OF_REQUEST_URL
,
interceptorContext
.
allArguments
()[
1
]);
}
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
URL
url
=
(
URL
)
context
.
get
(
CONTEXT
_NAME_OF_REQUEST_URL
);
URL
url
=
(
URL
)
context
.
get
(
KEY
_NAME_OF_REQUEST_URL
);
Request
request
=
(
Request
)
interceptorContext
.
allArguments
()[
0
];
if
(
url
!=
null
)
{
Request
request
=
(
Request
)
interceptorContext
.
allArguments
()[
0
];
Span
span
=
ContextManager
.
INSTANCE
.
createSpan
(
generateOperationName
(
url
,
request
));
Tags
.
PEER_HOST
.
set
(
span
,
url
.
getHost
());
Tags
.
PEER_PORT
.
set
(
span
,
url
.
getPort
());
...
...
@@ -64,10 +69,9 @@ public class MotanConsumerInvokeInterceptor implements InstanceMethodsAroundInte
Response
response
=
(
Response
)
ret
;
if
(
response
!=
null
&&
response
.
getException
()
!=
null
)
{
Span
span
=
ContextManager
.
INSTANCE
.
activeSpan
();
span
.
log
(
response
.
getException
());
Tags
.
ERROR
.
set
(
span
,
true
);
span
.
log
(
response
.
getException
());
}
ContextManager
.
INSTANCE
.
stopSpan
();
return
ret
;
}
...
...
@@ -79,6 +83,8 @@ public class MotanConsumerInvokeInterceptor implements InstanceMethodsAroundInte
}
/**
* Generate operation name.
*
...
...
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptor.java
浏览文件 @
aa10ce79
...
...
@@ -3,8 +3,6 @@ package com.a.eye.skywalking.plugin.motan;
import
com.a.eye.skywalking.api.context.ContextCarrier
;
import
com.a.eye.skywalking.api.context.ContextManager
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult
;
...
...
@@ -13,56 +11,40 @@ import com.a.eye.skywalking.trace.Span;
import
com.a.eye.skywalking.trace.tag.Tags
;
import
com.weibo.api.motan.rpc.Request
;
import
com.weibo.api.motan.rpc.Response
;
import
com.weibo.api.motan.rpc.URL
;
/**
* Current trace segment will ref the trace segment
from previous level if the serialized context data
that fetch
* Current trace segment will ref the trace segment
if the serialized trace context
that fetch
* from {@link Request#getAttachments()} is not null.
*
* {@link Motan
Provid
erInterceptor} intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} for record
* {@link Motan
Consum
erInterceptor} intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} for record
* the request url from consumer side.
*
* @author zhangxin
*/
public
class
MotanProviderInterceptor
implements
Instance
ConstructorInterceptor
,
Instance
MethodsAroundInterceptor
{
public
class
MotanProviderInterceptor
implements
InstanceMethodsAroundInterceptor
{
/**
* The
*/
private
static
final
String
KEY_NAME_OF_REQUEST_URL
=
"REQUEST_URL"
;
/**
* The {@link Request#getAttachments()} key. It maps to the serialized {@link ContextCarrier}.
* Attachment key of the serialized context data.
*/
private
static
final
String
ATTACHMENT_KEY_OF_CONTEXT_DATA
=
"SWTraceContext"
;
/**
* Motan component
*/
private
static
final
String
MOTAN_COMPONENT
=
"Motan"
;
@Override
public
void
onConstruct
(
EnhancedClassInstanceContext
context
,
ConstructorInvokeContext
interceptorContext
)
{
context
.
set
(
KEY_NAME_OF_REQUEST_URL
,
interceptorContext
.
allArguments
()[
0
]);
}
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
URL
url
=
(
URL
)
context
.
get
(
KEY_NAME_OF_REQUEST_URL
);
if
(
url
!=
null
)
{
com
.
weibo
.
api
.
motan
.
rpc
.
Request
request
=
(
com
.
weibo
.
api
.
motan
.
rpc
.
Request
)
interceptorContext
.
allArguments
()[
0
];
Span
span
=
ContextManager
.
INSTANCE
.
createSpan
(
generateViewPoint
(
request
));
Tags
.
COMPONENT
.
set
(
span
,
MOTAN_COMPONENT
);
Tags
.
URL
.
set
(
span
,
url
.
getIdentity
());
Tags
.
PEER_PORT
.
set
(
span
,
url
.
getPort
());
Tags
.
PEER_HOST
.
set
(
span
,
url
.
getHost
());
Tags
.
SPAN_KIND
.
set
(
span
,
Tags
.
SPAN_KIND_SERVER
);
Tags
.
SPAN_LAYER
.
asRPCFramework
(
span
);
Request
request
=
(
Request
)
interceptorContext
.
allArguments
()[
0
];
Span
span
=
ContextManager
.
INSTANCE
.
createSpan
(
generateViewPoint
(
request
));
Tags
.
COMPONENT
.
set
(
span
,
MOTAN_COMPONENT
);
Tags
.
SPAN_KIND
.
set
(
span
,
Tags
.
SPAN_KIND_SERVER
);
Tags
.
SPAN_LAYER
.
asRPCFramework
(
span
);
String
serializedContextData
=
request
.
getAttachments
().
get
(
ATTACHMENT_KEY_OF_CONTEXT_DATA
);
if
(!
StringUtil
.
isEmpty
(
serializedContextData
))
{
ContextManager
.
INSTANCE
.
extract
(
new
ContextCarrier
().
deserialize
(
serializedContextData
));
}
String
serializedContextData
=
request
.
getAttachments
().
get
(
ATTACHMENT_KEY_OF_CONTEXT_DATA
);
if
(!
StringUtil
.
isEmpty
(
serializedContextData
))
{
ContextManager
.
INSTANCE
.
extract
(
new
ContextCarrier
().
deserialize
(
serializedContextData
));
}
}
...
...
@@ -72,9 +54,10 @@ public class MotanProviderInterceptor implements InstanceConstructorInterceptor,
Response
response
=
(
Response
)
ret
;
if
(
response
!=
null
&&
response
.
getException
()
!=
null
)
{
Span
span
=
ContextManager
.
INSTANCE
.
activeSpan
();
Tags
.
ERROR
.
set
(
span
,
true
);
span
.
log
(
response
.
getException
());
Tags
.
ERROR
.
set
(
span
,
true
);
}
ContextManager
.
INSTANCE
.
stopSpan
();
return
ret
;
}
...
...
@@ -92,5 +75,4 @@ public class MotanProviderInterceptor implements InstanceConstructorInterceptor,
viewPoint
.
append
(
"("
+
request
.
getParamtersDesc
()
+
")"
);
return
viewPoint
.
toString
();
}
}
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanConsumerInstrumentation.java
浏览文件 @
aa10ce79
...
...
@@ -3,8 +3,7 @@ package com.a.eye.skywalking.plugin.motan.define;
import
com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint
;
import
com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
com.a.eye.skywalking.plugin.motan.MotanConsumerFetchRequestURLInterceptor
;
import
com.a.eye.skywalking.plugin.motan.MotanConsumerInvokeInterceptor
;
import
com.a.eye.skywalking.plugin.motan.MotanProviderInterceptor
;
import
com.weibo.api.motan.rpc.Request
;
import
com.weibo.api.motan.rpc.URL
;
...
...
@@ -15,19 +14,17 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link MotanConsumerInstrumentation} presents that skywalking intercept
* {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} by using {@link MotanConsumerInvokeInterceptor} and
* intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#setUrl(URL)} by using
* {@link MotanConsumerFetchRequestURLInterceptor} to intercept{@link MotanConsumerFetchRequestURLInterceptor}.
* {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} by using {@link MotanProviderInterceptor}.
*
* @author zhangxin
*/
public
class
MotanConsumerInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"com.weibo.api.motan.
cluster.support.ClusterSpi
"
;
private
static
final
String
ENHANCE_CLASS
=
"com.weibo.api.motan.
transport.ProviderMessageRouter
"
;
private
static
final
String
FETCH_REQUEST_URL_INTERCEPT_CLASS
=
"com.a.eye.skywalking.plugin.motan.MotanConsumerFetchRequestURLInterceptor"
;
//
private static final String FETCH_REQUEST_URL_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.MotanConsumerFetchRequestURLInterceptor";
private
static
final
String
INVOKE_INTERCEPT_CLASS
=
"com.a.eye.skywalking.plugin.motan.Motan
ConsumerInvoke
Interceptor"
;
private
static
final
String
INVOKE_INTERCEPT_CLASS
=
"com.a.eye.skywalking.plugin.motan.Motan
Provider
Interceptor"
;
@Override
protected
String
enhanceClassName
()
{
...
...
@@ -42,16 +39,6 @@ public class MotanConsumerInstrumentation extends ClassInstanceMethodsEnhancePlu
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"setUrl"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
FETCH_REQUEST_URL_INTERCEPT_CLASS
;
}
},
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"call"
);
...
...
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanProviderInstrumentation.java
浏览文件 @
aa10ce79
...
...
@@ -3,7 +3,7 @@ package com.a.eye.skywalking.plugin.motan.define;
import
com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint
;
import
com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
com.a.eye.skywalking.plugin.motan.Motan
Provid
erInterceptor
;
import
com.a.eye.skywalking.plugin.motan.Motan
Consum
erInterceptor
;
import
com.weibo.api.motan.rpc.Request
;
import
net.bytebuddy.description.method.MethodDescription
;
...
...
@@ -14,7 +14,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link MotanProviderInstrumentation} presents that skywalking will use
* {@link Motan
Provid
erInterceptor} to intercept
* {@link Motan
Consum
erInterceptor} to intercept
* all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and
* {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}.
*
...
...
@@ -25,15 +25,15 @@ public class MotanProviderInstrumentation extends ClassInstanceMethodsEnhancePlu
/**
* Enhance class.
*/
private
static
final
String
ENHANCE_CLASS
=
"com.weibo.api.motan.rpc.Abstract
Provid
er"
;
private
static
final
String
ENHANCE_CLASS
=
"com.weibo.api.motan.rpc.Abstract
Refer
er"
;
/**
* Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider}.
*/
private
static
final
String
CONSTRUCTOR_INTERCEPT_CLASS
=
"com.a.eye.skywalking.plugin.motan.Motan
Provid
erInterceptor"
;
private
static
final
String
CONSTRUCTOR_INTERCEPT_CLASS
=
"com.a.eye.skywalking.plugin.motan.Motan
Consum
erInterceptor"
;
/**
* Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}.
*/
private
static
final
String
PROVIDER_INVOKE_INTERCEPT_CLASS
=
"com.a.eye.skywalking.plugin.motan.Motan
Provid
erInterceptor"
;
private
static
final
String
PROVIDER_INVOKE_INTERCEPT_CLASS
=
"com.a.eye.skywalking.plugin.motan.Motan
Consum
erInterceptor"
;
@Override
protected
String
enhanceClassName
()
{
...
...
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanConsumerFetchRequestURLInterceptorTest.java
已删除
100644 → 0
浏览文件 @
507b6b06
package
com.a.eye.skywalking.plugin.motan
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.weibo.api.motan.rpc.URL
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Matchers
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
MotanConsumerFetchRequestURLInterceptorTest
{
private
MotanConsumerFetchRequestURLInterceptor
requestURLInterceptor
;
@Mock
private
EnhancedClassInstanceContext
instanceContext
;
@Mock
private
InstanceMethodInvokeContext
interceptorContext
;
private
URL
url
;
@Before
public
void
setUp
()
{
requestURLInterceptor
=
new
MotanConsumerFetchRequestURLInterceptor
();
url
=
URL
.
valueOf
(
"motan://127.0.0.0.1:34000/com.a.eye.skywalking.test.TestService"
);
when
(
interceptorContext
.
allArguments
()).
thenReturn
(
new
Object
[]{
url
});
}
@Test
public
void
testFetchRequestURL
()
{
requestURLInterceptor
.
beforeMethod
(
instanceContext
,
interceptorContext
,
null
);
requestURLInterceptor
.
afterMethod
(
instanceContext
,
interceptorContext
,
null
);
verify
(
instanceContext
,
times
(
1
)).
set
(
Matchers
.
any
(),
Matchers
.
any
());
}
@Test
public
void
testFetchRequestURLWithException
(){
requestURLInterceptor
.
beforeMethod
(
instanceContext
,
interceptorContext
,
null
);
requestURLInterceptor
.
handleMethodException
(
new
RuntimeException
(),
instanceContext
,
interceptorContext
);
requestURLInterceptor
.
afterMethod
(
instanceContext
,
interceptorContext
,
null
);
verify
(
instanceContext
,
times
(
1
)).
set
(
Matchers
.
any
(),
Matchers
.
any
());
}
}
\ No newline at end of file
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanConsumerIn
vokeIn
terceptorTest.java
→
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanConsumerInterceptorTest.java
浏览文件 @
aa10ce79
...
...
@@ -3,6 +3,7 @@ package com.a.eye.skywalking.plugin.motan;
import
com.a.eye.skywalking.api.context.TracerContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.a.eye.skywalking.plugin.motan.define.MotanConsumerInstrumentation
;
import
com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener
;
import
com.a.eye.skywalking.sniffer.mock.context.SegmentAssert
;
import
com.a.eye.skywalking.trace.LogData
;
...
...
@@ -32,11 +33,11 @@ import static org.mockito.Mockito.verify;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
MotanConsumerIn
vokeIn
terceptorTest
{
public
class
MotanConsumerInterceptorTest
{
private
MockTracerContextListener
contextListener
;
private
MotanConsumerIn
vokeIn
terceptor
invokeInterceptor
;
private
MotanConsumerInterceptor
invokeInterceptor
;
@Mock
private
EnhancedClassInstanceContext
instanceContext
;
@Mock
...
...
@@ -51,7 +52,7 @@ public class MotanConsumerInvokeInterceptorTest {
@Before
public
void
setUp
()
{
contextListener
=
new
MockTracerContextListener
();
invokeInterceptor
=
new
MotanConsumerIn
vokeIn
terceptor
();
invokeInterceptor
=
new
MotanConsumerInterceptor
();
url
=
URL
.
valueOf
(
"motan://127.0.0.1:34000/com.a.eye.skywalking.test.TestService"
);
TracerContext
.
ListenerManager
.
add
(
contextListener
);
...
...
skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptorTest.java
浏览文件 @
aa10ce79
...
...
@@ -71,12 +71,6 @@ public class MotanProviderInterceptorTest {
when
(
constructorInvokeContext
.
allArguments
()).
thenReturn
(
new
Object
[]{
url
});
}
@Test
public
void
testFetchRequestURL
()
{
invokeInterceptor
.
onConstruct
(
instanceContext
,
constructorInvokeContext
);
verify
(
instanceContext
,
times
(
1
)).
set
(
Matchers
.
any
(),
Matchers
.
any
());
}
@Test
public
void
testInvokerWithoutRefSegment
()
{
invokeInterceptor
.
beforeMethod
(
instanceContext
,
interceptorContext
,
null
);
...
...
@@ -170,10 +164,7 @@ public class MotanProviderInterceptorTest {
assertThat
(
span
.
getOperationName
(),
is
(
"com.a.eye.skywalking.test.TestService.test(java.lang.String, java.lang.Object)"
));
assertThat
(
Tags
.
COMPONENT
.
get
(
span
),
is
(
"Motan"
));
assertThat
(
Tags
.
SPAN_KIND
.
get
(
span
),
is
(
Tags
.
SPAN_KIND_SERVER
));
assertThat
(
Tags
.
PEER_HOST
.
get
(
span
),
is
(
"127.0.0.1"
));
assertThat
(
Tags
.
PEER_PORT
.
get
(
span
),
is
(
34000
));
assertTrue
(
Tags
.
SPAN_LAYER
.
isRPCFramework
(
span
));
assertThat
(
Tags
.
URL
.
get
(
span
),
is
(
"motan://127.0.0.1:34000/default_rpc/com.a.eye.skywalking.test.TestService/1.0/service"
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录