Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB2 Profiler Plugin added #10719

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/db2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target/
/.settings/
/.classpath
/.project
/*.iml
25 changes: 25 additions & 0 deletions plugins/db2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<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</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>

<artifactId>pinpoint-db2-plugin</artifactId>
<name>pinpoint-db2-plugin</name>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap-core</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

package com.navercorp.pinpoint.plugin.db2;

import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcConfig;


public class DB2Config extends JdbcConfig {
private final boolean profileSetAutoCommit;
private final boolean profileCommit;
private final boolean profileRollback;

public DB2Config(ProfilerConfig config) {
super(config.readBoolean("profiler.jdbc.DB2", false),
config.readBoolean("profiler.jdbc.DB2.tracesqlbindvalue", config.isTraceSqlBindValue()),
config.getMaxSqlBindValueSize());
this.profileSetAutoCommit = config.readBoolean("profiler.jdbc.DB2.setautocommit", false);
this.profileCommit = config.readBoolean("profiler.jdbc.DB2.commit", false);
this.profileRollback = config.readBoolean("profiler.jdbc.DB2.rollback", false);
}

public boolean isProfileSetAutoCommit() {
return profileSetAutoCommit;
}

public boolean isProfileCommit() {
return profileCommit;
}

public boolean isProfileRollback() {
return profileRollback;
}


@Override
public String toString() {
return "DB2Config [" + super.toString() + ", profileSetAutoCommit=" + profileSetAutoCommit + ", profileCommit=" + profileCommit + ", profileRollback=" + profileRollback + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

package com.navercorp.pinpoint.plugin.db2;

import com.navercorp.pinpoint.bootstrap.context.DatabaseInfo;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo;
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParserV2;
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.StringMaker;
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo;
import com.navercorp.pinpoint.common.trace.ServiceType;

import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;


public class DB2JdbcUrlParser implements JdbcUrlParserV2 {


static final String DB2_URL_PREFIX = "jdbc:db2:";
private static final Set<Type> TYPES = EnumSet.allOf(Type.class);

private final PLogger logger = PLoggerFactory.getLogger(this.getClass());

@Override
public DatabaseInfo parse(String jdbcUrl) {
if (jdbcUrl == null) {
logger.info("jdbcUrl");
return UnKnownDatabaseInfo.INSTANCE;
}

Type type = getType(jdbcUrl);
if (type == null) {
logger.info("jdbcUrl has invalid prefix.(url:{}, valid prefixes:{}, {})", jdbcUrl, DB2_URL_PREFIX, DB2_URL_PREFIX);
return UnKnownDatabaseInfo.INSTANCE;
}

try {
return parse0(jdbcUrl, type);
} catch (Exception e) {
logger.info("DB2JdbcUrl parse error. url: {}, Caused: {}", jdbcUrl, e.getMessage(), e);
return UnKnownDatabaseInfo.createUnknownDataBase(DB2PluginConstants.DB2,DB2PluginConstants.DB2_EXECUTE_QUERY, jdbcUrl);
}
}

private DatabaseInfo parse0(String url, Type type) {
return parseNormal(url, type);
}

private DatabaseInfo parseNormal(String url, Type type) {

StringMaker maker = new StringMaker(url);
maker.after(type.getUrlPrefix());

String host = maker.after("//").before('/').value();
List<String> hostList = parseHost(host);

String databaseId = maker.next().after('/').before('?').value();
String normalizedUrl = maker.clear().before('?').value();
return new DefaultDatabaseInfo(DB2PluginConstants.DB2, DB2PluginConstants.DB2_EXECUTE_QUERY, url,
normalizedUrl, hostList, databaseId);
}

private List<String> parseHost(String host) {
final int multiHost = host.indexOf(",");
if (multiHost == -1) {
return Collections.singletonList(host);
}

String[] parsedHost = host.split(",");
return Arrays.asList(parsedHost);
}

@Override
public ServiceType getServiceType() {
return DB2PluginConstants.DB2;
}

private static Type getType(String jdbcUrl) {
for (Type type : TYPES) {
if (jdbcUrl.startsWith(type.getUrlPrefix())) {
return type;
}
}
return null;
}

private enum Type {
DB2(DB2_URL_PREFIX);

private final String urlPrefix;
private final String loadbalanceUrlPrefix;

Type(String urlPrefix) {
this.urlPrefix = urlPrefix;
this.loadbalanceUrlPrefix = urlPrefix + "loadbalance:";
}

private String getUrlPrefix() {
return urlPrefix;
}

private String getLoadbalanceUrlPrefix() {
return loadbalanceUrlPrefix;
}
}
}
Loading