Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gdyjdao
SkyWalking
提交
8612f802
S
SkyWalking
项目概览
gdyjdao
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
1
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,发现更多精彩内容 >>
提交
8612f802
编写于
4月 12, 2018
作者:
C
carlvine500
提交者:
wu-sheng
4月 12, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add jdk-cross-thread-plugin (#845)
* add jdk-cross-thread-plugin
上级
5ea5471c
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
437 addition
and
0 deletion
+437
-0
apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/CallableWrapper.java
.../apache/skywalking/apm/toolkit/trace/CallableWrapper.java
+41
-0
apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/TraceCrossThread.java
...apache/skywalking/apm/toolkit/trace/TraceCrossThread.java
+32
-0
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
...che/skywalking/apm/agent/core/context/ContextManager.java
+1
-0
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/pom.xml
+59
-0
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableConstructInterceptor.java
...in/jdk/thread/CallableOrRunnableConstructInterceptor.java
+35
-0
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInvokeInterceptor.java
...lugin/jdk/thread/CallableOrRunnableInvokeInterceptor.java
+54
-0
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/define/CallableOrRunnableInstrumentation.java
.../jdk/thread/define/CallableOrRunnableInstrumentation.java
+85
-0
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/resources/skywalking-plugin.def
...ss-thread-plugin/src/main/resources/skywalking-plugin.def
+17
-0
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInterceptorTest.java
.../plugin/jdk/thread/CallableOrRunnableInterceptorTest.java
+112
-0
apm-sniffer/apm-sdk-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/pom.xml
+1
-0
未找到文件。
apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/CallableWrapper.java
0 → 100644
浏览文件 @
8612f802
/*
* 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.toolkit.trace
;
import
java.util.concurrent.Callable
;
/**
* @author carlvine500
*/
@TraceCrossThread
public
class
CallableWrapper
<
V
>
implements
Callable
<
V
>
{
final
Callable
<
V
>
callable
;
public
static
<
V
>
CallableWrapper
of
(
Callable
<
V
>
r
)
{
return
new
CallableWrapper
<
V
>(
r
);
}
public
CallableWrapper
(
Callable
<
V
>
callable
)
{
this
.
callable
=
callable
;
}
@Override
public
V
call
()
throws
Exception
{
return
callable
.
call
();
}
}
\ No newline at end of file
apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/TraceCrossThread.java
0 → 100644
浏览文件 @
8612f802
/*
* 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.toolkit.trace
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* @author carlvine500
*/
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
TraceCrossThread
{
}
\ No newline at end of file
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
浏览文件 @
8612f802
...
...
@@ -204,4 +204,5 @@ public class ContextManager implements TracingContextListener, BootService, Igno
public
static
boolean
isActive
()
{
return
CONTEXT
.
get
()
!=
null
;
}
}
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/pom.xml
0 → 100644
浏览文件 @
8612f802
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017, OpenSkywalking Organization All rights reserved.
~
~ Licensed 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.
~
~ Project repository: https://github.com/OpenSkywalking/skywalking
-->
<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>
apm-sdk-plugin
</artifactId>
<groupId>
org.apache.skywalking
</groupId>
<version>
5.0.0-beta-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apm-jdk-cross-thread-plugin
</artifactId>
<name>
jdk-cross-thread-plugin
</name>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-deploy-plugin
</artifactId>
</plugin>
<plugin>
<!-- 源码插件 -->
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<!-- 发布时自动将源码同时发布的配置 -->
<executions>
<execution>
<id>
attach-sources
</id>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableConstructInterceptor.java
0 → 100644
浏览文件 @
8612f802
/*
* 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.jdk.thread
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
/**
* @author carlvine500
*/
public
class
CallableOrRunnableConstructInterceptor
implements
InstanceConstructorInterceptor
{
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
if
(
ContextManager
.
isActive
())
{
objInst
.
setSkyWalkingDynamicField
(
ContextManager
.
capture
());
}
}
}
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInvokeInterceptor.java
0 → 100644
浏览文件 @
8612f802
/*
* 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.jdk.thread
;
import
java.lang.reflect.Method
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.context.ContextSnapshot
;
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
;
/**
* @author carlvine500
*/
public
class
CallableOrRunnableInvokeInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
ContextManager
.
createLocalSpan
(
"Thread/"
+
objInst
.
getClass
().
getName
()
+
"/"
+
method
.
getName
());
ContextSnapshot
cachedObjects
=
(
ContextSnapshot
)
objInst
.
getSkyWalkingDynamicField
();
if
(
cachedObjects
!=
null
)
{
ContextManager
.
continued
(
cachedObjects
);
}
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
ContextManager
.
stopSpan
();
// clear ContextSnapshot
objInst
.
setSkyWalkingDynamicField
(
null
);
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
ContextManager
.
activeSpan
().
errorOccurred
().
log
(
t
);
}
}
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/define/CallableOrRunnableInstrumentation.java
0 → 100644
浏览文件 @
8612f802
/*
* 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.jdk.thread.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
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
takesArguments
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
ClassAnnotationMatch
.
byClassAnnotationMatch
;
/**
* {@link CallableOrRunnableInstrumentation} presents that skywalking intercepts all Class with annotation
* "org.skywalking.apm.toolkit.trace.TraceCrossThread" and method named "call" or "run".
*
* @author carlvine500
*/
public
class
CallableOrRunnableInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
public
static
final
String
ANNOTATION_NAME
=
"org.apache.skywalking.apm.toolkit.trace.TraceCrossThread"
;
private
static
final
String
INIT_METHOD_INTERCEPTOR
=
"org.apache.skywalking.apm.plugin.jdk.thread.CallableOrRunnableConstructInterceptor"
;
private
static
final
String
CALL_METHOD_INTERCEPTOR
=
"org.apache.skywalking.apm.plugin.jdk.thread.CallableOrRunnableInvokeInterceptor"
;
private
static
final
String
CALL_METHOD_NAME
=
"call"
;
private
static
final
String
RUN_METHOD_NAME
=
"run"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
any
();
}
@Override
public
String
getConstructorInterceptor
()
{
return
INIT_METHOD_INTERCEPTOR
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
(
named
(
CALL_METHOD_NAME
).
and
(
takesArguments
(
0
)))
.
or
(
named
(
RUN_METHOD_NAME
).
and
(
takesArguments
(
0
)));
}
@Override
public
String
getMethodsInterceptor
()
{
return
CALL_METHOD_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
@Override
protected
ClassMatch
enhanceClass
()
{
return
byClassAnnotationMatch
(
new
String
[]
{
ANNOTATION_NAME
});
}
}
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
8612f802
# 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.
jdk-cross-thread=org.apache.skywalking.apm.plugin.jdk.thread.define.CallableOrRunnableInstrumentation
apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInterceptorTest.java
0 → 100644
浏览文件 @
8612f802
/*
* 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.jdk.thread
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
java.util.concurrent.Callable
;
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.modules.junit4.PowerMockRunner
;
import
org.powermock.modules.junit4.PowerMockRunnerDelegate
;
import
org.apache.skywalking.apm.agent.core.context.ContextSnapshot
;
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.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.test.helper.SegmentHelper
;
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
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
CallableOrRunnableInterceptorTest
{
private
CallableOrRunnableConstructInterceptor
constructorInterceptor
;
private
CallableOrRunnableInvokeInterceptor
callableCallInterceptor
;
@Rule
public
AgentServiceRule
serviceRule
=
new
AgentServiceRule
();
@SegmentStoragePoint
private
SegmentStorage
segmentStorage
;
private
EnhancedInstance
enhancedInstance
=
new
EnhancedInstance
()
{
private
Object
object
;
@Override
public
Object
getSkyWalkingDynamicField
()
{
return
object
;
}
@Override
public
void
setSkyWalkingDynamicField
(
Object
value
)
{
this
.
object
=
value
;
}
};
@Mock
private
ContextSnapshot
contextSnapshot
;
private
Object
[]
arguments
;
private
Method
callMethod
;
@Before
public
void
setUp
()
throws
NoSuchMethodException
{
constructorInterceptor
=
new
CallableOrRunnableConstructInterceptor
();
callableCallInterceptor
=
new
CallableOrRunnableInvokeInterceptor
();
Callable
<
String
>
call
=
new
Callable
<
String
>()
{
@Override
public
String
call
()
throws
Exception
{
return
null
;
}
};
callMethod
=
call
.
getClass
().
getMethod
(
"call"
);
arguments
=
new
Object
[
0
];
}
@Test
public
void
testOnConstructor
()
{
constructorInterceptor
.
onConstruct
(
enhancedInstance
,
null
);
Assert
.
assertNull
(
enhancedInstance
.
getSkyWalkingDynamicField
());
}
@Test
public
void
testCall
()
throws
Throwable
{
enhancedInstance
.
setSkyWalkingDynamicField
(
contextSnapshot
);
callableCallInterceptor
.
beforeMethod
(
enhancedInstance
,
callMethod
,
arguments
,
null
,
null
);
callableCallInterceptor
.
afterMethod
(
enhancedInstance
,
callMethod
,
arguments
,
null
,
"result"
);
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
traceSegment
);
assertThat
(
spans
.
size
(),
is
(
1
));
}
}
apm-sniffer/apm-sdk-plugin/pom.xml
浏览文件 @
8612f802
...
...
@@ -56,6 +56,7 @@
<module>
kafka-v1-plugin
</module>
<module>
servicecomb-plugin
</module>
<module>
hystrix-1.x-plugin
</module>
<module>
jdk-cross-thread-plugin
</module>
</modules>
<packaging>
pom
</packaging>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录