Skip to content

Commit 46d99c5

Browse files
authored
Support default database(not set through JDBC URL) in mysql-5.x plugin (#154)
1 parent a5ccbca commit 46d99c5

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Release Notes.
3737
* Fix the bug that maybe causing memory leak and repeated traceId when use gateway-2.1.x-plugin or gateway-3.x-plugin.
3838
* Fix Grpc 1.x plugin could leak context due to gRPC cancelled.
3939
* Add JDK ThreadPoolExecutor Plugin.
40+
* Support default database(not set through JDBC URL) in mysql-5.x plugin.
4041

4142
#### Documentation
4243

apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/ConnectionCreate5xInterceptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.skywalking.apm.plugin.jdbc.mysql.v5;
2020

21+
import java.util.Objects;
2122
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
2223
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
2324
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
@@ -42,7 +43,8 @@ public void beforeMethod(Class clazz, Method method, Object[] allArguments, Clas
4243
public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
4344
Object ret) {
4445
if (ret instanceof EnhancedInstance) {
45-
ConnectionInfo connectionInfo = ConnectionCache.get(allArguments[0].toString(), allArguments[1].toString(), allArguments[3].toString());
46+
String database = Objects.isNull(allArguments[3]) ? "" : allArguments[3].toString();
47+
ConnectionInfo connectionInfo = ConnectionCache.get(allArguments[0].toString(), allArguments[1].toString(), database);
4648
if (connectionInfo == null) {
4749
connectionInfo = URLParser.parser(allArguments[4].toString());
4850
}

apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mysql/v5/ConnectionImplCreateInterceptorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,16 @@ public void testResultIsEnhanceInstance() throws Throwable {
5151
}, null, objectInstance);
5252
verify(objectInstance).setSkyWalkingDynamicField(Matchers.any());
5353
}
54+
55+
@Test
56+
public void testResultIsEnhanceInstanceWithNoDatabase() throws Throwable {
57+
interceptor.afterMethod(null, null, new Object[] {
58+
"localhost",
59+
3360,
60+
null,
61+
null,
62+
"jdbc:mysql:replication://localhost:3360,localhost:3360,localhost:3360/test?useUnicode=true&characterEncoding=utf8&useSSL=false&roundRobinLoadBalance=true"
63+
}, null, objectInstance);
64+
verify(objectInstance).setSkyWalkingDynamicField(Matchers.any());
65+
}
5466
}

0 commit comments

Comments
 (0)