Skip to content

Commit c973b9e

Browse files
authored
Fix parsing port from mariadb jdbc url (#9863)
1 parent 23b2521 commit c973b9e

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
322322
int clusterSepLoc = jdbcUrl.indexOf(",");
323323
int ipv6End = jdbcUrl.startsWith("[") ? jdbcUrl.indexOf("]") : -1;
324324
int portLoc = jdbcUrl.indexOf(":", Math.max(0, ipv6End));
325-
portLoc = clusterSepLoc < portLoc ? -1 : portLoc;
325+
portLoc = clusterSepLoc != -1 && clusterSepLoc < portLoc ? -1 : portLoc;
326326
int dbLoc = jdbcUrl.indexOf("/", Math.max(portLoc, clusterSepLoc));
327327

328328
int paramLoc = jdbcUrl.indexOf("?", dbLoc);

instrumentation/jdbc/library/src/test/groovy/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParserTest.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class JdbcConnectionUrlParserTest extends Specification {
8989
"jdbc:mariadb:failover://mdb.host1:33,mdb.host/mdbdb?characterEncoding=utf8" | null | "mariadb:failover://mdb.host1:33" | "mariadb" | "failover" | null | "mdb.host1" | 33 | null | "mdbdb"
9090
"jdbc:mariadb:sequential://mdb.host1,mdb.host2:33/mdbdb" | null | "mariadb:sequential://mdb.host1:3306" | "mariadb" | "sequential" | null | "mdb.host1" | 3306 | null | "mdbdb"
9191
"jdbc:mariadb:loadbalance://127.0.0.1:33,mdb.host/mdbdb" | null | "mariadb:loadbalance://127.0.0.1:33" | "mariadb" | "loadbalance" | null | "127.0.0.1" | 33 | null | "mdbdb"
92+
"jdbc:mariadb:loadbalance://127.0.0.1:33/mdbdb" | null | "mariadb:loadbalance://127.0.0.1:33" | "mariadb" | "loadbalance" | null | "127.0.0.1" | 33 | null | "mdbdb"
9293
"jdbc:mariadb:loadbalance://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:33,mdb.host/mdbdb" | null | "mariadb:loadbalance://2001:0660:7401:0200:0000:0000:0edf:bdd7:33" | "mariadb" | "loadbalance" | null | "2001:0660:7401:0200:0000:0000:0edf:bdd7" | 33 | null | "mdbdb"
9394
"jdbc:mysql:loadbalance://127.0.0.1,127.0.0.1:3306/mdbdb?user=mdbuser&password=PW" | null | "mysql:loadbalance://127.0.0.1:3306" | "mysql" | "loadbalance" | "mdbuser" | "127.0.0.1" | 3306 | null | "mdbdb"
9495
"jdbc:mariadb:replication://localhost:33,anotherhost:3306/mdbdb" | null | "mariadb:replication://localhost:33" | "mariadb" | "replication" | null | "localhost" | 33 | null | "mdbdb"

0 commit comments

Comments
 (0)