-
Notifications
You must be signed in to change notification settings - Fork 677
Add support for dameng(DM) JDBC URL format in URLParser #758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7558d73
[Feature] Add URLParser for dameng(DM)
saber-wang 99455ee
update CHANGES
saber-wang e6e5201
Clean up comments
saber-wang 74718b0
update DMDB_JDBC_DRIVER Component id
saber-wang 359f373
Remove DM logo
saber-wang 5411c3a
Revert "Remove DM logo"
saber-wang e149915
Update description
saber-wang a2cc314
CHANGES.md
wu-sheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...src/main/java/org/apache/skywalking/apm/plugin/jdbc/connectionurl/parser/DMURLParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.