diff --git a/CHANGES.md b/CHANGES.md index 88e517366..8b411b04c 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 000000000..52b3edfbd --- /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 9b47afa5d..883e8b0a3 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 45b976a82..ddf2f20fc 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 0e066fd9d..ec71036ab 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")); + } + }