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 06:59:14 UTC

[skywalking-java] branch fix-oracle-url-parser created (now 15eb941956)

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

yihaochen pushed a change to branch fix-oracle-url-parser
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


      at 15eb941956 Fix oracle url parser missed case

This branch includes the following new commits:

     new 15eb941956 Fix oracle url parser missed case

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking-java] 01/01: Fix oracle url parser missed case

Posted by yi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 15eb9419567f16ea351428bfae62381308f045eb
Author: Superskyyy <su...@outlook.com>
AuthorDate: Tue Feb 14 01:57:45 2023 -0500

    Fix oracle url parser missed case
---
 .../plugin/jdbc/connectionurl/parser/OracleURLParser.java   | 13 ++++++++++---
 .../apm/plugin/jdbc/connectionurl/parser/URLParserTest.java |  4 ++--
 2 files changed, 12 insertions(+), 5 deletions(-)

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