Skip to content

Commit 5250ecf

Browse files
authored
Fix oracle url parser ignoring actual port (#456)
* Fix oracle url parser missed case * Add changelog
1 parent 9cb5a13 commit 5250ecf

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Release Notes.
1414
* Refactor pipeline in jedis-plugin.
1515
* Enhance kotlin coroutine plugin for stack tracing.
1616
* Add plugin to support ClickHouse JDBC driver (0.3.2.*).
17+
* Fix OracleURLParser ignoring actual port when :SID is absent.
1718

1819
#### Documentation
1920
* Update docs of Tracing APIs, reorganize the API docs into six parts.

apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
/**
2828
* {@link OracleURLParser} presents that how to parse oracle connection url.
2929
* <p>
30-
* Note: {@link OracleURLParser} can parse the commons connection url. the commons connection url is of the form:
31-
* <code>jdbc:oracle:(drivertype):@(database)</code>,the other the form of connection url cannot be parsed success.
30+
* Note: {@link OracleURLParser} can parse the commons/TNS connection url. the commons connection url is of the form:
31+
* <code>jdbc:oracle:(drivertype):@(database)</code>, the other the form of connection url cannot be parsed successfully.
3232
*/
3333
public class OracleURLParser extends AbstractURLParser {
3434

@@ -49,7 +49,14 @@ protected URLLocation fetchDatabaseHostsIndexRange() {
4949
} else {
5050
hostLabelStartIndex = url.indexOf("@") + 1;
5151
}
52-
int hostLabelEndIndex = url.lastIndexOf(":");
52+
53+
String urlTrimmed = url.substring(hostLabelStartIndex);
54+
55+
// When /service/<property> exists, check the first slash in trimmed url
56+
// otherwise use the last colon to locate the port number
57+
int hostLabelEndIndex = urlTrimmed.contains("/") ?
58+
hostLabelStartIndex + urlTrimmed.indexOf("/") : url.lastIndexOf(":");
59+
5360
return new URLLocation(hostLabelStartIndex, hostLabelEndIndex);
5461
}
5562

apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ public void testParseOracleSID() {
9999

100100
@Test
101101
public void testParseOracleServiceName() {
102-
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@//localhost:1521/orcl");
102+
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@//localhost:1531/orcl");
103103
assertThat(connectionInfo.getDBType(), is("Oracle"));
104104
assertThat(connectionInfo.getDatabaseName(), is("orcl"));
105-
assertThat(connectionInfo.getDatabasePeer(), is("localhost:1521"));
105+
assertThat(connectionInfo.getDatabasePeer(), is("localhost:1531"));
106106
}
107107

108108
@Test

0 commit comments

Comments
 (0)