You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by yi...@apache.org on 2023/02/14 08:22:08 UTC

[skywalking-java] branch main updated: Fix oracle url parser ignoring actual port (#456)

This is an automated email from the ASF dual-hosted git repository.

yihaochen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


The following commit(s) were added to refs/heads/main by this push:
     new 5250ecfe2e Fix oracle url parser ignoring actual port (#456)
5250ecfe2e is described below

commit 5250ecfe2e8aa04d3d27420f5ff1e822fc548876
Author: Superskyyy (AWAY, busy graduating | Debug 人) <Su...@outlook.com>
AuthorDate: Tue Feb 14 03:22:01 2023 -0500

    Fix oracle url parser ignoring actual port (#456)
    
    * Fix oracle url parser missed case
    
    * Add changelog
---
 CHANGES.md                                                  |  1 +
 .../plugin/jdbc/connectionurl/parser/OracleURLParser.java   | 13 ++++++++++---
 .../apm/plugin/jdbc/connectionurl/parser/URLParserTest.java |  4 ++--
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 9f95405d75..cda54595a7 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 470cf6e5bc..9c14d40ce5 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.
  * <p>
- * Note: {@link OracleURLParser} can parse the commons connection url. the commons connection url is of the form:
- * <code>jdbc:oracle:(drivertype):@(database)</code>,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:
+ * <code>jdbc:oracle:(drivertype):@(database)</code>, 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/<property> 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 b9120aeb74..0e066fd9d0 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