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

wusheng 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 7005f2d466 Feature/fix clickhouse with druid (#566)
7005f2d466 is described below

commit 7005f2d4664fdcbfcb752bae4f45684f67f767c9
Author: gzlicanyi <[email protected]>
AuthorDate: Sat Jul 1 00:01:40 2023 +0800

    Feature/fix clickhouse with druid (#566)
---
 CHANGES.md                                         |  1 +
 .../connectionurl/parser/ClickHouseURLParser.java  | 32 ++++++++++++++++++++++
 .../jdbc/connectionurl/parser/MysqlURLParser.java  | 12 ++++++--
 .../jdbc/connectionurl/parser/URLParser.java       |  3 ++
 .../jdbc/connectionurl/parser/URLParserTest.java   |  9 ++++++
 5 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 88e5173667..8b411b04c3 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -139,6 +139,7 @@ Callable {
 * Fix NPE in guava-eventbus-plugin.
 * Add WebSphere Liberty 23.x plugin
 * Add Plugin to support aerospike Java client
+* Add ClickHouse parsing to the jdbc-common plugin.
 
 #### Documentation
 
diff --git 
a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ClickHouseURLParser.java
 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ClickHouseURLParser.java
new file mode 100644
index 0000000000..52b3edfbd9
--- /dev/null
+++ 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/ClickHouseURLParser.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser;
+
+import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+
+/**
+ * {@link ClickHouseURLParser} parse connection url of mysql.
+ */
+public class ClickHouseURLParser extends MysqlURLParser {
+
+    public ClickHouseURLParser(String url) {
+        super(url, "ClickHouse", ComponentsDefine.CLICKHOUSE_JDBC_DRIVER, 
8123);
+    }
+
+}
diff --git 
a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java
 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java
index 9b47afa5d2..883e8b0a37 100644
--- 
a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java
+++ 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java
@@ -28,6 +28,7 @@ import 
org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
 public class MysqlURLParser extends AbstractURLParser {
 
     private static final int DEFAULT_PORT = 3306;
+    private int defaultPort = DEFAULT_PORT;
     private String dbType = "Mysql";
     private OfficialComponent component = ComponentsDefine.MYSQL_JDBC_DRIVER;
 
@@ -41,6 +42,13 @@ public class MysqlURLParser extends AbstractURLParser {
         this.component = component;
     }
 
+    public MysqlURLParser(String url, String dbType, OfficialComponent 
component, int defaultPort) {
+        super(url);
+        this.dbType = dbType;
+        this.component = component;
+        this.defaultPort = defaultPort;
+    }
+
     @Override
     protected URLLocation fetchDatabaseHostsIndexRange() {
         int hostLabelStartIndex = url.indexOf("//");
@@ -101,7 +109,7 @@ public class MysqlURLParser extends AbstractURLParser {
             StringBuilder sb = new StringBuilder();
             for (String host : hostSegment) {
                 if (host.split(":").length == 1) {
-                    
sb.append(host).append(":").append(DEFAULT_PORT).append(",");
+                    
sb.append(host).append(":").append(defaultPort).append(",");
                 } else {
                     sb.append(host).append(",");
                 }
@@ -113,7 +121,7 @@ public class MysqlURLParser extends AbstractURLParser {
                 return new ConnectionInfo(component, dbType, hostAndPort[0], 
Integer.valueOf(hostAndPort[1]), fetchDatabaseNameFromURL(location
                         .endIndex()));
             } else {
-                return new ConnectionInfo(component, dbType, hostAndPort[0], 
DEFAULT_PORT, fetchDatabaseNameFromURL(location
+                return new ConnectionInfo(component, dbType, hostAndPort[0], 
defaultPort, fetchDatabaseNameFromURL(location
                         .endIndex()));
             }
         }
diff --git 
a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
index 45b976a820..ddf2f20fc7 100644
--- 
a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
+++ 
b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParser.java
@@ -35,6 +35,7 @@ public class URLParser {
     private static final String MSSQL_JDBC_URL_PREFIX = "jdbc:sqlserver:";
     private static final String KYLIN_JDBC_URK_PREFIX = "jdbc:kylin";
     private static final String IMPALA_JDBC_URK_PREFIX = "jdbc:impala";
+    private static final String CLICKHOUSE_JDBC_URK_PREFIX = "jdbc:clickhouse";
 
     public static ConnectionInfo parser(String url) {
         ConnectionURLParser parser = null;
@@ -57,6 +58,8 @@ public class URLParser {
             parser = new KylinJdbcURLParser(url);
         } else if (lowerCaseUrl.startsWith(IMPALA_JDBC_URK_PREFIX)) {
             parser = new ImpalaJdbcURLParser(url);
+        } else if (lowerCaseUrl.startsWith(CLICKHOUSE_JDBC_URK_PREFIX)) {
+            parser = new ClickHouseURLParser(url);
         }
         return parser.parse();
     }
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 0e066fd9d0..ec71036abe 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
@@ -168,4 +168,13 @@ public class URLParserTest {
         assertThat(connectionInfo.getDatabaseName(), is("test"));
         assertThat(connectionInfo.getDatabasePeer(), is("primaryhost:3306"));
     }
+
+    @Test
+    public void testParseClickhouseJDBCURL() {
+        ConnectionInfo connectionInfo = new 
URLParser().parser("jdbc:clickhouse://localhost:8123/test");
+        assertThat(connectionInfo.getDBType(), is("ClickHouse"));
+        assertThat(connectionInfo.getDatabaseName(), is("test"));
+        assertThat(connectionInfo.getDatabasePeer(), is("localhost:8123"));
+    }
+
 }

Reply via email to