提交 aa18eb69 编写于 作者: A aderm 提交者: wu-sheng

[test/plugin] immigrate postgresql scenario (#3644)

* Modify plugin test run.sh script parameter error

* shell fun error, delete ()

* delete space line

* [test/plugin] immigrate postgresql scenario

* add licene

* format expectedData.yaml & update support-version.list

* change workload from 3 to 1

* add startup.sh

* update startup.sh

* Add verify health-check segment

* remove health-check segment

* update code. 1. context is not effective; 2.format code. 3.change log to slf4j;

* update expectedData.yaml & change log to log4j2

* Add stage case count

* add immigrate postgresql-9.4-scenario

* repair module name & package name

* repair all postgresql-9.4 to postgresql-above9.4.1207

* change module name to postgresql-above9.4.1207

* change stage name
上级 89c320bf
......@@ -107,4 +107,4 @@ pipeline {
deleteDir()
}
}
}
\ No newline at end of file
}
......@@ -54,7 +54,7 @@ pipeline {
sh './mvnw -f test/plugin/pom.xml clean package -DskipTests -Dbuild_id=${BUILD_ID} docker:build'
}
}
stage('Test Cases Report (21)') {
stage('Test Cases Report (73)') {
steps {
echo "reserve."
}
......@@ -77,9 +77,14 @@ pipeline {
}
stage('Group2') {
stages {
stage('reserve stages') {
stage('postgresql 9.2.x-9.4.x (36)') {
steps {
echo "reserve."
sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} postgresql-scenario'
}
}
stage('postgresql-9.4.1207+ (16)') {
steps {
sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} postgresql-above9.4.1207-scenario'
}
}
}
......
# 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.
registryItems:
applications:
- {postgresql-above9.4.1207-scenario: nq 0}
instances:
- {postgresql-above9.4.1207-scenario: 1}
operationNames:
- postgresql-above9.4.1207-scenario: [/postgresql-scenario/case/postgres, PostgreSQL/JDBI/PreparedStatement/executeWithFlags,
PostgreSQL/JDBI/CallableStatement/executeWithFlags, PostgreSQL/JDBI/Statement/execute,
PostgreSQL/JDBI/Connection/close]
segmentItems:
- applicationCode: postgresql-above9.4.1207-scenario
segmentSize: ge 1
segments:
- segmentId: not null
spans:
- operationName: PostgreSQL/JDBI/PreparedStatement/executeWithFlags
operationId: eq 0
parentSpanId: 0
spanId: 1
tags:
- {key: "db.type", value: "sql"}
- {key: "db.instance", value: "postgres"}
- {key: "db.statement", value: "CREATE TABLE test_007(\nid VARCHAR(1) PRIMARY KEY, \nvalue VARCHAR(1) NOT NULL)"}
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentName: null
componentId: 37
peer: postgresql-server:5432
peerId: eq 0
- operationName: PostgreSQL/JDBI/CallableStatement/executeWithFlags
operationId: eq 0
parentSpanId: 0
spanId: 2
tags:
- {key: "db.type", value: "sql"}
- {key: "db.instance", value: "postgres"}
- {key: "db.statement", value: "INSERT INTO test_007(id, value) VALUES(?,?)"}
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentName: null
componentId: 37
peer: postgresql-server:5432
peerId: eq 0
- operationName: PostgreSQL/JDBI/Statement/execute
operationId: eq 0
parentSpanId: 0
spanId: 3
tags:
- {key: "db.type", value: "sql"}
- {key: "db.instance", value: "postgres"}
- {key: "db.statement", value: "DROP table test_007"}
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentName: null
componentId: 37
peer: postgresql-server:5432
peerId: eq 0
- operationName: PostgreSQL/JDBI/Connection/close
operationId: eq 0
parentSpanId: 0
spanId: 4
tags:
- {key: "db.type", value: "sql"}
- {key: "db.instance", value: "postgres"}
- {key: "db.statement", value: ""}
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentName: null
componentId: 37
peer: postgresql-server:5432
peerId: eq 0
- operationName: /postgresql-scenario/case/postgres
operationId: eq 0
parentSpanId: -1
spanId: 0
startTime: nq 0
endTime: nq 0
spanLayer: Http
isError: false
spanType: Entry
componentName: null
componentId: 1
tags:
- {key: url, value: 'http://localhost:8080/postgresql-scenario/case/postgres'}
- {key: http.method, value: GET}
peer: null
peerId: eq 0
# 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/postgresql-scenario/case/postgres
healthCheck: http://localhost:8080/postgresql-scenario/case/healthcheck
startScript: ./bin/startup.sh
framework: PostgreSQL
environment:
- POSTGRESQL_SERVER=postgresql-server:5432
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
dependencies:
postgresql-server:
image: postgres:9.3-alpine
hostname: postgresql-server
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.skywalking</groupId>
<artifactId>postgresql-above9.4.1207-scenario</artifactId>
<version>5.0.0</version>
<name>skywalking-postgresql-above9.4.1207-scenario</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>1.8</compiler.version>
<test.framework.version>9.4-1206-jdbc42</test.framework.version>
<docker.image.version>${test.framework.version}</docker.image.version>
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>
<lombok.version>1.16.20</lombok.version>
<log4j.version>2.8.1</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${test.framework.version}</version>
</dependency>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
<build>
<finalName>postgresql-above9.4.1207-scenario</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.9.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</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>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?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}/postgresql-above9.4.1207-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.postgresql;
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.postgresql.controller;
import java.sql.SQLException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/postgresql-scenario/case")
public class CaseController {
private static Logger logger = LogManager.getLogger(CaseController.class);
@Autowired
PostgresqlConfig postgresqlConfig;
@GetMapping("/healthcheck")
public String healthcheck() throws Exception {
SQLExecutor sqlExecute = null;
try {
sqlExecute = new SQLExecutor(postgresqlConfig);
sqlExecute.checkPG(ConstSql.TEST_SQL);
} catch (SQLException e) {
logger.error("Failed to execute sql.", e);
throw e;
} finally {
if (sqlExecute != null) {
try {
sqlExecute.closeConnection();
} catch (SQLException e) {
logger.error("Failed to close connection.", e);
}
}
}
return "Success";
}
@GetMapping("/postgres")
public String postgres() throws SQLException {
logger.info("Begin to start execute sql");
SQLExecutor sqlExecute = null;
try {
sqlExecute = new SQLExecutor(postgresqlConfig);
sqlExecute.createTable(ConstSql.CREATE_TABLE_SQL);
sqlExecute.insertData(ConstSql.INSERT_DATA_SQL, "1", "1");
sqlExecute.dropTable(ConstSql.DROP_TABLE_SQL);
} catch (SQLException e) {
logger.error("Failed to execute sql.", e);
throw e;
} finally {
if (sqlExecute != null) {
try {
sqlExecute.closeConnection();
} catch (SQLException e) {
logger.error("Failed to close connection.", e);
}
}
}
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.
*
*/
package org.apache.skywalking.apm.testcase.postgresql.controller;
public class ConstSql {
public static final String TEST_SQL = "SELECT 1";
public static final String CREATE_TABLE_SQL = "CREATE TABLE test_007(\n" +
"id VARCHAR(1) PRIMARY KEY, \n" +
"value VARCHAR(1) NOT NULL)";
public static final String INSERT_DATA_SQL = "INSERT INTO test_007(id, value) VALUES(?,?)";
public static final String DROP_TABLE_SQL = "DROP table test_007";
}
/*
* 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.postgresql.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
public class PostgresqlConfig {
@Value("${POSTGRESQL_SERVER}")
private String host;
@Value("${POSTGRES_DB}")
private String db;
@Value("${POSTGRES_USER}")
private String user;
@Value("${POSTGRES_PASSWORD}")
private String password;
public String getUrl() {
return "jdbc:postgresql://" + host + "/" + db;
}
public String getUserName() {
return user;
}
public 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.postgresql.controller;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class SQLExecutor {
private Connection connection;
public SQLExecutor(PostgresqlConfig postgresqlConfig) throws SQLException {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
//
}
connection = DriverManager.getConnection(postgresqlConfig.getUrl(), postgresqlConfig.getUserName(), postgresqlConfig.getPassword());
}
public void checkPG(String sql) throws SQLException {
Statement preparedStatement = connection.createStatement();
preparedStatement.execute(sql);
}
public void createTable(String sql) throws SQLException {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.execute();
}
public void insertData(String sql, String id, String value) throws SQLException {
CallableStatement preparedStatement = connection.prepareCall(sql);
preparedStatement.setString(1, id);
preparedStatement.setString(2, value);
preparedStatement.execute();
}
public void dropTable(String sql) throws SQLException {
Statement preparedStatement = connection.createStatement();
preparedStatement.execute(sql);
}
public void closeConnection() throws SQLException {
if (this.connection != null) {
this.connection.close();
}
}
}
# 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
<?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 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.
9.4.1207
9.4.1208
9.4.1209
9.4.1210
9.4.1211
9.4.1212
9.4.1208.jre7
9.4.1208.jre6
9.4.1209.jre7
9.4.1209.jre6
9.4.1210.jre6
9.4.1210.jre7
9.4.1211.jre6
9.4.1211.jre7
9.4.1212.jre6
9.4.1212.jre7
#!/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/postgresql-scenario.jar &
# 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.
registryItems:
applications:
- {postgresql-scenario: nq 0}
instances:
- {postgresql-scenario: 1}
operationNames:
- postgresql-scenario: [/postgresql-scenario/case/postgres, PostgreSQL/JDBI/PreparedStatement/execute,
PostgreSQL/JDBI/CallableStatement/execute, PostgreSQL/JDBI/Statement/execute,
PostgreSQL/JDBI/Connection/close]
heartbeat: []
segmentItems:
- applicationCode: postgresql-scenario
segmentSize: ge 1
segments:
- segmentId: not null
spans:
- operationName: PostgreSQL/JDBI/PreparedStatement/execute
operationId: eq 0
parentSpanId: 0
spanId: 1
tags:
- {key: "db.type", value: "sql"}
- {key: "db.instance", value: "postgres"}
- {key: "db.statement", value: "CREATE TABLE test_007(\nid VARCHAR(1) PRIMARY KEY, \nvalue VARCHAR(1) NOT NULL)"}
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentName: ''
componentId: 37
peer: postgresql-server:5432
peerId: eq 0
- operationName: PostgreSQL/JDBI/CallableStatement/execute
operationId: eq 0
parentSpanId: 0
spanId: 2
tags:
- {key: "db.type", value: "sql"}
- {key: "db.instance", value: "postgres"}
- {key: "db.statement", value: "INSERT INTO test_007(id, value) VALUES(?,?)"}
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentName: ''
componentId: 37
peer: postgresql-server:5432
peerId: eq 0
- operationName: PostgreSQL/JDBI/Statement/execute
operationId: eq 0
parentSpanId: 0
spanId: 3
tags:
- {key: "db.type", value: "sql"}
- {key: "db.instance", value: "postgres"}
- {key: "db.statement", value: "DROP table test_007"}
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentName: ''
componentId: 37
peer: postgresql-server:5432
peerId: eq 0
- operationName: PostgreSQL/JDBI/Connection/close
operationId: eq 0
parentSpanId: 0
spanId: 4
tags:
- {key: "db.type", value: "sql"}
- {key: "db.instance", value: "postgres"}
- {key: "db.statement", value: ""}
startTime: nq 0
endTime: nq 0
isError: false
spanLayer: Database
spanType: Exit
componentName: ''
componentId: 37
peer: postgresql-server:5432
peerId: eq 0
- operationName: /postgresql-scenario/case/postgres
operationId: eq 0
parentSpanId: -1
spanId: 0
startTime: nq 0
endTime: nq 0
spanLayer: Http
isError: false
spanType: Entry
componentName: ''
componentId: 1
tags:
- {key: url, value: 'http://localhost:8080/postgresql-scenario/case/postgres'}
- {key: http.method, value: GET}
peer: null
peerId: eq 0
# 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/postgresql-scenario/case/postgres
healthCheck: http://localhost:8080/postgresql-scenario/case/healthcheck
startScript: ./bin/startup.sh
framework: PostgreSQL
environment:
- POSTGRESQL_SERVER=postgresql-server:5432
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
dependencies:
postgresql-server:
image: postgres:9.3-alpine
hostname: postgresql-server
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.skywalking</groupId>
<artifactId>postgresql-scenario</artifactId>
<version>5.0.0</version>
<name>skywalking-postgresql-scenario</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>1.8</compiler.version>
<test.framework.version>9.4-1200-jdbc41</test.framework.version>
<docker.image.version>${test.framework.version}</docker.image.version>
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>
<lombok.version>1.16.20</lombok.version>
<log4j.version>2.8.1</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${test.framework.version}</version>
</dependency>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
<build>
<finalName>postgresql-scenario</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.9.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</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>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?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}/postgresql-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.postgresql;
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.postgresql.controller;
import java.sql.SQLException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/postgresql-scenario/case")
public class CaseController {
private static Logger logger = LogManager.getLogger(CaseController.class);
@Autowired
PostgresqlConfig postgresqlConfig;
@GetMapping("/healthcheck")
public String healthcheck() throws Exception {
SQLExecutor sqlExecute = null;
try {
sqlExecute = new SQLExecutor(postgresqlConfig);
sqlExecute.checkPG(ConstSql.TEST_SQL);
} catch (SQLException e) {
logger.error("Failed to execute sql.", e);
throw e;
} finally {
if (sqlExecute != null) {
try {
sqlExecute.closeConnection();
} catch (SQLException e) {
logger.error("Failed to close connection.", e);
}
}
}
return "Success";
}
@GetMapping("/postgres")
public String postgres() throws SQLException {
logger.info("Begin to start execute sql");
SQLExecutor sqlExecute = null;
try {
sqlExecute = new SQLExecutor(postgresqlConfig);
sqlExecute.createTable(ConstSql.CREATE_TABLE_SQL);
sqlExecute.insertData(ConstSql.INSERT_DATA_SQL, "1", "1");
sqlExecute.dropTable(ConstSql.DROP_TABLE_SQL);
} catch (SQLException e) {
logger.error("Failed to execute sql.", e);
throw e;
} finally {
if (sqlExecute != null) {
try {
sqlExecute.closeConnection();
} catch (SQLException e) {
logger.error("Failed to close connection.", e);
}
}
}
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.
*
*/
package org.apache.skywalking.apm.testcase.postgresql.controller;
public class ConstSql {
public static final String TEST_SQL = "SELECT 1";
public static final String CREATE_TABLE_SQL = "CREATE TABLE test_007(\n" +
"id VARCHAR(1) PRIMARY KEY, \n" +
"value VARCHAR(1) NOT NULL)";
public static final String INSERT_DATA_SQL = "INSERT INTO test_007(id, value) VALUES(?,?)";
public static final String DROP_TABLE_SQL = "DROP table test_007";
}
/*
* 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.postgresql.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
public class PostgresqlConfig {
@Value("${POSTGRESQL_SERVER}")
private String host;
@Value("${POSTGRES_DB}")
private String db;
@Value("${POSTGRES_USER}")
private String user;
@Value("${POSTGRES_PASSWORD}")
private String password;
public String getUrl() {
return "jdbc:postgresql://" + host + "/" + db;
}
public String getUserName() {
return user;
}
public 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.postgresql.controller;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class SQLExecutor {
private Connection connection;
public SQLExecutor(PostgresqlConfig postgresqlConfig) throws SQLException {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
//
}
connection = DriverManager.getConnection(postgresqlConfig.getUrl(), postgresqlConfig.getUserName(), postgresqlConfig.getPassword());
}
public void checkPG(String sql) throws SQLException {
Statement preparedStatement = connection.createStatement();
preparedStatement.execute(sql);
}
public void createTable(String sql) throws SQLException {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.execute();
}
public void insertData(String sql, String id, String value) throws SQLException {
CallableStatement preparedStatement = connection.prepareCall(sql);
preparedStatement.setString(1, id);
preparedStatement.setString(2, value);
preparedStatement.execute();
}
public void dropTable(String sql) throws SQLException {
Statement preparedStatement = connection.createStatement();
preparedStatement.execute(sql);
}
public void closeConnection() throws SQLException {
if (this.connection != null) {
this.connection.close();
}
}
}
# 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
<?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 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.
9.2-1002-jdbc4
9.2-1003-jdbc3
9.2-1003-jdbc4
9.2-1004-jdbc3
9.2-1004-jdbc4
9.2-1004-jdbc41
9.3-1100-jdbc3
9.3-1100-jdbc4
9.3-1101-jdbc3
9.3-1101-jdbc4
9.3-1101-jdbc41
9.3-1102-jdbc3
9.3-1102-jdbc4
9.3-1102-jdbc41
9.3-1103-jdbc3
9.3-1103-jdbc4
9.3-1103-jdbc41
9.3-1104-jdbc4
9.3-1104-jdbc41
9.4-1201-jdbc4
9.4-1201-jdbc41
9.4-1202-jdbc4
9.4-1202-jdbc41
9.4-1202-jdbc42
9.4-1203-jdbc4
9.4-1203-jdbc41
9.4-1203-jdbc42
9.4-1204-jdbc4
9.4-1204-jdbc41
9.4-1204-jdbc42
9.4-1205-jdbc4
9.4-1205-jdbc41
9.4-1205-jdbc42
9.4-1206-jdbc4
9.4-1206-jdbc41
9.4-1206-jdbc42
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册