Skip to content

Commit

Permalink
[#11681] add dameng-jdbc plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yjqg6666 authored and emeroad committed Nov 6, 2024
1 parent a59b789 commit dbd6ae9
Show file tree
Hide file tree
Showing 25 changed files with 1,559 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,20 @@ profiler.jdbc.mariadb.rollback=true
# Trace bindvalues for MariaDB PreparedStatements (overrides profiler.jdbc.tracesqlbindvalue)
#profiler.jdbc.mariadb.tracesqlbindvalue=true

#
# Dameng
#
# Profile MariaDB
profiler.jdbc.dameng=true
# Allow profiling of setautocommit.
profiler.jdbc.dameng.setautocommit=false
# Allow profiling of commit.
profiler.jdbc.dameng.commit=false
# Allow profiling of rollback.
profiler.jdbc.dameng.rollback=false
# Trace bindvalues for Dameng PreparedStatements (overrides profiler.jdbc.tracesqlbindvalue)
#profiler.jdbc.dameng.tracesqlbindvalue=true

#
# MSSQL JDBC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,20 @@ profiler.jdbc.mariadb.rollback=false
# Trace bindvalues for MariaDB PreparedStatements (overrides profiler.jdbc.tracesqlbindvalue)
#profiler.jdbc.mariadb.tracesqlbindvalue=true

#
# Dameng
#
# Profile MariaDB
profiler.jdbc.dameng=true
# Allow profiling of setautocommit.
profiler.jdbc.dameng.setautocommit=false
# Allow profiling of commit.
profiler.jdbc.dameng.commit=false
# Allow profiling of rollback.
profiler.jdbc.dameng.rollback=false
# Trace bindvalues for Dameng PreparedStatements (overrides profiler.jdbc.tracesqlbindvalue)
#profiler.jdbc.dameng.tracesqlbindvalue=true

#
# MSSQL JDBC
#
Expand Down
82 changes: 82 additions & 0 deletions agent-module/plugins-it/dameng-jdbc-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2024 NAVER Corp.
~
~ 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 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-plugins-it</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>pinpoint-dameng-jdbc-driver-plugin-it</artifactId>

<packaging>jar</packaging>

<properties>
<jdk.version>1.8</jdk.version>
<jdk.home>${env.JAVA_8_HOME}</jdk.home>
</properties>

<dependencies>
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
</dependency>
<!-- testcontainers -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-plugin-it-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-plugin-it-utils-jdbc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-dameng-jdbc-driver-plugin</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<jvm>${env.JAVA_8_HOME}/bin/java</jvm>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.navercorp.pinpoint.it.plugin.jdbc;

import com.navercorp.pinpoint.it.plugin.utils.LogOutputStream;
import com.navercorp.pinpoint.it.plugin.utils.jdbc.DriverProperties;
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Strings;
import org.junit.jupiter.api.Assumptions;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import java.util.Properties;

/**
* @author yjqg6666
*/
public class DamengServer implements SharedTestLifeCycle {
private final Logger logger = LogManager.getLogger(getClass());

public static final DockerImageName DM_IMAGE = DockerImageName.parse("yjqg6666/dameng-server:v8-20240715");

private GenericContainer<?> dm;

protected static final String USER = "SYSDBA";
protected static final String PASSWORD = "SYSDBA001";
private static final int PORT = 5236;

@Override
public Properties beforeAll() {
Assumptions.assumeTrue(DockerClientFactory.instance().isDockerAvailable(), "Docker not enabled");

dm = new GenericContainer(DM_IMAGE)
.withExposedPorts(PORT)
.withPrivilegedMode(true)
.withReuse(false)
.withEnv("LD_LIBRARY_PATH", "/opt/dmdbms/bin")
.withEnv("UNICODE_FLAG", "1")
.withEnv("INSTANCE_NAME", "DM8CI")
.waitingFor(Wait.forLogMessage(".*SYSTEM IS READY.*\\n", 1));
dm.withLogConsumer(new LogOutputStream(logger::info));
dm.start();

sourceInitSql();

int port = dm.getMappedPort(PORT);
String url = "jdbc:dm://" + dm.getHost() + ":" + port;
System.setProperty(DriverProperties.URL, url);
System.setProperty(DriverProperties.HOST, dm.getHost());
System.setProperty(DriverProperties.PORT, String.valueOf(port));
System.setProperty(DriverProperties.USER, USER);
System.setProperty(DriverProperties.PASSWARD, PASSWORD);

Properties properties = new Properties();
properties.setProperty(DriverProperties.URL, url);
properties.setProperty(DriverProperties.HOST, dm.getHost());
properties.setProperty(DriverProperties.PORT, String.valueOf(port));
properties.setProperty(DriverProperties.USER, USER);
properties.setProperty(DriverProperties.PASSWARD, PASSWORD);
return properties;
}

@Override
public void afterAll() {
if (dm != null) {
dm.stop();
}
}

private void sourceInitSql() {

String dst = "/tmp/citest_init.sql";
dm.copyFileToContainer(MountableFile.forClasspathResource("jdbc/dameng/init.sql"), dst);

String cmd = "/tmp/citest_init_sql";
String content = String.format("#!/bin/sh\n/opt/dmdbms/bin/disql %s/%s < %s", USER, PASSWORD, dst);
int filemode = 000755; //can not be 755 in oct.
dm.copyFileToContainer(Transferable.of(content, filemode), cmd);

boolean ok = true;
String msg = Strings.EMPTY;
try {
Container.ExecResult execResult = dm.execInContainer(cmd);
if (execResult.getExitCode() != 0) {
ok = false;
msg = execResult.getStderr();
}
System.out.println(execResult.getStdout());
} catch (Exception e) {
ok = false;
msg = e.getMessage();
}
if (!ok) {
System.err.println("Source init.sql failed, cause:" + msg);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2024 NAVER Corp.
*
* 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.
*/

package com.navercorp.pinpoint.it.plugin.jdbc;

import com.navercorp.pinpoint.it.plugin.utils.jdbc.AbstractJDBCDriverClass;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.PreparedStatement;
import java.sql.Statement;

/**
* @author yjqg6666
*/
public class Dameng_18_DriverClass extends AbstractJDBCDriverClass {

@Override
public Class<Driver> getDriver() {
return forName("dm.jdbc.driver.DmDriver");
}

@Override
public Class<Connection> getConnection() {
return forName("dm.jdbc.driver.DmdbConnection");
}

@Override
public Class<Statement> getStatement() {
return forName("dm.jdbc.driver.DmdbStatement");

}

@Override
public Class<PreparedStatement> getPreparedStatement() {
return forName("dm.jdbc.driver.DmdbPreparedStatement");
}

@Override
public Class<CallableStatement> getCallableStatement() {
return forName("dm.jdbc.driver.DmdbCallableStatement");
}
}
Loading

0 comments on commit dbd6ae9

Please sign in to comment.