Add support for dameng(DM) JDBC URL format in URLParser (#758)
* [Feature] Add URLParser for dameng(DM)
This commit is contained in:
parent
529d6d7eb3
commit
6c74815fdf
|
|
@ -12,6 +12,7 @@ Release Notes.
|
||||||
initialization. Delay so11y metrics#build when the services are not ready to avoid MeterService status is not
|
initialization. Delay so11y metrics#build when the services are not ready to avoid MeterService status is not
|
||||||
initialized.
|
initialized.
|
||||||
* Fix retransform failure when enhancing both parent and child classes.
|
* Fix retransform failure when enhancing both parent and child classes.
|
||||||
|
* Add support for `dameng(DM)` JDBC url format in `URLParser`.
|
||||||
|
|
||||||
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/236?closed=1)
|
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/236?closed=1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -262,4 +262,7 @@ public class ComponentsDefine {
|
||||||
public static final OfficialComponent CAFFEINE = new OfficialComponent(160, "Caffeine");
|
public static final OfficialComponent CAFFEINE = new OfficialComponent(160, "Caffeine");
|
||||||
|
|
||||||
public static final OfficialComponent THREAD_PER_TASK_EXECUTOR = new OfficialComponent(161, "ThreadPerTask-executor");
|
public static final OfficialComponent THREAD_PER_TASK_EXECUTOR = new OfficialComponent(161, "ThreadPerTask-executor");
|
||||||
|
|
||||||
|
public static final OfficialComponent DMDB_JDBC_DRIVER = new OfficialComponent(163, "Dmdb-jdbc-driver");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
|
||||||
|
|
||||||
|
public class DMURLParser extends AbstractURLParser {
|
||||||
|
private static final int DEFAULT_PORT = 5236;
|
||||||
|
private static final String DB_TYPE = "DM";
|
||||||
|
private static final String URL_PARAMS_HOST_KEY = "host";
|
||||||
|
private static final String URL_PARAMS_PORT_KEY = "port";
|
||||||
|
private static final String URL_PARAMS_SCHEMA_KEY = "schema";
|
||||||
|
|
||||||
|
public DMURLParser(String url) {
|
||||||
|
super(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected URLLocation fetchDatabaseHostsIndexRange() {
|
||||||
|
int hostLabelStartIndex = url.indexOf("//");
|
||||||
|
if (hostLabelStartIndex == -1) {
|
||||||
|
return new URLLocation(0, 0);
|
||||||
|
}
|
||||||
|
int hostLabelEndIndex = url.indexOf("?", hostLabelStartIndex + 2);
|
||||||
|
if (hostLabelEndIndex == -1) {
|
||||||
|
hostLabelEndIndex = url.length();
|
||||||
|
}
|
||||||
|
return new URLLocation(hostLabelStartIndex + 2, hostLabelEndIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected URLLocation fetchDatabaseNameIndexRange() {
|
||||||
|
return new URLLocation(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConnectionInfo parse() {
|
||||||
|
URLLocation location = fetchDatabaseHostsIndexRange();
|
||||||
|
String hostPortSegment = "";
|
||||||
|
if (location.endIndex() > location.startIndex()) {
|
||||||
|
hostPortSegment = url.substring(location.startIndex(), location.endIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
String host = "";
|
||||||
|
String port = "";
|
||||||
|
|
||||||
|
if (!hostPortSegment.isEmpty()) {
|
||||||
|
String[] parts = hostPortSegment.split(":");
|
||||||
|
if (parts.length >= 1) {
|
||||||
|
host = parts[0];
|
||||||
|
}
|
||||||
|
if (parts.length == 2) {
|
||||||
|
port = parts[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (host.isEmpty()) {
|
||||||
|
host = fetchFromUrlParams(URL_PARAMS_HOST_KEY);
|
||||||
|
}
|
||||||
|
if (port == null || port.isEmpty()) {
|
||||||
|
port = fetchFromUrlParams(URL_PARAMS_PORT_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (port == null || port.isEmpty()) {
|
||||||
|
port = String.valueOf(DEFAULT_PORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
String schema = fetchFromUrlParams(URL_PARAMS_SCHEMA_KEY);
|
||||||
|
|
||||||
|
return new ConnectionInfo(
|
||||||
|
ComponentsDefine.DMDB_JDBC_DRIVER,
|
||||||
|
DB_TYPE,
|
||||||
|
host,
|
||||||
|
Integer.parseInt(port),
|
||||||
|
schema == null ? "" : schema
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String fetchFromUrlParams(String key) {
|
||||||
|
int paramIndex = url.indexOf("?");
|
||||||
|
if (paramIndex == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String[] params = url.substring(paramIndex + 1).split("&");
|
||||||
|
for (String pair : params) {
|
||||||
|
if (pair.startsWith(key + "=")) {
|
||||||
|
String[] segments = pair.split("=", 2);
|
||||||
|
if (segments.length == 2) {
|
||||||
|
return segments[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -41,6 +41,7 @@ public class URLParser {
|
||||||
private static final String DB2_JDBC_URL_PREFIIX = "jdbc:db2:";
|
private static final String DB2_JDBC_URL_PREFIIX = "jdbc:db2:";
|
||||||
private static final String SYBASE_JDBC_URL_PREFIX = "jdbc:sybase:tds:";
|
private static final String SYBASE_JDBC_URL_PREFIX = "jdbc:sybase:tds:";
|
||||||
private static final String OCEANBASE_JDBC_URL_PREFIX = "jdbc:oceanbase:";
|
private static final String OCEANBASE_JDBC_URL_PREFIX = "jdbc:oceanbase:";
|
||||||
|
private static final String DM_JDBC_URL_PREFIX = "jdbc:dm:";
|
||||||
|
|
||||||
public static ConnectionInfo parser(String url) {
|
public static ConnectionInfo parser(String url) {
|
||||||
ConnectionURLParser parser = null;
|
ConnectionURLParser parser = null;
|
||||||
|
|
@ -75,7 +76,10 @@ public class URLParser {
|
||||||
parser = new SybaseURLParser(url);
|
parser = new SybaseURLParser(url);
|
||||||
} else if (lowerCaseUrl.startsWith(OCEANBASE_JDBC_URL_PREFIX)) {
|
} else if (lowerCaseUrl.startsWith(OCEANBASE_JDBC_URL_PREFIX)) {
|
||||||
parser = new OceanBaseURLParser(url);
|
parser = new OceanBaseURLParser(url);
|
||||||
|
} else if (lowerCaseUrl.startsWith(DM_JDBC_URL_PREFIX)) {
|
||||||
|
parser = new DMURLParser(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parser.parse();
|
return parser.parse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -415,4 +415,49 @@ public class URLParserTest {
|
||||||
assertThat(connectionInfo.getDatabaseName(), is("mydb"));
|
assertThat(connectionInfo.getDatabaseName(), is("mydb"));
|
||||||
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5000"));
|
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5000"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseDMJDBCURLWithNamedParams()
|
||||||
|
{
|
||||||
|
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://?host=localhost&port=5236");
|
||||||
|
assertThat(connectionInfo.getDBType(), is("DM"));
|
||||||
|
assertThat(connectionInfo.getDatabaseName(), is(""));
|
||||||
|
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5236"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseDMJDBCURLWithNamedParamsAndScheme()
|
||||||
|
{
|
||||||
|
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://?host=localhost&port=5236&schema=dm");
|
||||||
|
assertThat(connectionInfo.getDBType(), is("DM"));
|
||||||
|
assertThat(connectionInfo.getDatabaseName(), is("dm"));
|
||||||
|
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5236"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseDMJDBCURLWithoutHost()
|
||||||
|
{
|
||||||
|
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://localhost");
|
||||||
|
assertThat(connectionInfo.getDBType(), is("DM"));
|
||||||
|
assertThat(connectionInfo.getDatabaseName(), is(""));
|
||||||
|
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5236"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseDMJDBCURLWithoutHostAndScheme()
|
||||||
|
{
|
||||||
|
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://localhost?schema=dm");
|
||||||
|
assertThat(connectionInfo.getDBType(), is("DM"));
|
||||||
|
assertThat(connectionInfo.getDatabaseName(), is("dm"));
|
||||||
|
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5236"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseDMJDBCURLWithoutHostPort()
|
||||||
|
{
|
||||||
|
ConnectionInfo connectionInfo = URLParser.parser("jdbc:dm://localhost:5237?schema=dm");
|
||||||
|
assertThat(connectionInfo.getDBType(), is("DM"));
|
||||||
|
assertThat(connectionInfo.getDatabaseName(), is("dm"));
|
||||||
|
assertThat(connectionInfo.getDatabasePeer(), is("localhost:5237"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,7 @@ The meter plugin provides the advanced metrics collections, which are not a part
|
||||||
* [DB2](https://www.ibm.com/products/db2/database)
|
* [DB2](https://www.ibm.com/products/db2/database)
|
||||||
* Sybase
|
* Sybase
|
||||||
* [OceanBase](https://www.oceanbase.com/)
|
* [OceanBase](https://www.oceanbase.com/)
|
||||||
|
* [DaMeng(DM)](https://www.dameng.com/)
|
||||||
* Supported Connection Pool Frameworks
|
* Supported Connection Pool Frameworks
|
||||||
* [Apache Commons DBCP](https://github.com/apache/commons-dbcp) 2.x
|
* [Apache Commons DBCP](https://github.com/apache/commons-dbcp) 2.x
|
||||||
* [Alibaba Druid](https://github.com/alibaba/druid) 1.x
|
* [Alibaba Druid](https://github.com/alibaba/druid) 1.x
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue