Search in sources :

Example 66 with DatabaseInfo

use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.

the class JDBCUrlParserTest method oracleRacParser1.

@Test
public void oracleRacParser1() {
    //    "jdbc:oracle:thin:@(Description1=(LOAD_BALANCE=on)" +
    //    "(ADDRESS=(PROTOCOL=TCP)(HOST=1.2.3.4) (PORT=1521))" +
    //            "(ADDRESS=(PROTOCOL=TCP)(HOST=1.2.3.5) (PORT=1521))" +
    //            "(CONNECT_DATA=(SERVICE_NAME=service)))"
    String rac = "jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)" + "(ADDRESS=(PROTOCOL=TCP)(HOST=1.2.3.4) (PORT=1521))" + "(ADDRESS=(PROTOCOL=TCP)(HOST=1.2.3.5) (PORT=1522))" + "(CONNECT_DATA=(SERVICE_NAME=service)))";
    DatabaseInfo dbInfo = jdbcUrlParser.parse(rac);
    Assert.assertTrue(dbInfo.isParsingComplete());
    Assert.assertEquals(dbInfo.getType(), OracleConstants.ORACLE);
    Assert.assertEquals(dbInfo.getHost().get(0), "1.2.3.4:1521");
    Assert.assertEquals(dbInfo.getHost().get(1), "1.2.3.5:1522");
    Assert.assertEquals(dbInfo.getDatabaseId(), "service");
    Assert.assertEquals(dbInfo.getUrl(), rac);
    logger.info(dbInfo.toString());
}
Also used : DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) Test(org.junit.Test)

Example 67 with DatabaseInfo

use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.

the class JDBCUrlParserTest method oracleParserServiceName.

@Test
public void oracleParserServiceName() {
    //    jdbc:oracle:thin:@hostname:port:SID
    //      "jdbc:oracle:thin:MYWORKSPACE/qwerty@localhost:1521:XE";
    DatabaseInfo dbInfo = jdbcUrlParser.parse("jdbc:oracle:thin:@hostname:port/serviceName");
    Assert.assertTrue(dbInfo.isParsingComplete());
    Assert.assertEquals(dbInfo.getType(), OracleConstants.ORACLE);
    Assert.assertEquals(dbInfo.getHost().get(0), "hostname:port");
    Assert.assertEquals(dbInfo.getDatabaseId(), "serviceName");
    Assert.assertEquals(dbInfo.getUrl(), "jdbc:oracle:thin:@hostname:port/serviceName");
    logger.info(dbInfo.toString());
}
Also used : DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) Test(org.junit.Test)

Example 68 with DatabaseInfo

use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.

the class PostgreSqlUrlParserTest method postgresqlParse3.

@Test
public void postgresqlParse3() {
    DatabaseInfo dbInfo = jdbcUrlParser.parse("jdbc:postgresql://61.74.71.31/log?useUnicode=yes&characterEncoding=UTF-8");
    Assert.assertTrue(dbInfo.isParsingComplete());
    Assert.assertEquals(dbInfo.getType(), PostgreSqlConstants.POSTGRESQL);
    Assert.assertEquals(dbInfo.getHost().get(0), "61.74.71.31");
    Assert.assertEquals(dbInfo.getDatabaseId(), "log");
    Assert.assertEquals(dbInfo.getUrl(), "jdbc:postgresql://61.74.71.31/log");
    logger.info(dbInfo.toString());
}
Also used : DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) Test(org.junit.Test)

Example 69 with DatabaseInfo

use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.

the class PostgreSqlUrlParserTest method postgresqlParse1.

@Test
public void postgresqlParse1() {
    DatabaseInfo dbInfo = jdbcUrlParser.parse("jdbc:postgresql://ip_address:3306/database_name?useUnicode=yes&characterEncoding=UTF-8");
    Assert.assertTrue(dbInfo.isParsingComplete());
    Assert.assertEquals(dbInfo.getType(), PostgreSqlConstants.POSTGRESQL);
    Assert.assertEquals(dbInfo.getHost().get(0), ("ip_address:3306"));
    Assert.assertEquals(dbInfo.getDatabaseId(), "database_name");
    Assert.assertEquals(dbInfo.getUrl(), "jdbc:postgresql://ip_address:3306/database_name");
}
Also used : DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) Test(org.junit.Test)

Example 70 with DatabaseInfo

use of com.navercorp.pinpoint.bootstrap.context.DatabaseInfo in project pinpoint by naver.

the class PostgreSQLConnectionCreateInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    if (args == null || args.length != 5) {
        return;
    }
    Properties properties = getProperties(args[3]);
    final String hostToConnectTo = properties.getProperty("PGHOST");
    final Integer portToConnectTo = Integer.valueOf(properties.getProperty("PGPORT", DEFAULT_PORT));
    final String databaseId = properties.getProperty("PGDBNAME");
    // In case of loadbalance, connectUrl is modified.
    // final String url = getString(args[4]);
    DatabaseInfo databaseInfo = null;
    if (hostToConnectTo != null && portToConnectTo != null && databaseId != null) {
        // It's dangerous to use this url directly
        databaseInfo = createDatabaseInfo(hostToConnectTo, portToConnectTo, databaseId);
        if (InterceptorUtils.isSuccess(throwable)) {
            // Set only if connection is success.
            if (target instanceof DatabaseInfoAccessor) {
                ((DatabaseInfoAccessor) target)._$PINPOINT$_setDatabaseInfo(databaseInfo);
            }
        }
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.currentSpanEventRecorder();
    // We must do this if current transaction is being recorded.
    if (databaseInfo != null) {
        recorder.recordServiceType(databaseInfo.getType());
        recorder.recordEndPoint(databaseInfo.getMultipleHost());
        recorder.recordDestinationId(databaseInfo.getDatabaseId());
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) DefaultDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Properties(java.util.Properties)

Aggregations

DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)74 Test (org.junit.Test)48 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)25 DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)20 DefaultDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo)8 ParsingResult (com.navercorp.pinpoint.bootstrap.context.ParsingResult)4 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)4 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)4 ParsingResultAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)4 RegularStatement (com.datastax.driver.core.RegularStatement)2 BindValueAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 Cluster (com.datastax.driver.core.Cluster)1 Host (com.datastax.driver.core.Host)1 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)1 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)1 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)1 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)1 JdbcUrlParserV2 (com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParserV2)1 ServiceType (com.navercorp.pinpoint.common.trace.ServiceType)1