未验证 提交 7220643c 编写于 作者: Z zifeihan 提交者: GitHub

Add the plugin for mssql-jtds 1.x plugin. (#5842)

* Add the plugin for mssql-jtds 1.x plugin.
上级 ef1363d9
......@@ -60,6 +60,7 @@ jobs:
- mongodb-4.x-scenario
- netty-socketio-scenario
- postgresql-above9.4.1207-scenario
- mssql-jtds-scenario
steps:
- uses: actions/checkout@v2
with:
......
......@@ -18,6 +18,7 @@ Release Notes.
* Add the plugin for async-http-client 2.x
* Fix NPE in the nutz plugin.
* Provide Apache Commons DBCP 2.x plugin.
* Add the plugin for mssql-jtds 1.x plugin.
#### OAP-Backend
* Add the `@SuperDataset` annotation for BrowserErrorLog.
......
......@@ -188,4 +188,6 @@ public class ComponentsDefine {
public static final OfficialComponent ASYNC_HTTP_CLIENT = new OfficialComponent(102, "AsyncHttpClient");
public static final OfficialComponent DBCP = new OfficialComponent(103, "dbcp");
public static final OfficialComponent MSSQL_JDBC_DRIVER = new OfficialComponent(104, "mssql-jdbc-driver");
}
/*
* 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.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.apache.skywalking.apm.network.trace.component.OfficialComponent;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
/**
* {@link MssqlJtdsURLParser} parse connection url of mssql.
*/
public class MssqlJtdsURLParser extends AbstractURLParser {
private static final int DEFAULT_PORT = 1433;
private String dbType = "Mssql";
private OfficialComponent component = ComponentsDefine.MSSQL_JDBC_DRIVER;
private static ILog LOGGER = LogManager.getLogger(MssqlJtdsURLParser.class);
public MssqlJtdsURLParser(String url) {
super(url);
}
public MssqlJtdsURLParser(String url, String dbType, OfficialComponent component) {
super(url);
this.dbType = dbType;
this.component = component;
}
@Override
protected URLLocation fetchDatabaseHostsIndexRange() {
int hostLabelStartIndex = url.indexOf("//");
int hostLabelEndIndex = url.indexOf(";", hostLabelStartIndex + 2);
if (hostLabelEndIndex == -1) {
hostLabelEndIndex = url.indexOf("/", hostLabelStartIndex + 2);
}
return new URLLocation(hostLabelStartIndex + 2, hostLabelEndIndex);
}
protected String fetchDatabaseNameFromURL(int startSize) {
URLLocation hostsLocation = fetchDatabaseNameIndexRange(startSize);
if (hostsLocation == null) {
return "";
}
return url.substring(hostsLocation.startIndex(), hostsLocation.endIndex());
}
protected URLLocation fetchDatabaseNameIndexRange(int startSize) {
int databaseStartTag = url.indexOf("/", startSize);
if (databaseStartTag == -1) {
return null;
}
int databaseEndTag = url.indexOf(";", databaseStartTag);
if (databaseEndTag == -1) {
databaseEndTag = url.length();
}
return new URLLocation(databaseStartTag + 1, databaseEndTag);
}
@Override
protected URLLocation fetchDatabaseNameIndexRange() {
int databaseStartTag = url.lastIndexOf("/");
int databaseEndTag = url.indexOf(";", databaseStartTag);
if (databaseEndTag == -1) {
databaseEndTag = url.length();
}
return new URLLocation(databaseStartTag + 1, databaseEndTag);
}
@Override
public ConnectionInfo parse() {
try {
URLLocation location = fetchDatabaseHostsIndexRange();
String hosts = url.substring(location.startIndex(), location.endIndex());
String[] hostSegment = hosts.split(",");
if (hostSegment.length > 1) {
StringBuilder sb = new StringBuilder();
for (String host : hostSegment) {
if (host.split(":").length == 1) {
sb.append(host).append(":").append(DEFAULT_PORT).append(",");
} else {
sb.append(host).append(",");
}
}
return new ConnectionInfo(
component, dbType, sb.substring(0, sb.length() - 1), fetchDatabaseNameFromURL());
} else {
String[] hostAndPort = hostSegment[0].split(":");
if (hostAndPort.length != 1) {
return new ConnectionInfo(
component, dbType, hostAndPort[0], Integer.valueOf(hostAndPort[1]),
fetchDatabaseNameFromURL(location.endIndex())
);
} else {
return new ConnectionInfo(
component, dbType, hostAndPort[0], DEFAULT_PORT, fetchDatabaseNameFromURL(location
.endIndex()));
}
}
} catch (Exception e) {
LOGGER.error(e, "parse mssql connection info error, url:{}", url);
return new ConnectionInfo(component, dbType, url, "UNKNOWN");
}
}
}
......@@ -31,6 +31,7 @@ public class URLParser {
private static final String H2_JDBC_URL_PREFIX = "jdbc:h2";
private static final String POSTGRESQL_JDBC_URL_PREFIX = "jdbc:postgresql";
private static final String MARIADB_JDBC_URL_PREFIX = "jdbc:mariadb";
private static final String MSSQL_JTDS_URL_PREFIX = "jdbc:jtds:sqlserver:";
public static ConnectionInfo parser(String url) {
ConnectionURLParser parser = null;
......@@ -45,6 +46,8 @@ public class URLParser {
parser = new PostgreSQLURLParser(url);
} else if (lowerCaseUrl.startsWith(MARIADB_JDBC_URL_PREFIX)) {
parser = new MariadbURLParser(url);
} else if (lowerCaseUrl.startsWith(MSSQL_JTDS_URL_PREFIX)) {
parser = new MssqlJtdsURLParser(url);
}
return parser.parse();
}
......
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-sdk-plugin</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>8.3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-mssql-jtds-1.x-plugin</artifactId>
<packaging>jar</packaging>
<name>mssql-jtds-1.x-plugin</name>
<url>http://maven.apache.org</url>
<properties>
<mssql-jtds.version>1.2.6</mssql-jtds.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-jdbc-commons</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${mssql-jtds.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* 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.mssql.jtds.v1.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.plugin.jdbc.define.Constants;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
/**
* {@link AbstractConnectionInstrumentation} define how to enhance the following methods that the class which extend
* {@link java.sql.Connection}.
* <p>
* 1. Enhance <code>prepareStatement</code> by <code>org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor</code>
* 2. Enhance <code>prepareCall</code> by <code>org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor</code>
* 3. Enhance <code>createStatement</code> by <code>org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor</code>
* 4. Enhance <code>commit, rollback, close, releaseSavepoint</code> by <code>org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor</code>
*/
public abstract class AbstractConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(1));
}
@Override
public String getMethodsInterceptor() {
return Constants.PREPARE_STATEMENT_INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(3));
}
@Override
public String getMethodsInterceptor() {
return Constants.PREPARE_STATEMENT_INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(4));
}
@Override
public String getMethodsInterceptor() {
return Constants.PREPARE_STATEMENT_INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(Constants.PREPARE_CALL_METHOD_NAME);
}
@Override
public String getMethodsInterceptor() {
return Constants.PREPARE_CALL_INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(Constants.CREATE_STATEMENT_METHOD_NAME);
}
@Override
public String getMethodsInterceptor() {
return Constants.CREATE_STATEMENT_INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(Constants.COMMIT_METHOD_NAME).or(named(Constants.ROLLBACK_METHOD_NAME))
.or(named(Constants.CLOSE_METHOD_NAME))
.or(named(Constants.RELEASE_SAVE_POINT_METHOD_NAME));
}
@Override
public String getMethodsInterceptor() {
return Constants.SERVICE_METHOD_INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}
/*
* 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.mssql.jtds.v1.define;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch;
/**
* {@link ConnectionInstrumentation} presents that skywalking intercepts.
*/
public class ConnectionInstrumentation extends AbstractConnectionInstrumentation {
public static final String ENHANCE_CONNECTION_JDBC2_CLASS = "net.sourceforge.jtds.jdbc.ConnectionJDBC2";
public static final String ENHANCE_JTDS_CONNECTION_CLASS = "net.sourceforge.jtds.jdbc.JtdsConnection";
@Override
protected ClassMatch enhanceClass() {
return MultiClassNameMatch.byMultiClassMatch(ENHANCE_CONNECTION_JDBC2_CLASS, ENHANCE_JTDS_CONNECTION_CLASS);
}
}
/*
* 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.mssql.jtds.v1.define;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link DriverInstrumentation} presents that skywalking intercepts {@link net.sourceforge.jtds.jdbc.Driver}.
*/
public class DriverInstrumentation extends AbstractDriverInstrumentation {
private static final String ENHANCE_CLASS = "net.sourceforge.jtds.jdbc.Driver";
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
}
# 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.
mssql-jtds-1.x=org.apache.skywalking.apm.plugin.mssql.jtds.v1.define.DriverInstrumentation
mssql-jtds-1.x=org.apache.skywalking.apm.plugin.mssql.jtds.v1.define.ConnectionInstrumentation
......@@ -104,6 +104,7 @@
<module>httpclient-commons</module>
<module>asynchttpclient-2.x-plugin</module>
<module>dbcp-2.x-plugin</module>
<module>mssql-jtds-1.x-plugin</module>
</modules>
<packaging>pom</packaging>
......
......@@ -109,3 +109,4 @@
- vertx-core-3.x
- xxl-job-2.x
- zookeeper-3.4.x
- mssql-jtds-1.x
\ No newline at end of file
......@@ -39,6 +39,7 @@ metrics based on the tracing data.
* PostgreSQL Driver 8.x, 9.x, 42.x
* Mariadb Driver 2.x, 1.8
* [InfluxDB](https://github.com/influxdata/influxdb-java) 2.5 -> 2.17
* [Mssql-Jtds](https://github.com/milesibastos/jTDS) 1.x
* RPC Frameworks
* [Dubbo](https://github.com/alibaba/dubbo) 2.5.4 -> 2.6.0
* [Dubbox](https://github.com/dangdangdotcom/dubbox) 2.8.4
......
......@@ -341,6 +341,9 @@ AsyncHttpClient:
dbcp:
id: 103
languages: Java
mssql-jdbc-driver:
id: 104
languages: Java
# .NET/.NET Core components
# [3000, 4000) for C#/.NET only
......@@ -361,7 +364,7 @@ StackExchange.Redis:
languages: C#
SqlServer:
id: 3006
languages: C#
languages: C#,Java
Npgsql:
id: 3007
languages: C#
......@@ -537,4 +540,5 @@ Component-Server-Mappings:
influxdb-java: InfluxDB
Predis: Redis
PyMysql: Mysql
spring-kafka-consumer: kafka-consumer
\ No newline at end of file
spring-kafka-consumer: kafka-consumer
mssql-jdbc-driver: SqlServer
\ No newline at end of file
#!/bin/bash
#
# 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.
home="$(cd "$(dirname $0)"; pwd)"
java -jar ${agent_opts} ${home}/../libs/mssql-jtds-scenario.jar &
\ No newline at end of file
# 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.
segmentItems:
- serviceName: mssql-jtds-scenario
segmentSize: ge 2
segments:
- segmentId: not null
spans:
- operationName: Mssql/JDBI/PreparedStatement/execute
operationId: eq 0
parentSpanId: 0
spanId: 1
tags:
- {key: db.type, value: sql}
- {key: db.instance, value: tempdb}
- key: db.statement
value: "CREATE TABLE test_007(\nid VARCHAR(1) PRIMARY KEY, \nvalue VARCHAR(1)\
\ NOT NULL)"
logs: []
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentId: 104
peer: mssql-server:1433
skipAnalysis: 'false'
- operationName: Mssql/JDBI/PreparedStatement/execute
operationId: eq 0
parentSpanId: 0
spanId: 2
tags:
- {key: db.type, value: sql}
- {key: db.instance, value: tempdb}
- {key: db.statement, value: 'INSERT INTO test_007(id, value) VALUES(?,?)'}
logs: []
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentId: 104
peer: mssql-server:1433
skipAnalysis: 'false'
- operationName: Mssql/JDBI/Statement/execute
operationId: eq 0
parentSpanId: 0
spanId: 3
tags:
- {key: db.type, value: sql}
- {key: db.instance, value: tempdb}
- {key: db.statement, value: DROP table test_007}
logs: []
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentId: 104
peer: mssql-server:1433
skipAnalysis: 'false'
- operationName: Mssql/JDBI/Connection/close
operationId: eq 0
parentSpanId: 0
spanId: 4
tags:
- {key: db.type, value: sql}
- {key: db.instance, value: tempdb}
- {key: db.statement, value: ''}
logs: []
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentId: 104
peer: mssql-server:1433
skipAnalysis: 'false'
- operationName: /mssql-jtds-scenario/case/mssql-jtds-scenario
operationId: eq 0
parentSpanId: -1
spanId: 0
startTime: nq 0
endTime: nq 0
spanLayer: Http
isError: false
spanType: Entry
componentId: 1
tags:
- {key: url, value: 'http://localhost:8080/mssql-jtds-scenario/case/mssql-jtds-scenario'}
- {key: http.method, value: GET}
logs: []
skipAnalysis: 'false'
# 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.
type: jvm
entryService: http://localhost:8080/mssql-jtds-scenario/case/mssql-jtds-scenario
healthCheck: http://localhost:8080/mssql-jtds-scenario/case/healthCheck
startScript: ./bin/startup.sh
environment:
depends_on:
- mssql-server
dependencies:
mssql-server:
image: microsoft/mssql-server-linux
hostname: mssql-server
expose:
- "1433"
environment:
- SA_PASSWORD=yourStrong(!)Password
- ACCEPT_EULA=Y
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.apache.skywalking.apm.testcase</groupId>
<artifactId>mssql-jtds-scenario</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>1.8</compiler.version>
<test.framework.version>1.3.1</test.framework.version>
<docker.image.version>${test.framework.version}</docker.image.version>
<spring-boot-version>2.1.6.RELEASE</spring-boot-version>
</properties>
<name>skywalking-mssql-jtds-scenario</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${test.framework.version}</version>
</dependency>
</dependencies>
<build>
<finalName>mssql-jtds-scenario</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assemble</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<outputDirectory>./target/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>./bin</directory>
<fileMode>0775</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>${project.build.directory}/mssql-jtds-scenario.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
</files>
</assembly>
/*
* 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.testcase.mssql;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
try {
SpringApplication.run(Application.class, args);
} catch (Exception e) {
// Never do this
}
}
}
/*
* 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.testcase.mssql;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class MssqlConfig {
private static final Logger LOGGER = LogManager.getLogger(MssqlConfig.class);
private static String url;
private static String userName;
private static String password;
static {
InputStream inputStream = MssqlConfig.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties properties = new Properties();
try {
properties.load(inputStream);
} catch (IOException e) {
LOGGER.error("Failed to load config", e);
}
url = properties.getProperty("mssql.url");
userName = properties.getProperty("mssql.username");
password = properties.getProperty("mssql.password");
}
public static String getUrl() {
return url;
}
public static String getUserName() {
return userName;
}
public static String getPassword() {
return password;
}
}
/*
* 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.testcase.mssql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class SQLExecutor implements AutoCloseable {
private Connection connection;
public SQLExecutor() throws SQLException {
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
connection = DriverManager.getConnection(MssqlConfig.getUrl(), MssqlConfig.getUserName(), MssqlConfig.getPassword());
}
public void createTable(String sql) throws SQLException {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.execute();
preparedStatement.close();
}
public void insertData(String sql, String id, String value) throws SQLException {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, id);
preparedStatement.setString(2, value);
preparedStatement.execute();
preparedStatement.close();
}
public void dropTable(String sql) throws SQLException {
executeStatement(sql);
}
public void createProcedure(String sql) throws SQLException {
executeStatement(sql);
}
public void dropProcedure(String sql) throws SQLException {
executeStatement(sql);
}
public void callProcedure(String sql, String id) throws SQLException {
PreparedStatement preparedStatement = connection.prepareCall(sql);
preparedStatement.setString(1, id);
preparedStatement.execute();
preparedStatement.close();
}
public void executeStatement(String sql) throws SQLException {
Statement preparedStatement = connection.createStatement();
preparedStatement.execute(sql);
preparedStatement.close();
}
public void closeConnection() throws SQLException {
if (this.connection != null) {
this.connection.close();
}
}
@Override
public void close() throws Exception {
closeConnection();
}
}
/*
* 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.testcase.mssql.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.apm.testcase.mssql.SQLExecutor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/case")
public class CaseController {
private static final Logger LOGGER = LogManager.getLogger(CaseController.class);
private static final String SUCCESS = "Success";
private static final String CREATE_TABLE_SQL = "CREATE TABLE test_007(\n" + "id VARCHAR(1) PRIMARY KEY, \n" + "value VARCHAR(1) NOT NULL)";
private static final String INSERT_DATA_SQL = "INSERT INTO test_007(id, value) VALUES(?,?)";
private static final String QUERY_DATA_SQL = "SELECT id, value FROM test_007 WHERE id=?";
private static final String DELETE_DATA_SQL = "DELETE FROM test_007 WHERE id=?";
private static final String DROP_TABLE_SQL = "DROP table test_007";
@RequestMapping("/mssql-jtds-scenario")
@ResponseBody
public String testcase() throws Exception {
try (SQLExecutor sqlExecute = new SQLExecutor()) {
sqlExecute.createTable(CREATE_TABLE_SQL);
sqlExecute.insertData(INSERT_DATA_SQL, "1", "1");
sqlExecute.dropTable(DROP_TABLE_SQL);
} catch (Exception e) {
LOGGER.error("Failed to execute sql.", e);
throw e;
}
return SUCCESS;
}
@RequestMapping("/healthCheck")
@ResponseBody
public String healthCheck() throws Exception {
try (SQLExecutor sqlExecutor = new SQLExecutor()) {
// ignore
}
return SUCCESS;
}
}
#
# 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.
#
#
server:
port: 8080
servlet:
context-path: /mssql-jtds-scenario
logging:
config: classpath:log4j2.xml
\ No newline at end of file
# 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
# "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.
mssql.url=jdbc:jtds:sqlserver://mssql-server:1433/tempdb
mssql.username=SA
mssql.password=yourStrong(!)Password
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_ERR">
<PatternLayout charset="UTF-8" pattern="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="WARN">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
# 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
# "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.
1.2.2
1.2.4
1.2.6
1.2.7
1.2.8
1.3.0
1.3.1
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册