Feature/fix clickhouse with druid (#566)
This commit is contained in:
parent
d42e24583d
commit
7005f2d466
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue