Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
dbee9531
S
SkyWalking
项目概览
月轩居士
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
4
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,发现更多精彩内容 >>
提交
dbee9531
编写于
2月 24, 2018
作者:
L
lytscu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add [Agent] V1 servicecomb plugin
上级
84358710
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
653 addition
and
0 deletion
+653
-0
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml
+1
-0
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/pom.xml
...cecomb-plugin/servicecomb-java-chassis-1.x-plugin/pom.xml
+57
-0
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptor.java
...n/servicecomb/v1/ProducerOperationHandlerInterceptor.java
+80
-0
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptor.java
...gin/servicecomb/v1/TransportClientHandlerInterceptor.java
+104
-0
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/ProducerOperationHandlerInstrumentation.java
...mb/v1/define/ProducerOperationHandlerInstrumentation.java
+74
-0
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/TransportClientHandlerInstrumentation.java
...comb/v1/define/TransportClientHandlerInstrumentation.java
+74
-0
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/resources/skywalking-plugin.def
...assis-1.x-plugin/src/main/resources/skywalking-plugin.def
+2
-0
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptorTest.java
...rvicecomb/v1/ProducerOperationHandlerInterceptorTest.java
+133
-0
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptorTest.java
...servicecomb/v1/TransportClientHandlerInterceptorTest.java
+128
-0
未找到文件。
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/pom.xml
浏览文件 @
dbee9531
...
...
@@ -13,6 +13,7 @@
<modules>
<module>
servicecomb-java-chassis-0.x-plugin
</module>
<module>
servicecomb-java-chassis-1.x-plugin
</module>
</modules>
<packaging>
pom
</packaging>
...
...
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/pom.xml
0 → 100644
浏览文件 @
dbee9531
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
servicecomb-plugin
</artifactId>
<groupId>
org.apache.skywalking
</groupId>
<version>
5.0.0-alpha
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apm-servicecomb-java-chassis-1.x-plugin
</artifactId>
<packaging>
jar
</packaging>
<name>
servicecomb-java-chassis-1.x-plugin
</name>
<url>
http://maven.apache.org
</url>
<dependencies>
<dependency>
<groupId>
org.apache.servicecomb
</groupId>
<artifactId>
java-chassis-core
</artifactId>
<version>
1.0.0-m1-SNAPSHOT
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>
apache-servicecomb
</id>
<url>
https://repository.apache.org/content/repositories/snapshots/org/apache/servicecomb/java-chassis-core/1.0.0-m1-SNAPSHOT/
</url>
<snapshots>
<enabled>
true
</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<!-- 源码插件 -->
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<!-- 发布时自动将源码同时发布的配置 -->
<executions>
<execution>
<id>
attach-sources
</id>
<phase>
none
</phase>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptor.java
0 → 100644
浏览文件 @
dbee9531
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org.apache.skywalking.apm.plugin.servicecomb.v1
;
import
java.lang.reflect.Method
;
import
org.apache.servicecomb.core.Invocation
;
import
org.apache.skywalking.apm.agent.core.context.CarrierItem
;
import
org.apache.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.context.tag.Tags
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.apache.skywalking.apm.agent.core.context.trace.SpanLayer
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.apache.skywalking.apm.network.trace.component.ComponentsDefine
;
/**
* {ProducerOperationHandlerInterceptor} define how to enhance class {@link
* ProducerOperationHandler#handle(org.apache.servicecomb.core.Invocation, org.apache.servicecomb.swagger.invocation.AsyncResponse)}.
*
* @author lytscu
*/
public
class
ProducerOperationHandlerInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
Invocation
invocation
=
(
Invocation
)
allArguments
[
0
];
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
CarrierItem
next
=
contextCarrier
.
items
();
while
(
next
.
hasNext
())
{
next
=
next
.
next
();
next
.
setHeadValue
(
invocation
.
getContext
().
get
(
next
.
getHeadKey
()));
}
String
operationName
=
invocation
.
getMicroserviceQualifiedName
();
AbstractSpan
span
=
ContextManager
.
createEntrySpan
(
operationName
,
contextCarrier
);
String
url
=
invocation
.
getOperationMeta
().
getOperationPath
();
Tags
.
URL
.
set
(
span
,
url
);
span
.
setComponent
(
ComponentsDefine
.
SERVICECOMB
);
SpanLayer
.
asRPCFramework
(
span
);
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
Invocation
invocation
=
(
Invocation
)
allArguments
[
0
];
AbstractSpan
span
=
ContextManager
.
activeSpan
();
int
statusCode
=
invocation
.
getStatus
().
getStatusCode
();
if
(
statusCode
>=
400
)
{
span
.
errorOccurred
();
Tags
.
STATUS_CODE
.
set
(
span
,
Integer
.
toString
(
statusCode
));
}
ContextManager
.
stopSpan
();
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
AbstractSpan
span
=
ContextManager
.
activeSpan
();
span
.
errorOccurred
();
span
.
log
(
t
);
}
}
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptor.java
0 → 100644
浏览文件 @
dbee9531
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org.apache.skywalking.apm.plugin.servicecomb.v1
;
import
java.lang.reflect.Method
;
import
java.net.URI
;
import
org.apache.servicecomb.core.Invocation
;
import
org.apache.skywalking.apm.agent.core.context.CarrierItem
;
import
org.apache.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.context.tag.Tags
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.apache.skywalking.apm.agent.core.context.trace.SpanLayer
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.apache.skywalking.apm.network.trace.component.ComponentsDefine
;
/**
* {@link TransportClientHandlerInterceptor} define how to enhance class {@link TransportClientHandler#handle(org.apache.servicecomb.core.Invocation,
* org.apache.servicecomb.swagger.invocation.AsyncResponse)}.
*
* @author lytscu
*/
public
class
TransportClientHandlerInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
Invocation
invocation
=
(
Invocation
)
allArguments
[
0
];
if
(!
checkRegisterStatus
(
invocation
))
{
return
;
}
URI
uri
=
new
URI
(
invocation
.
getEndpoint
().
toString
());
String
peer
=
uri
.
getHost
()
+
":"
+
uri
.
getPort
();
String
operationName
=
invocation
.
getMicroserviceQualifiedName
();
final
ContextCarrier
contextCarrier
=
new
ContextCarrier
();
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
operationName
,
contextCarrier
,
peer
);
CarrierItem
next
=
contextCarrier
.
items
();
while
(
next
.
hasNext
())
{
next
=
next
.
next
();
invocation
.
getContext
().
put
(
next
.
getHeadKey
(),
next
.
getHeadValue
());
}
String
url
=
invocation
.
getOperationMeta
().
getOperationPath
();
Tags
.
URL
.
set
(
span
,
url
);
span
.
setComponent
(
ComponentsDefine
.
SERVICECOMB
);
SpanLayer
.
asRPCFramework
(
span
);
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
Invocation
invocation
=
(
Invocation
)
allArguments
[
0
];
if
(!
checkRegisterStatus
(
invocation
))
{
return
ret
;
}
AbstractSpan
span
=
ContextManager
.
activeSpan
();
int
statusCode
=
invocation
.
getStatus
().
getStatusCode
();
if
(
statusCode
>=
400
)
{
span
.
errorOccurred
();
Tags
.
STATUS_CODE
.
set
(
span
,
Integer
.
toString
(
statusCode
));
}
ContextManager
.
stopSpan
();
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
Invocation
invocation
=
(
Invocation
)
allArguments
[
0
];
if
(!
checkRegisterStatus
(
invocation
))
{
return
;
}
AbstractSpan
span
=
ContextManager
.
activeSpan
();
span
.
errorOccurred
();
span
.
log
(
t
);
}
/**
* Serviecomb chassis Consumers and providers need to register at the service center. If the consumer is not
* registered then return false.
*/
private
Boolean
checkRegisterStatus
(
Invocation
invocation
)
{
if
(
null
==
invocation
.
getOperationMeta
()
||
null
==
invocation
.
getEndpoint
())
{
return
false
;
}
return
true
;
}
}
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/ProducerOperationHandlerInstrumentation.java
0 → 100644
浏览文件 @
dbee9531
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org.apache.skywalking.apm.plugin.servicecomb.v1.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
org.apache.skywalking.apm.agent.core.plugin.match.NameMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* {@link ProducerOperationHandlerInstrumentation} represents that skywalking intercept {@link
* ProducerOperationHandler#handle(org.apache.servicecomb.core.Invocation, org.apache.servicecomb.swagger.invocation.AsyncResponse)}by
* using {@link ProducerOperationHandlerInterceptor}
*
* @author lytscu
*/
public
class
ProducerOperationHandlerInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.apache.servicecomb.core.handler.impl.ProducerOperationHandler"
;
private
static
final
String
INTERCEPT_CLASS
=
"org.apache.skywalking.apm.plugin.servicecomb.v1.ProducerOperationHandlerInterceptor"
;
@Override
protected
ClassMatch
enhanceClass
()
{
return
NameMatch
.
byName
(
ENHANCE_CLASS
);
}
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[
0
];
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"handle"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
INTERCEPT_CLASS
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
}
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/servicecomb/v1/define/TransportClientHandlerInstrumentation.java
0 → 100644
浏览文件 @
dbee9531
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org.apache.skywalking.apm.plugin.servicecomb.v1.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
import
org.apache.servicecomb.core.handler.impl.TransportClientHandler
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
org.apache.skywalking.apm.agent.core.plugin.match.NameMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
/**
* {@link TransportClientHandlerInstrumentation} represents that skywalking intercept {@link TransportClientHandler}by
* using {@linkTransportClientHandlerInterceptor }
*
* @author lytscu
*/
public
class
TransportClientHandlerInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.apache.servicecomb.core.handler.impl.TransportClientHandler"
;
private
static
final
String
INTERCEPT_CLASS
=
"org.apache.skywalking.apm.plugin.servicecomb.v1.TransportClientHandlerInterceptor"
;
@Override
protected
ClassMatch
enhanceClass
()
{
return
NameMatch
.
byName
(
ENHANCE_CLASS
);
}
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[
0
];
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"handle"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
INTERCEPT_CLASS
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
},
};
}
}
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
dbee9531
servicecomb-1.x=org.apache.skywalking.apm.plugin.servicecomb.v1.define.ProducerOperationHandlerInstrumentation
servicecomb-1.x=org.apache.skywalking.apm.plugin.servicecomb.v1.define.TransportClientHandlerInstrumentation
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/ProducerOperationHandlerInterceptorTest.java
0 → 100644
浏览文件 @
dbee9531
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org.apache.skywalking.apm.plugin.servicecomb.v1
;
import
org.apache.servicecomb.core.Endpoint
;
import
org.apache.servicecomb.core.Invocation
;
import
org.apache.servicecomb.core.definition.OperationMeta
;
import
org.apache.servicecomb.core.definition.SchemaMeta
;
import
org.apache.servicecomb.swagger.invocation.InvocationType
;
import
org.apache.servicecomb.swagger.invocation.SwaggerInvocation
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
javax.ws.rs.core.Response
;
import
org.apache.skywalking.apm.agent.core.boot.ServiceManager
;
import
org.apache.skywalking.apm.agent.core.conf.Config
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan
;
import
org.apache.skywalking.apm.agent.core.context.trace.TraceSegment
;
import
org.apache.skywalking.apm.agent.core.context.util.KeyValuePair
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.test.helper.SegmentHelper
;
import
org.apache.skywalking.apm.agent.test.helper.SpanHelper
;
import
org.apache.skywalking.apm.agent.test.tools.AgentServiceRule
;
import
org.apache.skywalking.apm.agent.test.tools.SegmentStorage
;
import
org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint
;
import
org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
org.powermock.modules.junit4.PowerMockRunnerDelegate
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
ProducerOperationHandlerInterceptorTest
{
@Rule
public
AgentServiceRule
agentServiceRule
=
new
AgentServiceRule
();
@Mock
Response
.
StatusType
statusType
;
@SegmentStoragePoint
private
SegmentStorage
segmentStorage
;
private
ProducerOperationHandlerInterceptor
invocationInterceptor
;
@Mock
private
OperationMeta
operationMeta
;
@Mock
private
EnhancedInstance
enhancedInstance
;
@Mock
private
Invocation
invocation
;
@Mock
private
Endpoint
endpoint
;
@Mock
private
Method
method
;
@Mock
private
SwaggerInvocation
swagger
;
private
Object
[]
allArguments
;
private
Class
[]
argumentsType
;
private
Object
[]
swaggerArguments
;
@Mock
private
SchemaMeta
schemaMeta
;
@Before
public
void
setUp
()
throws
Exception
{
ServiceManager
.
INSTANCE
.
boot
();
invocationInterceptor
=
new
ProducerOperationHandlerInterceptor
();
PowerMockito
.
mock
(
Invocation
.
class
);
when
(
operationMeta
.
getSchemaMeta
()).
thenReturn
(
schemaMeta
);
when
(
endpoint
.
getAddress
()).
thenReturn
(
"0.0.0.0:7777"
);
when
(
invocation
.
getEndpoint
()).
thenReturn
(
endpoint
);
when
(
invocation
.
getMicroserviceQualifiedName
()).
thenReturn
(
"productorTest"
);
when
(
operationMeta
.
getOperationPath
()).
thenReturn
(
"/bmi"
);
when
(
invocation
.
getOperationMeta
()).
thenReturn
(
operationMeta
);
when
(
invocation
.
getStatus
()).
thenReturn
(
statusType
);
when
(
statusType
.
getStatusCode
()).
thenReturn
(
200
);
when
(
method
.
getName
()).
thenReturn
(
"producer"
);
when
(
invocation
.
getInvocationType
()).
thenReturn
(
InvocationType
.
PRODUCER
);
Config
.
Agent
.
APPLICATION_CODE
=
"serviceComnTestCases-APP"
;
allArguments
=
new
Object
[]
{
invocation
,};
argumentsType
=
new
Class
[]
{};
swaggerArguments
=
new
Class
[]
{};
}
@Test
public
void
testConsumer
()
throws
Throwable
{
invocationInterceptor
.
beforeMethod
(
enhancedInstance
,
method
,
allArguments
,
argumentsType
,
null
);
invocationInterceptor
.
afterMethod
(
enhancedInstance
,
method
,
allArguments
,
argumentsType
,
null
);
Assert
.
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
traceSegment
);
assertCombSpan
(
spans
.
get
(
0
));
verify
(
invocation
,
times
(
1
)).
getContext
();
}
private
void
assertCombSpan
(
AbstractTracingSpan
span
)
{
assertThat
(
span
.
getOperationName
(),
is
(
"productorTest"
));
assertThat
(
SpanHelper
.
getComponentId
(
span
),
is
(
28
));
List
<
KeyValuePair
>
tags
=
SpanHelper
.
getTags
(
span
);
assertThat
(
tags
.
get
(
0
).
getValue
(),
is
(
"/bmi"
));
assertThat
(
span
.
isEntry
(),
is
(
true
));
}
}
apm-sniffer/apm-sdk-plugin/servicecomb-plugin/servicecomb-java-chassis-1.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/servicecomb/v1/TransportClientHandlerInterceptorTest.java
0 → 100644
浏览文件 @
dbee9531
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
org.apache.skywalking.apm.plugin.servicecomb.v1
;
import
org.apache.servicecomb.core.Endpoint
;
import
org.apache.servicecomb.core.Invocation
;
import
org.apache.servicecomb.core.definition.OperationMeta
;
import
org.apache.servicecomb.core.definition.SchemaMeta
;
import
org.apache.servicecomb.core.provider.consumer.ReferenceConfig
;
import
org.apache.servicecomb.swagger.invocation.InvocationType
;
import
org.apache.servicecomb.swagger.invocation.SwaggerInvocation
;
import
java.util.List
;
import
javax.ws.rs.core.Response
;
import
org.apache.skywalking.apm.agent.core.boot.ServiceManager
;
import
org.apache.skywalking.apm.agent.core.conf.Config
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan
;
import
org.apache.skywalking.apm.agent.core.context.trace.TraceSegment
;
import
org.apache.skywalking.apm.agent.core.context.util.KeyValuePair
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.test.helper.SegmentHelper
;
import
org.apache.skywalking.apm.agent.test.helper.SpanHelper
;
import
org.apache.skywalking.apm.agent.test.tools.AgentServiceRule
;
import
org.apache.skywalking.apm.agent.test.tools.SegmentStorage
;
import
org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint
;
import
org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
org.powermock.modules.junit4.PowerMockRunnerDelegate
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
TransportClientHandlerInterceptorTest
{
@Rule
public
AgentServiceRule
agentServiceRule
=
new
AgentServiceRule
();
@Mock
Response
.
StatusType
statusType
;
@Mock
ReferenceConfig
referenceConfig
;
@SegmentStoragePoint
private
SegmentStorage
segmentStorage
;
private
TransportClientHandlerInterceptor
nextInterceptor
;
@Mock
private
OperationMeta
operationMeta
;
@Mock
private
EnhancedInstance
enhancedInstance
;
@Mock
private
Invocation
invocation
;
@Mock
private
Endpoint
endpoint
;
@Mock
private
SwaggerInvocation
swagger
;
private
Object
[]
allArguments
;
private
Class
[]
argumentsType
;
private
Object
[]
swaggerArguments
;
@Mock
private
SchemaMeta
schemaMeta
;
@Before
public
void
setUp
()
throws
Exception
{
ServiceManager
.
INSTANCE
.
boot
();
nextInterceptor
=
new
TransportClientHandlerInterceptor
();
PowerMockito
.
mock
(
Invocation
.
class
);
when
(
operationMeta
.
getSchemaMeta
()).
thenReturn
(
schemaMeta
);
when
(
endpoint
.
getAddress
()).
thenReturn
(
"0.0.0.0:7777"
);
when
(
invocation
.
getEndpoint
()).
thenReturn
(
endpoint
);
when
(
invocation
.
getMicroserviceQualifiedName
()).
thenReturn
(
"consumerTest"
);
when
(
operationMeta
.
getOperationPath
()).
thenReturn
(
"/bmi"
);
when
(
invocation
.
getOperationMeta
()).
thenReturn
(
operationMeta
);
when
(
invocation
.
getStatus
()).
thenReturn
(
statusType
);
when
(
statusType
.
getStatusCode
()).
thenReturn
(
200
);
when
(
invocation
.
getInvocationType
()).
thenReturn
(
InvocationType
.
CONSUMER
);
Config
.
Agent
.
APPLICATION_CODE
=
"serviceComnTestCases-APP"
;
allArguments
=
new
Object
[]
{
invocation
,};
argumentsType
=
new
Class
[]
{};
swaggerArguments
=
new
Class
[]
{};
}
@Test
public
void
testConsumer
()
throws
Throwable
{
nextInterceptor
.
beforeMethod
(
enhancedInstance
,
null
,
allArguments
,
argumentsType
,
null
);
nextInterceptor
.
afterMethod
(
enhancedInstance
,
null
,
allArguments
,
argumentsType
,
null
);
Assert
.
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
traceSegment
);
assertCombSpan
(
spans
.
get
(
0
));
verify
(
invocation
,
times
(
1
)).
getContext
();
}
private
void
assertCombSpan
(
AbstractTracingSpan
span
)
{
assertThat
(
span
.
getOperationName
(),
is
(
"consumerTest"
));
assertThat
(
SpanHelper
.
getComponentId
(
span
),
is
(
28
));
List
<
KeyValuePair
>
tags
=
SpanHelper
.
getTags
(
span
);
assertThat
(
tags
.
get
(
0
).
getValue
(),
is
(
"/bmi"
));
assertThat
(
span
.
isExit
(),
is
(
true
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录