Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
086c5ac0
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,发现更多精彩内容 >>
提交
086c5ac0
编写于
10月 12, 2017
作者:
G
gaohongtao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor code for performance
上级
0c2176c4
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
173 addition
and
32 deletion
+173
-32
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java
...rg/skywalking/apm/agent/core/context/ContextSnapshot.java
+4
-0
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/pom.xml
...sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/pom.xml
+18
-0
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java
...org/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java
+23
-2
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java
...king/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java
+18
-10
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java
...kywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java
+18
-0
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java
...in/sjdbc/define/ExecutorEngineConstructorInterceptor.java
+36
-0
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java
...king/apm/plugin/sjdbc/define/ExecutorInstrumentation.java
+34
-3
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java
...java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java
+22
-17
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/ContextSnapshot.java
浏览文件 @
086c5ac0
...
...
@@ -113,4 +113,8 @@ public class ContextSnapshot {
public
int
getEntryApplicationInstanceId
()
{
return
entryApplicationInstanceId
;
}
public
boolean
fromCurrent
()
{
return
traceSegmentId
.
equals
(
ContextManager
.
capture
().
getTraceSegmentId
());
}
}
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/pom.xml
浏览文件 @
086c5ac0
<?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"
>
...
...
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/ExecuteEventListener.java
浏览文件 @
086c5ac0
/*
* 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.sjdbc
;
import
com.dangdang.ddframe.rdb.sharding.executor.event.AbstractExecutionEvent
;
...
...
@@ -17,7 +35,7 @@ import org.skywalking.apm.network.trace.component.ComponentsDefine;
import
org.skywalking.apm.plugin.sjdbc.define.AsyncExecuteInterceptor
;
/**
* Sharding-jdbc provides {@link EventBusInstance} to help external systems get events
about
sql execution.
* Sharding-jdbc provides {@link EventBusInstance} to help external systems get events
of
sql execution.
* {@link ExecuteEventListener} can get sql statement start and end events, resulting in db span.
*
* @author gaohongtao
...
...
@@ -45,7 +63,10 @@ public class ExecuteEventListener {
case
BEFORE_EXECUTE:
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
"/SJDBC/BRANCH/"
+
operation
,
event
.
getDataSource
());
if
(
ExecutorDataMap
.
getDataMap
().
containsKey
(
AsyncExecuteInterceptor
.
SNAPSHOT_DATA_KEY
))
{
ContextManager
.
continued
((
ContextSnapshot
)
ExecutorDataMap
.
getDataMap
().
get
(
AsyncExecuteInterceptor
.
SNAPSHOT_DATA_KEY
));
ContextSnapshot
contextSnapshot
=
(
ContextSnapshot
)
ExecutorDataMap
.
getDataMap
().
get
(
AsyncExecuteInterceptor
.
SNAPSHOT_DATA_KEY
);
if
(!
contextSnapshot
.
fromCurrent
())
{
ContextManager
.
continued
(
contextSnapshot
);
}
}
Tags
.
DB_TYPE
.
set
(
span
,
"sql"
);
Tags
.
DB_INSTANCE
.
set
(
span
,
event
.
getDataSource
());
...
...
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/AsyncExecuteInterceptor.java
浏览文件 @
086c5ac0
/*
* 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.sjdbc.define
;
import
com.dangdang.ddframe.rdb.sharding.constant.SQLType
;
import
com.dangdang.ddframe.rdb.sharding.executor.ExecuteCallback
;
import
com.dangdang.ddframe.rdb.sharding.executor.threadlocal.ExecutorDataMap
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
import
org.skywalking.apm.agent.core.context.ContextSnapshot
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
...
...
@@ -34,14 +50,6 @@ public class AsyncExecuteInterceptor implements InstanceMethodsAroundInterceptor
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
Map
<
String
,
Object
>
oldMap
=
ExecutorDataMap
.
getDataMap
();
Map
<
String
,
Object
>
newMap
=
new
HashMap
<>(
oldMap
.
size
()
-
1
);
for
(
Map
.
Entry
<
String
,
Object
>
each
:
oldMap
.
entrySet
())
{
if
(!
each
.
getKey
().
equals
(
SNAPSHOT_DATA_KEY
))
{
newMap
.
put
(
each
.
getKey
(),
each
.
getValue
());
}
}
ExecutorDataMap
.
setDataMap
(
newMap
);
return
ret
;
}
...
...
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecuteInterceptor.java
浏览文件 @
086c5ac0
/*
* 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.sjdbc.define
;
import
com.dangdang.ddframe.rdb.sharding.constant.SQLType
;
...
...
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorEngineConstructorInterceptor.java
0 → 100644
浏览文件 @
086c5ac0
/*
* 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.sjdbc.define
;
import
com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.skywalking.apm.plugin.sjdbc.ExecuteEventListener
;
/**
* {@link ExecutorEngineConstructorInterceptor} enhances {@link ExecutorEngine#}'s constructor, initializing {@link ExecuteEventListener}
*
* @author gaohongtao
*/
public
class
ExecutorEngineConstructorInterceptor
implements
InstanceConstructorInterceptor
{
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
ExecuteEventListener
.
init
();
}
}
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/main/java/org/skywalking/apm/plugin/sjdbc/define/ExecutorInstrumentation.java
浏览文件 @
086c5ac0
/*
* 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.sjdbc.define
;
import
net.bytebuddy.description.method.MethodDescription
;
...
...
@@ -6,8 +24,8 @@ import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoin
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
org.skywalking.apm.plugin.sjdbc.ExecuteEventListener
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
...
...
@@ -19,6 +37,8 @@ import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
public
class
ExecutorInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine"
;
private
static
final
String
EXECUTOR_ENGINE_CONSTRUCTOR_INTERCEPTOR_CLASS
=
"org.skywalking.apm.plugin.sjdbc.define.ExecutorEngineConstructorInterceptor"
;
private
static
final
String
EXECUTE_INTERCEPTOR_CLASS
=
"org.skywalking.apm.plugin.sjdbc.define.ExecuteInterceptor"
;
...
...
@@ -26,7 +46,19 @@ public class ExecutorInstrumentation extends ClassInstanceMethodsEnhancePluginDe
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
null
;
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
any
();
}
@Override
public
String
getConstructorInterceptor
()
{
return
EXECUTOR_ENGINE_CONSTRUCTOR_INTERCEPTOR_CLASS
;
}
}
};
}
@Override
...
...
@@ -69,7 +101,6 @@ public class ExecutorInstrumentation extends ClassInstanceMethodsEnhancePluginDe
@Override
protected
ClassMatch
enhanceClass
()
{
ExecuteEventListener
.
init
();
return
byName
(
ENHANCE_CLASS
);
}
}
apm-sniffer/apm-sdk-plugin/sharding-jdbc-1.5.x-plugin/src/test/java/org/skywalking/apm/plugin/sjdbc/InterceptorTest.java
浏览文件 @
086c5ac0
/*
* 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.sjdbc
;
import
com.dangdang.ddframe.rdb.sharding.constant.SQLType
;
...
...
@@ -14,7 +32,6 @@ import java.util.List;
import
java.util.Map
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
org.hamcrest.core.Is
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
...
...
@@ -34,9 +51,11 @@ import org.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import
org.skywalking.apm.network.trace.component.ComponentsDefine
;
import
org.skywalking.apm.plugin.sjdbc.define.AsyncExecuteInterceptor
;
import
org.skywalking.apm.plugin.sjdbc.define.ExecuteInterceptor
;
import
org.skywalking.apm.plugin.sjdbc.define.ExecutorEngineConstructorInterceptor
;
import
static
org
.
hamcrest
.
core
.
Is
.
is
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SpanAssert
.
assertComponent
;
import
static
org
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SpanAssert
.
assertLayer
;
...
...
@@ -64,6 +83,7 @@ public class InterceptorTest {
@BeforeClass
public
static
void
init
()
{
ExecuteEventListener
.
init
();
new
ExecutorEngineConstructorInterceptor
().
onConstruct
(
null
,
null
);
ES
=
Executors
.
newSingleThreadExecutor
();
}
...
...
@@ -109,6 +129,7 @@ public class InterceptorTest {
TraceSegment
segment0
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
TraceSegment
segment1
=
segmentStorage
.
getTraceSegments
().
get
(
1
);
assertThat
(
segment0
.
getRefs
().
size
(),
is
(
1
));
assertNull
(
segment1
.
getRefs
());
List
<
AbstractTracingSpan
>
spans0
=
SegmentHelper
.
getSpans
(
segment0
);
assertNotNull
(
spans0
);
assertThat
(
spans0
.
size
(),
is
(
1
));
...
...
@@ -120,22 +141,6 @@ public class InterceptorTest {
assertThat
(
spans1
.
get
(
1
).
getOperationName
(),
is
(
"/SJDBC/TRUNK/DQL"
));
}
@Test
public
void
assertAsyncContextHold
()
throws
Throwable
{
ExecutorDataMap
.
getDataMap
().
put
(
"FOO_KEY"
,
"FOO_VALUE"
);
executeInterceptor
.
beforeMethod
(
null
,
null
,
allArguments
,
null
,
null
);
asyncExecuteInterceptor
.
beforeMethod
(
null
,
null
,
null
,
null
,
null
);
final
Map
<
String
,
Object
>
dataMap
=
ExecutorDataMap
.
getDataMap
();
ES
.
submit
(()
->
{
ExecutorDataMap
.
setDataMap
(
dataMap
);
sendEvent
(
"ds_1"
,
"select * from t_order_1"
);
}).
get
();
asyncExecuteInterceptor
.
afterMethod
(
null
,
null
,
null
,
null
,
null
);
executeInterceptor
.
afterMethod
(
null
,
null
,
allArguments
,
null
,
null
);
assertThat
(
ExecutorDataMap
.
getDataMap
().
size
(),
is
(
1
));
assertThat
(
ExecutorDataMap
.
getDataMap
().
get
(
"FOO_KEY"
),
Is
.<
Object
>
is
(
"FOO_VALUE"
));
}
@Test
public
void
assertExecuteError
()
throws
Throwable
{
executeInterceptor
.
beforeMethod
(
null
,
null
,
allArguments
,
null
,
null
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录