Search in sources :

Example 11 with DatabaseInfoAccessor

use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.

the class CassandraDriverConnectInterceptor method prepareAfterTrace.

@Override
protected void prepareAfterTrace(Object target, Object[] args, Object result, Throwable throwable) {
    final boolean success = InterceptorUtils.isSuccess(throwable);
    // Must not check if current transaction is trace target or not. Connection can be made by other thread.
    List<String> hostList = new ArrayList<String>();
    if (target instanceof Cluster) {
        Cluster cluster = (Cluster) target;
        final Set<Host> hosts = cluster.getMetadata().getAllHosts();
        final int port = cluster.getConfiguration().getProtocolOptions().getPort();
        for (Host host : hosts) {
            final String hostAddress = host.getAddress().getHostAddress() + ":" + port;
            hostList.add(hostAddress);
        }
    }
    if (args == null) {
        return;
    }
    final String keyspace = (String) args[0];
    DatabaseInfo databaseInfo = createDatabaseInfo(keyspace, hostList);
    if (success) {
        if (recordConnection) {
            if (result instanceof DatabaseInfoAccessor) {
                ((DatabaseInfoAccessor) result)._$PINPOINT$_setDatabaseInfo(databaseInfo);
            }
        }
    }
}
Also used : UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DefaultDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) ArrayList(java.util.ArrayList) Cluster(com.datastax.driver.core.Cluster) Host(com.datastax.driver.core.Host)

Example 12 with DatabaseInfoAccessor

use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.

the class CassandraDriverConnectInterceptor method doInAfterTrace.

@Override
protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    if (recordConnection) {
        DatabaseInfo databaseInfo;
        if (result instanceof DatabaseInfoAccessor) {
            databaseInfo = ((DatabaseInfoAccessor) result)._$PINPOINT$_getDatabaseInfo();
        } else {
            databaseInfo = null;
        }
        if (databaseInfo == null) {
            databaseInfo = UnKnownDatabaseInfo.INSTANCE;
        }
        // Count database connect too because it's very heavy operation
        recorder.recordServiceType(databaseInfo.getType());
        recorder.recordEndPoint(databaseInfo.getMultipleHost());
        recorder.recordDestinationId(databaseInfo.getDatabaseId());
    }
    recorder.recordApi(methodDescriptor);
    recorder.recordException(throwable);
}
Also used : UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DefaultDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)

Example 13 with DatabaseInfoAccessor

use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.

the class CassandraPreparedStatementCreateInterceptor method doInBeforeTrace.

@Override
public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
    DatabaseInfo databaseInfo = (target instanceof DatabaseInfoAccessor) ? ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo() : null;
    if (databaseInfo == null) {
        databaseInfo = UnKnownDatabaseInfo.INSTANCE;
    }
    recorder.recordServiceType(databaseInfo.getType());
    recorder.recordEndPoint(databaseInfo.getMultipleHost());
    recorder.recordDestinationId(databaseInfo.getDatabaseId());
}
Also used : UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)

Example 14 with DatabaseInfoAccessor

use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.

the class MySQLConnectionCreateInterceptor 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;
    }
    final String hostToConnectTo = getString(args[0]);
    final Integer portToConnectTo = getInteger(args[1]);
    final String databaseId = getString(args[3]);
    // 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)

Example 15 with DatabaseInfoAccessor

use of com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor in project pinpoint by naver.

the class DriverConnectInterceptorTest method driverConnect.

@Test
public void driverConnect() throws SQLException {
    TraceContext traceContext = mock(TraceContext.class);
    MethodDescriptor methodDescriptor = mock(MethodDescriptor.class);
    JdbcUrlParser parser = mock(JdbcUrlParser.class);
    when(parser.parse(anyString())).thenReturn(UnKnownDatabaseInfo.INSTANCE);
    String invalidJdbcUrl = "invalidUrl";
    Driver driver = mock(Driver.class);
    DatabaseInfoAccessor setAccessor = mock(DatabaseInfoAccessor.class);
    DatabaseInfoAccessor getAccessor = mock(DatabaseInfoAccessor.class);
    SpanEventRecorder spanEventRecorder = mock(SpanEventRecorder.class);
    DriverConnectInterceptor driverConnectInterceptor = new DriverConnectInterceptor(traceContext, methodDescriptor, parser);
    driverConnectInterceptor.prepareAfterTrace(driver, va(invalidJdbcUrl), setAccessor, null);
    driverConnectInterceptor.doInAfterTrace(spanEventRecorder, driver, va(invalidJdbcUrl), getAccessor, null);
    verify(setAccessor, times(1))._$PINPOINT$_setDatabaseInfo(UnKnownDatabaseInfo.INSTANCE);
    verify(getAccessor, times(1))._$PINPOINT$_getDatabaseInfo();
}
Also used : JdbcUrlParser(com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) Driver(java.sql.Driver) Matchers.anyString(org.mockito.Matchers.anyString) MethodDescriptor(com.navercorp.pinpoint.bootstrap.context.MethodDescriptor) Test(org.junit.Test)

Aggregations

DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)27 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)24 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)20 ParsingResultAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)7 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)5 ParsingResult (com.navercorp.pinpoint.bootstrap.context.ParsingResult)4 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)4 DefaultDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo)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 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)1 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1 JdbcUrlParser (com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser)1 Driver (java.sql.Driver)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Test (org.junit.Test)1