Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
润土的好友猹
SkyWalking
提交
62f76881
S
SkyWalking
项目概览
润土的好友猹
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
9
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,发现更多精彩内容 >>
未验证
提交
62f76881
编写于
7月 17, 2020
作者:
P
Patrick Jiang(白泽)
提交者:
GitHub
7月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix issue 4965 (#5109)
上级
8b46e5c5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
101 addition
and
9 deletion
+101
-9
apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java
...dbc/mysql/PreparedStatementExecuteMethodsInterceptor.java
+6
-6
test/plugin/scenarios/mysql-scenario/config/expectedData.yaml
.../plugin/scenarios/mysql-scenario/config/expectedData.yaml
+68
-1
test/plugin/scenarios/mysql-scenario/src/main/java/org/apache/skywalking/apm/testcase/mysql/SQLExecutor.java
...org/apache/skywalking/apm/testcase/mysql/SQLExecutor.java
+20
-1
test/plugin/scenarios/mysql-scenario/src/main/java/org/apache/skywalking/apm/testcase/mysql/controller/CaseController.java
...walking/apm/testcase/mysql/controller/CaseController.java
+7
-1
未找到文件。
apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java
浏览文件 @
62f76881
...
...
@@ -40,15 +40,15 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho
public
final
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
{
StatementEnhanceInfos
cacheObject
=
(
StatementEnhanceInfos
)
objInst
.
getSkyWalkingDynamicField
();
ConnectionInfo
connectInfo
=
cacheObject
.
getConnectionInfo
();
/**
* For avoid NPE. In this particular case, Execute sql inside the {@link com.mysql.jdbc.ConnectionImpl} constructor,
* before the interceptor sets the connectionInfo.
*
* When invoking prepareCall, cacheObject is null. Because it will determine procedures's parameter types by executing sql in mysql
* before the interceptor sets the statementEnhanceInfos.
* @see JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object)
*/
if
(
c
onnectInfo
!=
null
)
{
if
(
c
acheObject
!=
null
&&
cacheObject
.
getConnectionInfo
()
!=
null
)
{
ConnectionInfo
connectInfo
=
cacheObject
.
getConnectionInfo
();
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
buildOperationName
(
connectInfo
,
method
.
getName
(),
cacheObject
.
getStatementName
()),
connectInfo
.
getDatabasePeer
());
Tags
.
DB_TYPE
.
set
(
span
,
"sql"
);
...
...
@@ -73,7 +73,7 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho
public
final
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
{
StatementEnhanceInfos
cacheObject
=
(
StatementEnhanceInfos
)
objInst
.
getSkyWalkingDynamicField
();
if
(
cacheObject
.
getConnectionInfo
()
!=
null
)
{
if
(
cacheObject
!=
null
&&
cacheObject
.
getConnectionInfo
()
!=
null
)
{
ContextManager
.
stopSpan
();
}
return
ret
;
...
...
@@ -83,7 +83,7 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho
public
final
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
StatementEnhanceInfos
cacheObject
=
(
StatementEnhanceInfos
)
objInst
.
getSkyWalkingDynamicField
();
if
(
cacheObject
.
getConnectionInfo
()
!=
null
)
{
if
(
cacheObject
!=
null
&&
cacheObject
.
getConnectionInfo
()
!=
null
)
{
ContextManager
.
activeSpan
().
errorOccurred
().
log
(
t
);
}
}
...
...
test/plugin/scenarios/mysql-scenario/config/expectedData.yaml
浏览文件 @
62f76881
...
...
@@ -72,10 +72,77 @@ segmentItems:
componentId
:
33
peer
:
mysql-server:3306
skipAnalysis
:
'
false'
-
operationName
:
Mysql/JDBI/
Connection/clos
e
-
operationName
:
Mysql/JDBI/
Statement/execut
e
operationId
:
eq
0
parentSpanId
:
0
spanId
:
4
tags
:
-
{
key
:
db.type
,
value
:
sql
}
-
{
key
:
db.instance
,
value
:
test
}
-
{
key
:
db.statement
,
value
:
"
create
procedure
testProcedure(IN
id
varchar(10))
\n
begin
\n
select
id;
\n
end"
}
logs
:
[]
startTime
:
nq
0
endTime
:
nq
0
isError
:
false
spanLayer
:
Database
spanType
:
Exit
componentId
:
33
peer
:
mysql-server:3306
skipAnalysis
:
'
false'
-
operationName
:
Mysql/JDBI/Statement/executeQuery
operationId
:
eq
0
parentSpanId
:
0
spanId
:
5
spanLayer
:
Database
startTime
:
nq
0
endTime
:
nq
0
componentId
:
33
isError
:
false
spanType
:
Exit
peer
:
mysql-server:3306
skipAnalysis
:
false
tags
:
-
{
key
:
db.type
,
value
:
sql
}
-
{
key
:
db.instance
,
value
:
test
}
-
{
key
:
db.statement
,
value
:
SHOW CREATE PROCEDURE `test`.`testProcedure`
}
-
operationName
:
Mysql/JDBI/CallableStatement/execute
operationId
:
eq
0
parentSpanId
:
0
spanId
:
6
tags
:
-
{
key
:
db.type
,
value
:
sql
}
-
{
key
:
db.instance
,
value
:
test
}
-
{
key
:
db.statement
,
value
:
"
call
testProcedure(
?
)"
}
logs
:
[]
startTime
:
nq
0
endTime
:
nq
0
isError
:
false
spanLayer
:
Database
spanType
:
Exit
componentId
:
33
peer
:
mysql-server:3306
skipAnalysis
:
'
false'
-
operationName
:
Mysql/JDBI/Statement/execute
operationId
:
eq
0
parentSpanId
:
0
spanId
:
7
tags
:
-
{
key
:
db.type
,
value
:
sql
}
-
{
key
:
db.instance
,
value
:
test
}
-
{
key
:
db.statement
,
value
:
"
drop
procedure
testProcedure"
}
logs
:
[]
startTime
:
nq
0
endTime
:
nq
0
isError
:
false
spanLayer
:
Database
spanType
:
Exit
componentId
:
33
peer
:
mysql-server:3306
skipAnalysis
:
'
false'
-
operationName
:
Mysql/JDBI/Connection/close
operationId
:
eq
0
parentSpanId
:
0
spanId
:
8
tags
:
-
{
key
:
db.type
,
value
:
sql
}
-
{
key
:
db.instance
,
value
:
test
}
...
...
test/plugin/scenarios/mysql-scenario/src/main/java/org/apache/skywalking/apm/testcase/mysql/SQLExecutor.java
浏览文件 @
62f76881
...
...
@@ -51,11 +51,30 @@ public class SQLExecutor implements AutoCloseable {
}
public
void
dropTable
(
String
sql
)
throws
SQLException
{
executeStatement
(
sql
);
}
public
void
createProcedure
(
String
sql
)
throws
SQLException
{
executeStatement
(
sql
);
}
public
void
dropProcedure
(
String
sql
)
throws
SQLException
{
executeStatement
(
sql
);
}
public
void
callProcedure
(
String
sql
,
String
id
)
throws
SQLException
{
PreparedStatement
preparedStatement
=
connection
.
prepareCall
(
sql
);
preparedStatement
.
setString
(
1
,
id
);
preparedStatement
.
execute
();
preparedStatement
.
close
();
}
public
void
executeStatement
(
String
sql
)
throws
SQLException
{
Statement
preparedStatement
=
connection
.
createStatement
();
preparedStatement
.
execute
(
sql
);
preparedStatement
.
close
();
}
public
void
closeConnection
()
throws
SQLException
{
if
(
this
.
connection
!=
null
)
{
this
.
connection
.
close
();
...
...
test/plugin/scenarios/mysql-scenario/src/main/java/org/apache/skywalking/apm/testcase/mysql/controller/CaseController.java
浏览文件 @
62f76881
...
...
@@ -40,7 +40,10 @@ public class CaseController {
private
static
final
String
QUERY_DATA_SQL
=
"SELECT id, value FROM test_007 WHERE id=?"
;
private
static
final
String
DELETE_DATA_SQL
=
"DELETE FROM test_007 WHERE id=?"
;
private
static
final
String
DROP_TABLE_SQL
=
"DROP table test_007"
;
private
static
final
String
CREATE_PROCEDURE_SQL
=
"create procedure testProcedure(IN id varchar(10)) \n begin \n select id; \n end"
;
private
static
final
String
CALL_PROCEDURE_SQL
=
"call testProcedure( ? )"
;
private
static
final
String
DROP_PROCEDURE_SQL
=
"drop procedure testProcedure"
;
@RequestMapping
(
"/mysql-scenario"
)
@ResponseBody
public
String
testcase
()
throws
Exception
{
...
...
@@ -48,6 +51,9 @@ public class CaseController {
sqlExecute
.
createTable
(
CREATE_TABLE_SQL
);
sqlExecute
.
insertData
(
INSERT_DATA_SQL
,
"1"
,
"1"
);
sqlExecute
.
dropTable
(
DROP_TABLE_SQL
);
sqlExecute
.
createProcedure
(
CREATE_PROCEDURE_SQL
);
sqlExecute
.
callProcedure
(
CALL_PROCEDURE_SQL
,
"nihao"
);
sqlExecute
.
dropProcedure
(
DROP_PROCEDURE_SQL
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"Failed to execute sql."
,
e
);
throw
e
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录