Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Release Notes.
initialization. Delay so11y metrics#build when the services are not ready to avoid MeterService status is not
initialized.
* 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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,7 @@ public class ComponentsDefine {
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 DMDB_JDBC_DRIVER = new OfficialComponent(163, "Dmdb-jdbc-driver");

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class URLParser {
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 OCEANBASE_JDBC_URL_PREFIX = "jdbc:oceanbase:";
private static final String DM_JDBC_URL_PREFIX = "jdbc:dm:";

public static ConnectionInfo parser(String url) {
ConnectionURLParser parser = null;
Expand Down Expand Up @@ -75,7 +76,10 @@ public static ConnectionInfo parser(String url) {
parser = new SybaseURLParser(url);
} else if (lowerCaseUrl.startsWith(OCEANBASE_JDBC_URL_PREFIX)) {
parser = new OceanBaseURLParser(url);
} else if (lowerCaseUrl.startsWith(DM_JDBC_URL_PREFIX)) {
parser = new DMURLParser(url);
}

return parser.parse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,49 @@ public void testParseSybaseJDBCURL() {
assertThat(connectionInfo.getDatabaseName(), is("mydb"));
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"));
}
}
1 change: 1 addition & 0 deletions docs/en/setup/service-agent/java-agent/Supported-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
* Sybase
* [OceanBase](https://www.oceanbase.com/)
* [DaMeng(DM)](https://www.dameng.com/)
* Supported Connection Pool Frameworks
* [Apache Commons DBCP](https://github.com/apache/commons-dbcp) 2.x
* [Alibaba Druid](https://github.com/alibaba/druid) 1.x
Expand Down
Loading