Merge branch 'master' into master
This commit is contained in:
commit
370395b393
|
|
@ -67,6 +67,8 @@ public class ComponentsDefine {
|
|||
|
||||
public static final OfficialComponent SHARDING_JDBC = new OfficialComponent(21, "ShardingJDBC");
|
||||
|
||||
public static final OfficialComponent POSTGRESQL = new OfficialComponent(22, "PostgreSQL");
|
||||
|
||||
private static ComponentsDefine instance = new ComponentsDefine();
|
||||
|
||||
private String[] components;
|
||||
|
|
@ -76,7 +78,7 @@ public class ComponentsDefine {
|
|||
}
|
||||
|
||||
public ComponentsDefine() {
|
||||
components = new String[22];
|
||||
components = new String[23];
|
||||
addComponent(TOMCAT);
|
||||
addComponent(HTTPCLIENT);
|
||||
addComponent(DUBBO);
|
||||
|
|
@ -98,6 +100,7 @@ public class ComponentsDefine {
|
|||
addComponent(JETTY_SERVER);
|
||||
addComponent(MEMCACHED);
|
||||
addComponent(SHARDING_JDBC);
|
||||
addComponent(POSTGRESQL);
|
||||
}
|
||||
|
||||
private void addComponent(OfficialComponent component) {
|
||||
|
|
|
|||
|
|
@ -60,6 +60,12 @@
|
|||
<version>[2.0.14,6.0.6]</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import org.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
import org.skywalking.apm.plugin.jdbc.ConnectionInfo;
|
||||
|
||||
/**
|
||||
* {@link PostgreSQLURLParser} parse connection url of mysql.
|
||||
* <p>
|
||||
* The {@link ConnectionInfo#host} be set the string between charset "//" and the first
|
||||
* charset "/" after the charset "//", and {@link ConnectionInfo#databaseName} be set the
|
||||
* string between the last index of "/" and the first charset "?". but one more thing, the
|
||||
* {@link ConnectionInfo#hosts} be set if the host container multiple host.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class PostgreSQLURLParser extends AbstractURLParser {
|
||||
|
||||
private static final int DEFAULT_PORT = 5432;
|
||||
private static final String DB_TYPE = "PostgreSQL";
|
||||
|
||||
public PostgreSQLURLParser(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[] fetchDatabaseHostsIndexRange() {
|
||||
int hostLabelStartIndex = url.indexOf("//");
|
||||
int hostLabelEndIndex = url.indexOf("/", hostLabelStartIndex + 2);
|
||||
return new int[] {hostLabelStartIndex + 2, hostLabelEndIndex};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int[] fetchDatabaseNameIndexRange() {
|
||||
int databaseStartTag = url.lastIndexOf("/");
|
||||
int databaseEndTag = url.indexOf("?", databaseStartTag);
|
||||
if (databaseEndTag == -1) {
|
||||
databaseEndTag = url.length();
|
||||
}
|
||||
return new int[] {databaseStartTag + 1, databaseEndTag};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionInfo parse() {
|
||||
int[] hostRangeIndex = fetchDatabaseHostsIndexRange();
|
||||
String hosts = url.substring(hostRangeIndex[0], hostRangeIndex[1]);
|
||||
String[] hostSegment = hosts.split(",");
|
||||
if (hostSegment.length > 1) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String host : hostSegment) {
|
||||
if (host.split(":").length == 1) {
|
||||
sb.append(host + ":" + DEFAULT_PORT + ",");
|
||||
} else {
|
||||
sb.append(host + ",");
|
||||
}
|
||||
}
|
||||
return new ConnectionInfo(ComponentsDefine.POSTGRESQL, DB_TYPE, sb.toString(), fetchDatabaseNameFromURL());
|
||||
} else {
|
||||
String[] hostAndPort = hostSegment[0].split(":");
|
||||
if (hostAndPort.length != 1) {
|
||||
return new ConnectionInfo(ComponentsDefine.POSTGRESQL, DB_TYPE, hostAndPort[0], Integer.valueOf(hostAndPort[1]), fetchDatabaseNameFromURL());
|
||||
} else {
|
||||
return new ConnectionInfo(ComponentsDefine.POSTGRESQL, DB_TYPE, hostAndPort[0], DEFAULT_PORT, fetchDatabaseNameFromURL());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,8 +21,8 @@ package org.skywalking.apm.plugin.jdbc.connectionurl.parser;
|
|||
import org.skywalking.apm.plugin.jdbc.ConnectionInfo;
|
||||
|
||||
/**
|
||||
* {@link URLParser#parser(String)} support parse the connection url, such as Mysql, Oracle, H2 Database.
|
||||
* But there are some url cannot be parsed, such as Oracle connection url with multiple host.
|
||||
* {@link URLParser#parser(String)} support parse the connection url, such as Mysql, Oracle, H2 Database. But there are
|
||||
* some url cannot be parsed, such as Oracle connection url with multiple host.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
|
|
@ -31,6 +31,7 @@ public class URLParser {
|
|||
private static final String MYSQL_JDBC_URL_PREFIX = "jdbc:mysql";
|
||||
private static final String ORACLE_JDBC_URL_PREFIX = "jdbc:oracle";
|
||||
private static final String H2_JDBC_URL_PREFIX = "jdbc:h2";
|
||||
private static final String POSTGRESQL_JDBC_URL_PREFIX = "jdbc:postgresql";
|
||||
|
||||
public static ConnectionInfo parser(String url) {
|
||||
ConnectionURLParser parser = null;
|
||||
|
|
@ -40,6 +41,8 @@ public class URLParser {
|
|||
parser = new OracleURLParser(url);
|
||||
} else if (url.startsWith(H2_JDBC_URL_PREFIX)) {
|
||||
parser = new H2URLParser(url);
|
||||
} else if (url.startsWith(POSTGRESQL_JDBC_URL_PREFIX)) {
|
||||
parser = new PostgreSQLURLParser(url);
|
||||
}
|
||||
return parser.parse();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.define;
|
||||
|
||||
import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
|
||||
import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
/**
|
||||
* {@link PostgreSQLInstrumentation} presents that skywalking intercepts {@link org.postgresql.Driver}.
|
||||
*
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class PostgreSQLInstrumentation extends AbstractDatabaseInstrumentation {
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return byName("org.postgresql.Driver");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
jdbc=org.skywalking.apm.plugin.jdbc.define.H2Instrumentation
|
||||
jdbc=org.skywalking.apm.plugin.jdbc.define.MysqlInstrumentation
|
||||
jdbc=org.skywalking.apm.plugin.jdbc.define.OracleInstrumentation
|
||||
jdbc=org.skywalking.apm.plugin.jdbc.define.OracleInstrumentation
|
||||
jdbc=org.skywalking.apm.plugin.jdbc.define.PostgreSQLInstrumentation
|
||||
|
|
|
|||
Loading…
Reference in New Issue