Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
c15d1a56
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,发现更多精彩内容 >>
提交
c15d1a56
编写于
11月 20, 2017
作者:
G
gaohongtao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #603 Elastic-Job plugin
上级
df97dc34
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
300 addition
and
1 deletion
+300
-1
apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java
...walking/apm/network/trace/component/ComponentsDefine.java
+4
-1
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/pom.xml
+54
-0
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java
...g/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java
+65
-0
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java
...g/apm/plugin/esjob/define/JobExecutorInstrumentation.java
+68
-0
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/resources/skywalking-plugin.def
...c-job-2.x-plugin/src/main/resources/skywalking-plugin.def
+1
-0
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java
...ywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java
+107
-0
apm-sniffer/apm-sdk-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/pom.xml
+1
-0
未找到文件。
apm-network/src/main/java/org/skywalking/apm/network/trace/component/ComponentsDefine.java
浏览文件 @
c15d1a56
...
...
@@ -71,6 +71,8 @@ public class ComponentsDefine {
public
static
final
OfficialComponent
GRPC
=
new
OfficialComponent
(
23
,
"GRPC"
);
public
static
final
OfficialComponent
ELASTIC_JOB
=
new
OfficialComponent
(
24
,
"ElasticJob"
);
private
static
ComponentsDefine
instance
=
new
ComponentsDefine
();
private
String
[]
components
;
...
...
@@ -80,7 +82,7 @@ public class ComponentsDefine {
}
public
ComponentsDefine
()
{
components
=
new
String
[
2
4
];
components
=
new
String
[
2
5
];
addComponent
(
TOMCAT
);
addComponent
(
HTTPCLIENT
);
addComponent
(
DUBBO
);
...
...
@@ -104,6 +106,7 @@ public class ComponentsDefine {
addComponent
(
SHARDING_JDBC
);
addComponent
(
POSTGRESQL
);
addComponent
(
GRPC
);
addComponent
(
ELASTIC_JOB
);
}
private
void
addComponent
(
OfficialComponent
component
)
{
...
...
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/pom.xml
0 → 100644
浏览文件 @
c15d1a56
<?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>
apm-sdk-plugin
</artifactId>
<groupId>
org.skywalking
</groupId>
<version>
3.2.4-2017
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apm-elastic-job-2.x-plugin
</artifactId>
<packaging>
jar
</packaging>
<name>
elastic-job-2.x-plugin
</name>
<url>
http://maven.apache.org
</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
com.dangdang
</groupId>
<artifactId>
elastic-job-common-core
</artifactId>
<version>
[2.0.0,3.0.0)
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
<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>
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptor.java
0 → 100644
浏览文件 @
c15d1a56
/*
* 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
*/
package
org.skywalking.apm.plugin.esjob
;
import
com.dangdang.ddframe.job.api.ShardingContext
;
import
com.dangdang.ddframe.job.executor.ShardingContexts
;
import
com.google.common.base.Strings
;
import
java.lang.reflect.Method
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.skywalking.apm.network.trace.component.ComponentsDefine
;
/**
* {@link JobExecutorInterceptor} enhances {@link com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor#process(ShardingContext)}
* ,creating a local span that records job execution.
*
* @author gaohongtao
*/
public
class
JobExecutorInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
ShardingContexts
shardingContexts
=
(
ShardingContexts
)
allArguments
[
0
];
Integer
item
=
(
Integer
)
allArguments
[
1
];
ShardingContext
shardingContext
=
new
ShardingContext
(
shardingContexts
,
item
);
String
operateName
=
shardingContext
.
getJobName
();
if
(!
Strings
.
isNullOrEmpty
(
shardingContext
.
getShardingParameter
()))
{
operateName
+=
"-"
+
shardingContext
.
getShardingParameter
();
}
AbstractSpan
span
=
ContextManager
.
createLocalSpan
(
operateName
);
span
.
setComponent
(
ComponentsDefine
.
ELASTIC_JOB
);
span
.
tag
(
"sharding_context"
,
shardingContext
.
toString
());
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
ContextManager
.
stopSpan
();
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/elastic-job-2.x-plugin/src/main/java/org/skywalking/apm/plugin/esjob/define/JobExecutorInstrumentation.java
0 → 100644
浏览文件 @
c15d1a56
/*
* 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
*/
package
org.skywalking.apm.plugin.esjob.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
import
org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
bytebuddy
.
ArgumentTypeNameMatch
.
takesArgumentWithType
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* {@link JobExecutorInstrumentation} presents that skywalking intercepts {@link com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor}.
*
* @author gaohongtao
*/
public
class
JobExecutorInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor"
;
private
static
final
String
JOB_EXECUTOR_INTERCEPTOR_CLASS
=
"org.skywalking.apm.plugin.esjob.JobExecutorInterceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[
0
];
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
takesArgumentWithType
(
2
,
"com.dangdang.ddframe.job.event.type.JobExecutionEvent"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
JOB_EXECUTOR_INTERCEPTOR_CLASS
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
@Override
protected
ClassMatch
enhanceClass
()
{
return
byName
(
ENHANCE_CLASS
);
}
}
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
c15d1a56
elastic-job-2.x=org.skywalking.apm.plugin.esjob.define.JobExecutorInstrumentation
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/elastic-job-2.x-plugin/src/test/java/org/skywalking/apm/plugin/esjob/JobExecutorInterceptorTest.java
0 → 100644
浏览文件 @
c15d1a56
/*
* 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
*/
package
org.skywalking.apm.plugin.esjob
;
import
com.dangdang.ddframe.job.executor.ShardingContexts
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
org.powermock.modules.junit4.PowerMockRunnerDelegate
;
import
org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan
;
import
org.skywalking.apm.agent.core.context.trace.TraceSegment
;
import
org.skywalking.apm.agent.test.helper.SegmentHelper
;
import
org.skywalking.apm.agent.test.tools.AgentServiceRule
;
import
org.skywalking.apm.agent.test.tools.SegmentStorage
;
import
org.skywalking.apm.agent.test.tools.SegmentStoragePoint
;
import
org.skywalking.apm.agent.test.tools.TracingSegmentRunner
;
import
static
org
.
hamcrest
.
core
.
Is
.
is
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
JobExecutorInterceptorTest
{
@SegmentStoragePoint
private
SegmentStorage
segmentStorage
;
@Rule
public
AgentServiceRule
serviceRule
=
new
AgentServiceRule
();
private
JobExecutorInterceptor
jobExecutorInterceptor
;
@Before
public
void
setUp
()
throws
SQLException
{
jobExecutorInterceptor
=
new
JobExecutorInterceptor
();
}
@Test
public
void
assertSuccess
()
throws
Throwable
{
jobExecutorInterceptor
.
beforeMethod
(
null
,
null
,
new
Object
[]{
mockShardingContext
(
"fooJob"
,
1
),
1
},
null
,
null
);
jobExecutorInterceptor
.
afterMethod
(
null
,
null
,
null
,
null
,
null
);
TraceSegment
segment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
segment
);
assertNotNull
(
spans
);
assertThat
(
spans
.
size
(),
is
(
1
));
assertThat
(
spans
.
get
(
0
).
transform
().
getOperationName
(),
is
(
"fooJob-test"
));
assertThat
(
spans
.
get
(
0
).
transform
().
getComponentId
(),
is
(
23
));
assertThat
(
spans
.
get
(
0
).
transform
().
getTags
(
0
).
getKey
(),
is
(
"sharding_context"
));
assertThat
(
spans
.
get
(
0
).
transform
().
getTags
(
0
).
getValue
(),
is
(
"ShardingContext(jobName=fooJob, taskId=fooJob1, shardingTotalCount=2, jobParameter=, shardingItem=1, shardingParameter=test)"
));
}
@Test
public
void
assertSuccessWithoutSharding
()
throws
Throwable
{
jobExecutorInterceptor
.
beforeMethod
(
null
,
null
,
new
Object
[]{
mockShardingContext
(
"fooJob"
,
0
),
0
},
null
,
null
);
jobExecutorInterceptor
.
afterMethod
(
null
,
null
,
null
,
null
,
null
);
TraceSegment
segment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
segment
);
assertNotNull
(
spans
);
assertThat
(
spans
.
size
(),
is
(
1
));
assertThat
(
spans
.
get
(
0
).
transform
().
getOperationName
(),
is
(
"fooJob"
));
assertThat
(
spans
.
get
(
0
).
transform
().
getTags
(
0
).
getValue
(),
is
(
"ShardingContext(jobName=fooJob, taskId=fooJob0, shardingTotalCount=1, jobParameter=, shardingItem=0, shardingParameter=null)"
));
}
@Test
public
void
assertError
()
throws
Throwable
{
jobExecutorInterceptor
.
beforeMethod
(
null
,
null
,
new
Object
[]{
mockShardingContext
(
"fooJob"
,
0
),
0
},
null
,
null
);
jobExecutorInterceptor
.
handleMethodException
(
null
,
null
,
null
,
null
,
new
Exception
(
"fooError"
));
jobExecutorInterceptor
.
afterMethod
(
null
,
null
,
null
,
null
,
null
);
TraceSegment
segment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
segment
);
assertNotNull
(
spans
);
assertThat
(
spans
.
size
(),
is
(
1
));
assertThat
(
spans
.
get
(
0
).
transform
().
getIsError
(),
is
(
true
));
assertThat
(
spans
.
get
(
0
).
transform
().
getLogs
(
0
).
getDataList
().
size
(),
is
(
4
));
}
private
ShardingContexts
mockShardingContext
(
String
jobName
,
int
shardingItem
)
{
Map
<
Integer
,
String
>
shardingMap
=
new
HashMap
<
Integer
,
String
>(
1
);
if
(
shardingItem
>=
1
)
{
shardingMap
.
put
(
shardingItem
,
"test"
);
}
return
new
ShardingContexts
(
jobName
+
shardingItem
,
jobName
,
shardingItem
+
1
,
""
,
shardingMap
);
}
}
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/pom.xml
浏览文件 @
c15d1a56
...
...
@@ -52,6 +52,7 @@
<module>
h2-1.x-plugin
</module>
<module>
postgresql-8.x-plugin
</module>
<module>
oracle-10.x-plugin
</module>
<module>
elastic-job-2.x-plugin
</module>
</modules>
<packaging>
pom
</packaging>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录