Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
03824c2f
S
SkyWalking
项目概览
月轩居士
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
03824c2f
编写于
12月 06, 2017
作者:
wu-sheng
提交者:
GitHub
12月 06, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #647 from ascrutae/feature/support-oracle-tns-url
support TNS URL of oracle plugin
上级
730c43d5
02877d4b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
159 addition
and
29 deletion
+159
-29
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java
...m/plugin/jdbc/connectionurl/parser/AbstractURLParser.java
+6
-6
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java
...ing/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java
+4
-4
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java
.../apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java
+6
-6
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java
...apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java
+76
-7
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java
...plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java
+6
-6
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java
...ing/apm/plugin/jdbc/connectionurl/parser/URLLocation.java
+37
-0
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java
...g/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java
+24
-0
未找到文件。
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/AbstractURLParser.java
浏览文件 @
03824c2f
...
...
@@ -31,14 +31,14 @@ public abstract class AbstractURLParser implements ConnectionURLParser {
*
* @return index range that database hosts.
*/
protected
abstract
int
[]
fetchDatabaseHostsIndexRange
();
protected
abstract
URLLocation
fetchDatabaseHostsIndexRange
();
/**
* Fetch the index range that database name from connection url.
*
* @return index range that database name.
*/
protected
abstract
int
[]
fetchDatabaseNameIndexRange
();
protected
abstract
URLLocation
fetchDatabaseNameIndexRange
();
/**
* Fetch database host(s) from connection url.
...
...
@@ -46,8 +46,8 @@ public abstract class AbstractURLParser implements ConnectionURLParser {
* @return database host(s).
*/
protected
String
fetchDatabaseHostsFromURL
()
{
int
[]
indexRange
=
fetchDatabaseHostsIndexRange
();
return
url
.
substring
(
indexRange
[
0
],
indexRange
[
1
]
);
URLLocation
hostsLocation
=
fetchDatabaseHostsIndexRange
();
return
url
.
substring
(
hostsLocation
.
startIndex
(),
hostsLocation
.
endIndex
()
);
}
/**
...
...
@@ -56,8 +56,8 @@ public abstract class AbstractURLParser implements ConnectionURLParser {
* @return database name.
*/
protected
String
fetchDatabaseNameFromURL
()
{
int
[]
indexRange
=
fetchDatabaseNameIndexRange
();
return
url
.
substring
(
indexRange
[
0
],
indexRange
[
1
]
);
URLLocation
hostsLocation
=
fetchDatabaseNameIndexRange
();
return
url
.
substring
(
hostsLocation
.
startIndex
(),
hostsLocation
.
endIndex
()
);
}
/**
...
...
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/H2URLParser.java
浏览文件 @
03824c2f
...
...
@@ -55,20 +55,20 @@ public class H2URLParser extends AbstractURLParser {
}
@Override
protected
int
[]
fetchDatabaseHostsIndexRange
()
{
protected
URLLocation
fetchDatabaseHostsIndexRange
()
{
int
hostLabelStartIndex
=
url
.
indexOf
(
"//"
);
int
hostLabelEndIndex
=
url
.
indexOf
(
"/"
,
hostLabelStartIndex
+
2
);
return
new
int
[]
{
hostLabelStartIndex
+
2
,
hostLabelEndIndex
}
;
return
new
URLLocation
(
hostLabelStartIndex
+
2
,
hostLabelEndIndex
)
;
}
@Override
protected
int
[]
fetchDatabaseNameIndexRange
()
{
protected
URLLocation
fetchDatabaseNameIndexRange
()
{
int
databaseStartTag
=
url
.
lastIndexOf
(
"/"
);
int
databaseEndTag
=
url
.
indexOf
(
";"
);
if
(
databaseEndTag
==
-
1
)
{
databaseEndTag
=
url
.
length
();
}
return
new
int
[]
{
databaseStartTag
+
1
,
databaseEndTag
}
;
return
new
URLLocation
(
databaseStartTag
+
1
,
databaseEndTag
)
;
}
@Override
...
...
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/MysqlURLParser.java
浏览文件 @
03824c2f
...
...
@@ -41,26 +41,26 @@ public class MysqlURLParser extends AbstractURLParser {
}
@Override
protected
int
[]
fetchDatabaseHostsIndexRange
()
{
protected
URLLocation
fetchDatabaseHostsIndexRange
()
{
int
hostLabelStartIndex
=
url
.
indexOf
(
"//"
);
int
hostLabelEndIndex
=
url
.
indexOf
(
"/"
,
hostLabelStartIndex
+
2
);
return
new
int
[]
{
hostLabelStartIndex
+
2
,
hostLabelEndIndex
}
;
return
new
URLLocation
(
hostLabelStartIndex
+
2
,
hostLabelEndIndex
)
;
}
@Override
protected
int
[]
fetchDatabaseNameIndexRange
()
{
protected
URLLocation
fetchDatabaseNameIndexRange
()
{
int
databaseStartTag
=
url
.
lastIndexOf
(
"/"
);
int
databaseEndTag
=
url
.
indexOf
(
"?"
,
databaseStartTag
);
if
(
databaseEndTag
==
-
1
)
{
databaseEndTag
=
url
.
length
();
}
return
new
int
[]
{
databaseStartTag
+
1
,
databaseEndTag
}
;
return
new
URLLocation
(
databaseStartTag
+
1
,
databaseEndTag
)
;
}
@Override
public
ConnectionInfo
parse
()
{
int
[]
hostRangeIndex
=
fetchDatabaseHostsIndexRange
();
String
hosts
=
url
.
substring
(
hostRangeIndex
[
0
],
hostRangeIndex
[
1
]
);
URLLocation
location
=
fetchDatabaseHostsIndexRange
();
String
hosts
=
url
.
substring
(
location
.
startIndex
(),
location
.
endIndex
()
);
String
[]
hostSegment
=
hosts
.
split
(
","
);
if
(
hostSegment
.
length
>
1
)
{
StringBuilder
sb
=
new
StringBuilder
();
...
...
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/OracleURLParser.java
浏览文件 @
03824c2f
...
...
@@ -18,8 +18,11 @@
package
org.skywalking.apm.plugin.jdbc.connectionurl.parser
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.skywalking.apm.network.trace.component.ComponentsDefine
;
import
org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo
;
import
org.skywalking.apm.util.StringUtil
;
/**
* {@link OracleURLParser} presents that how to parse oracle connection url.
...
...
@@ -38,29 +41,61 @@ public class OracleURLParser extends AbstractURLParser {
private
static
final
String
DB_TYPE
=
"Oracle"
;
private
static
final
int
DEFAULT_PORT
=
1521
;
public
static
final
String
SERVICE_NAME_FLAG
=
"@//"
;
public
static
final
String
TNSNAME_URL_FLAG
=
"DESCRIPTION"
;
public
OracleURLParser
(
String
url
)
{
super
(
url
);
}
@Override
protected
int
[]
fetchDatabaseHostsIndexRange
()
{
int
hostLabelStartIndex
=
url
.
indexOf
(
"@"
);
protected
URLLocation
fetchDatabaseHostsIndexRange
()
{
int
hostLabelStartIndex
;
if
(
isServiceNameURL
())
{
hostLabelStartIndex
=
url
.
indexOf
(
SERVICE_NAME_FLAG
)
+
3
;
}
else
{
hostLabelStartIndex
=
url
.
indexOf
(
"@"
)
+
1
;
}
int
hostLabelEndIndex
=
url
.
lastIndexOf
(
":"
);
return
new
int
[]
{
hostLabelStartIndex
+
1
,
hostLabelEndIndex
}
;
return
new
URLLocation
(
hostLabelStartIndex
,
hostLabelEndIndex
)
;
}
@Override
protected
int
[]
fetchDatabaseNameIndexRange
()
{
return
new
int
[
0
];
protected
URLLocation
fetchDatabaseNameIndexRange
()
{
int
hostLabelStartIndex
;
int
hostLabelEndIndex
=
url
.
length
();
if
(
isServiceNameURL
())
{
hostLabelStartIndex
=
url
.
lastIndexOf
(
"/"
)
+
1
;
}
else
if
(
isTNSNameURL
())
{
hostLabelStartIndex
=
url
.
indexOf
(
"="
,
url
.
indexOf
(
"SERVICE_NAME"
))
+
1
;
hostLabelEndIndex
=
url
.
indexOf
(
")"
,
hostLabelStartIndex
);
}
else
{
hostLabelStartIndex
=
url
.
lastIndexOf
(
":"
)
+
1
;
}
return
new
URLLocation
(
hostLabelStartIndex
,
hostLabelEndIndex
);
}
private
boolean
isServiceNameURL
()
{
return
url
.
contains
(
SERVICE_NAME_FLAG
);
}
private
boolean
isTNSNameURL
()
{
return
url
.
contains
(
TNSNAME_URL_FLAG
);
}
@Override
public
ConnectionInfo
parse
()
{
int
[]
hostRangeIndex
=
fetchDatabaseHostsIndexRange
();
if
(
isTNSNameURL
())
{
return
tnsNameURLParse
();
}
else
{
return
commonsURLParse
();
}
}
private
ConnectionInfo
commonsURLParse
()
{
String
host
=
fetchDatabaseHostsFromURL
();
String
[]
hostSegment
=
splitDatabaseAddress
(
host
);
String
databaseName
=
url
.
substring
(
hostRangeIndex
[
1
]
+
1
);
String
databaseName
=
fetchDatabaseNameFromURL
(
);
if
(
hostSegment
.
length
==
1
)
{
return
new
ConnectionInfo
(
ComponentsDefine
.
ORACLE
,
DB_TYPE
,
host
,
DEFAULT_PORT
,
databaseName
);
}
else
{
...
...
@@ -68,6 +103,40 @@ public class OracleURLParser extends AbstractURLParser {
}
}
private
ConnectionInfo
tnsNameURLParse
()
{
String
host
=
parseDatabaseHostsFromURL
();
String
databaseName
=
fetchDatabaseNameFromURL
();
return
new
ConnectionInfo
(
ComponentsDefine
.
ORACLE
,
DB_TYPE
,
host
,
databaseName
);
}
private
String
parseDatabaseHostsFromURL
()
{
int
beginIndex
=
url
.
indexOf
(
"DESCRIPTION"
);
List
<
String
>
hosts
=
new
ArrayList
<
String
>();
do
{
int
hostStartIndex
=
url
.
indexOf
(
"HOST"
,
beginIndex
);
if
(
hostStartIndex
==
-
1
)
{
break
;
}
int
equalStartIndex
=
url
.
indexOf
(
"="
,
hostStartIndex
);
int
hostEndIndex
=
url
.
indexOf
(
")"
,
hostStartIndex
);
String
host
=
url
.
substring
(
equalStartIndex
+
1
,
hostEndIndex
);
int
port
=
DEFAULT_PORT
;
int
portStartIndex
=
url
.
indexOf
(
"PORT"
,
hostEndIndex
);
int
portEndIndex
=
url
.
length
();
if
(
portStartIndex
!=
-
1
)
{
int
portEqualStartIndex
=
url
.
indexOf
(
"="
,
portStartIndex
);
portEndIndex
=
url
.
indexOf
(
")"
,
portEqualStartIndex
);
port
=
Integer
.
parseInt
(
url
.
substring
(
portEqualStartIndex
+
1
,
portEndIndex
).
trim
());
}
hosts
.
add
(
host
.
trim
()
+
":"
+
port
);
beginIndex
=
portEndIndex
;
}
while
(
true
);
return
StringUtil
.
join
(
','
,
hosts
.
toArray
(
new
String
[
0
]));
}
private
String
[]
splitDatabaseAddress
(
String
address
)
{
String
[]
hostSegment
=
address
.
split
(
":"
);
return
hostSegment
;
...
...
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/PostgreSQLURLParser.java
浏览文件 @
03824c2f
...
...
@@ -41,26 +41,26 @@ public class PostgreSQLURLParser extends AbstractURLParser {
}
@Override
protected
int
[]
fetchDatabaseHostsIndexRange
()
{
protected
URLLocation
fetchDatabaseHostsIndexRange
()
{
int
hostLabelStartIndex
=
url
.
indexOf
(
"//"
);
int
hostLabelEndIndex
=
url
.
indexOf
(
"/"
,
hostLabelStartIndex
+
2
);
return
new
int
[]
{
hostLabelStartIndex
+
2
,
hostLabelEndIndex
}
;
return
new
URLLocation
(
hostLabelStartIndex
+
2
,
hostLabelEndIndex
)
;
}
@Override
protected
int
[]
fetchDatabaseNameIndexRange
()
{
protected
URLLocation
fetchDatabaseNameIndexRange
()
{
int
databaseStartTag
=
url
.
lastIndexOf
(
"/"
);
int
databaseEndTag
=
url
.
indexOf
(
"?"
,
databaseStartTag
);
if
(
databaseEndTag
==
-
1
)
{
databaseEndTag
=
url
.
length
();
}
return
new
int
[]
{
databaseStartTag
+
1
,
databaseEndTag
}
;
return
new
URLLocation
(
databaseStartTag
+
1
,
databaseEndTag
)
;
}
@Override
public
ConnectionInfo
parse
()
{
int
[]
hostRangeIndex
=
fetchDatabaseHostsIndexRange
();
String
hosts
=
url
.
substring
(
hostRangeIndex
[
0
],
hostRangeIndex
[
1
]
);
URLLocation
location
=
fetchDatabaseHostsIndexRange
();
String
hosts
=
url
.
substring
(
location
.
startIndex
(),
location
.
endIndex
()
);
String
[]
hostSegment
=
hosts
.
split
(
","
);
if
(
hostSegment
.
length
>
1
)
{
StringBuilder
sb
=
new
StringBuilder
();
...
...
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLLocation.java
0 → 100644
浏览文件 @
03824c2f
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.plugin.jdbc.connectionurl.parser
;
public
class
URLLocation
{
private
final
int
startIndex
;
private
final
int
endIndex
;
public
URLLocation
(
int
startIndex
,
int
endIndex
)
{
this
.
startIndex
=
startIndex
;
this
.
endIndex
=
endIndex
;
}
public
int
startIndex
()
{
return
startIndex
;
}
public
int
endIndex
()
{
return
endIndex
;
}
}
apm-sniffer/apm-sdk-plugin/jdbc-commons/src/test/java/org/skywalking/apm/plugin/jdbc/connectionurl/parser/URLParserTest.java
浏览文件 @
03824c2f
...
...
@@ -73,6 +73,30 @@ public class URLParserTest {
assertThat
(
connectionInfo
.
getDatabasePeer
(),
is
(
"localhost:1522"
));
}
@Test
public
void
testParseOracleServiceName
()
{
ConnectionInfo
connectionInfo
=
new
URLParser
().
parser
(
"jdbc:oracle:thin:@//localhost:1521/orcl"
);
assertThat
(
connectionInfo
.
getDBType
(),
is
(
"Oracle"
));
assertThat
(
connectionInfo
.
getDatabaseName
(),
is
(
"orcl"
));
assertThat
(
connectionInfo
.
getDatabasePeer
(),
is
(
"localhost:1521"
));
}
@Test
public
void
testParseOracleTNSName
()
{
ConnectionInfo
connectionInfo
=
new
URLParser
().
parser
(
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= localhost )(PORT= 1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
);
assertThat
(
connectionInfo
.
getDBType
(),
is
(
"Oracle"
));
assertThat
(
connectionInfo
.
getDatabaseName
(),
is
(
"orcl"
));
assertThat
(
connectionInfo
.
getDatabasePeer
(),
is
(
"localhost:1521"
));
}
@Test
public
void
testParseOracleTNSNameWithMultiAddress
()
{
ConnectionInfo
connectionInfo
=
new
URLParser
().
parser
(
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL= TCP)(HOST=hostA)(PORT= 1523 ))(ADDRESS=(PROTOCOL=TCP)(HOST=hostB)(PORT= 1521 )))(SOURCE_ROUTE=yes)(CONNECT_DATA=(SERVICE_NAME=orcl)))"
);
assertThat
(
connectionInfo
.
getDBType
(),
is
(
"Oracle"
));
assertThat
(
connectionInfo
.
getDatabaseName
(),
is
(
"orcl"
));
assertThat
(
connectionInfo
.
getDatabasePeer
(),
is
(
"hostA:1523,hostB:1521"
));
}
@Test
public
void
testParseOracleJDBCURLWithUserNameAndPassword
()
{
ConnectionInfo
connectionInfo
=
new
URLParser
().
parser
(
"jdbc:oracle:thin:scott/tiger@myhost:1521:orcl"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录