diff --git a/CHANGES.md b/CHANGES.md index 9f95405d7..cda54595a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ Release Notes. * Refactor pipeline in jedis-plugin. * Enhance kotlin coroutine plugin for stack tracing. * Add plugin to support ClickHouse JDBC driver (0.3.2.*). +* Fix OracleURLParser ignoring actual port when :SID is absent. #### Documentation * Update docs of Tracing APIs, reorganize the API docs into six parts. diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java index 470cf6e5b..9c14d40ce 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java @@ -27,8 +27,8 @@ import org.apache.skywalking.apm.util.StringUtil; /** * {@link OracleURLParser} presents that how to parse oracle connection url. *

- * Note: {@link OracleURLParser} can parse the commons connection url. the commons connection url is of the form: - * jdbc:oracle:(drivertype):@(database),the other the form of connection url cannot be parsed success. + * Note: {@link OracleURLParser} can parse the commons/TNS connection url. the commons connection url is of the form: + * jdbc:oracle:(drivertype):@(database), the other the form of connection url cannot be parsed successfully. */ public class OracleURLParser extends AbstractURLParser { @@ -49,7 +49,14 @@ public class OracleURLParser extends AbstractURLParser { } else { hostLabelStartIndex = url.indexOf("@") + 1; } - int hostLabelEndIndex = url.lastIndexOf(":"); + + String urlTrimmed = url.substring(hostLabelStartIndex); + + // When /service/ exists, check the first slash in trimmed url + // otherwise use the last colon to locate the port number + int hostLabelEndIndex = urlTrimmed.contains("/") ? + hostLabelStartIndex + urlTrimmed.indexOf("/") : url.lastIndexOf(":"); + return new URLLocation(hostLabelStartIndex, hostLabelEndIndex); } diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java index b9120aeb7..0e066fd9d 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java @@ -99,10 +99,10 @@ public class URLParserTest { @Test public void testParseOracleServiceName() { - ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@//localhost:1521/orcl"); + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@//localhost:1531/orcl"); assertThat(connectionInfo.getDBType(), is("Oracle")); assertThat(connectionInfo.getDatabaseName(), is("orcl")); - assertThat(connectionInfo.getDatabasePeer(), is("localhost:1521")); + assertThat(connectionInfo.getDatabasePeer(), is("localhost:1531")); } @Test