Search in sources :

Example 36 with DatabaseInfo

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

the class JDBCUrlParserTest method oracleParser2.

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

Example 37 with DatabaseInfo

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

the class PostgreSqlUrlParserTest method parseFailTest1.

@Test
public void parseFailTest1() {
    DatabaseInfo dbInfo = jdbcUrlParser.parse(null);
    Assert.assertFalse(dbInfo.isParsingComplete());
    Assert.assertEquals(ServiceType.UNKNOWN_DB, dbInfo.getType());
}
Also used : DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) Test(org.junit.Test)

Example 38 with DatabaseInfo

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

the class DefaultDataSourceMetric method collectDataSource.

private TDataSource collectDataSource(DataSourceMonitorWrapper dataSourceMonitor) {
    TDataSource dataSource = new TDataSource();
    dataSource.setId(dataSourceMonitor.getId());
    dataSource.setServiceTypeCode(dataSourceMonitor.getServiceType().getCode());
    String jdbcUrl = dataSourceMonitor.getUrl();
    if (jdbcUrl != null) {
        dataSource.setUrl(jdbcUrl);
        DatabaseInfo databaseInfo = jdbcUrlParsingService.getDatabaseInfo(jdbcUrl);
        if (databaseInfo != null) {
            dataSource.setDatabaseName(databaseInfo.getDatabaseId());
        }
    }
    int activeConnectionSize = dataSourceMonitor.getActiveConnectionSize();
    // this field is optional (default value is 0)
    if (activeConnectionSize != 0) {
        dataSource.setActiveConnectionSize(activeConnectionSize);
    }
    dataSource.setMaxConnectionSize(dataSourceMonitor.getMaxConnectionSize());
    return dataSource;
}
Also used : DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) TDataSource(com.navercorp.pinpoint.thrift.dto.TDataSource)

Example 39 with DatabaseInfo

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

the class DefaultJdbcUrlParsingService method parseJdbcUrl.

@Override
public DatabaseInfo parseJdbcUrl(ServiceType serviceType, String jdbcUrl) {
    if (jdbcUrl == null) {
        return UnKnownDatabaseInfo.INSTANCE;
    }
    CacheKey cacheKey = new CacheKey(serviceType, jdbcUrl);
    DatabaseInfo cacheValue = eachServiceTypeCache.get(cacheKey);
    if (cacheValue != null) {
        return cacheValue;
    }
    for (JdbcUrlParserV2 parser : jdbcUrlParserList) {
        if (serviceType == parser.getServiceType()) {
            DatabaseInfo databaseInfo = parser.parse(jdbcUrl);
            return putCacheIfAbsent(cacheKey, databaseInfo);
        }
    }
    return putCacheIfAbsent(cacheKey, UnKnownDatabaseInfo.createUnknownDataBase(jdbcUrl));
}
Also used : UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) JdbcUrlParserV2(com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParserV2)

Example 40 with DatabaseInfo

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

the class AccessorInjectionTest method addTraceValue.

@Test
public void addTraceValue() throws Exception {
    final TestClassLoader loader = getTestClassLoader();
    final String javassistClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
    loader.addTransformer(javassistClassName, new TransformCallback() {

        @Override
        public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
            try {
                logger.info("modify cl:{}", loader);
                InstrumentClass aClass = instrumentor.getInstrumentClass(loader, javassistClassName, classfileBuffer);
                aClass.addField(ObjectTraceValue.class.getName());
                aClass.addField(IntTraceValue.class.getName());
                aClass.addField(IntArrayTraceValue.class.getName());
                aClass.addField(IntegerArrayTraceValue.class.getName());
                aClass.addField(DatabaseInfoTraceValue.class.getName());
                aClass.addField(BindValueTraceValue.class.getName());
                String methodName = "callA";
                aClass.getDeclaredMethod(methodName).addInterceptor("com.navercorp.pinpoint.test.javasssit.TestBeforeInterceptor");
                return aClass.toBytecode();
            } catch (InstrumentException e) {
                e.printStackTrace();
                throw new RuntimeException(e.getMessage(), e);
            }
        }
    });
    Class<?> testObjectClazz = loader.loadClass(javassistClassName);
    final String methodName = "callA";
    logger.info("class:{}", testObjectClazz.toString());
    final Object testObject = testObjectClazz.newInstance();
    Method callA = testObjectClazz.getMethod(methodName);
    callA.invoke(testObject);
    Class<?> objectTraceValue = loader.loadClass(ObjectTraceValue.class.getName());
    Assert.assertTrue("ObjectTraceValue implements fail", objectTraceValue.isInstance(testObject));
    objectTraceValue.getMethod("_$PINPOINT$_setTraceObject", Object.class).invoke(testObject, "a");
    Object get = objectTraceValue.getMethod("_$PINPOINT$_getTraceObject").invoke(testObject);
    Assert.assertEquals("a", get);
    Class<?> intTraceValue = loader.loadClass(IntTraceValue.class.getName());
    Assert.assertTrue("IntTraceValue implements fail", intTraceValue.isInstance(testObject));
    intTraceValue.getMethod("_$PINPOINT$_setTraceInt", int.class).invoke(testObject, 1);
    int a = (Integer) intTraceValue.getMethod("_$PINPOINT$_getTraceInt").invoke(testObject);
    Assert.assertEquals(1, a);
    Class<?> intArrayTraceValue = loader.loadClass(IntArrayTraceValue.class.getName());
    Assert.assertTrue("IntArrayTraceValue implements fail", intArrayTraceValue.isInstance(testObject));
    int[] expectedInts = { 1, 2, 3 };
    intArrayTraceValue.getMethod("_$PINPOINT$_setTraceIntArray", int[].class).invoke(testObject, expectedInts);
    int[] ints = (int[]) intArrayTraceValue.getMethod("_$PINPOINT$_getTraceIntArray").invoke(testObject);
    Assert.assertEquals(expectedInts, ints);
    Class<?> integerArrayTraceValue = loader.loadClass(IntegerArrayTraceValue.class.getName());
    Assert.assertTrue("IntegerArrayTraceValue implements fail", integerArrayTraceValue.isInstance(testObject));
    Integer[] expectedIntegers = { 1, 2 };
    // wrap due to vararg expansion
    Object[] wrappedExpectedIntegers = new Object[] { expectedIntegers };
    integerArrayTraceValue.getMethod("_$PINPOINT$_setTraceIntegerArray", Integer[].class).invoke(testObject, wrappedExpectedIntegers);
    Integer[] integers = (Integer[]) integerArrayTraceValue.getMethod("_$PINPOINT$_getTraceIntegerArray").invoke(testObject);
    Assert.assertArrayEquals(expectedIntegers, integers);
    Class<?> databaseTraceValue = loader.loadClass(DatabaseInfoTraceValue.class.getName());
    Assert.assertTrue("DatabaseInfoTraceValue implements fail", databaseTraceValue.isInstance(testObject));
    databaseTraceValue.getMethod("_$PINPOINT$_setTraceDatabaseInfo", DatabaseInfo.class).invoke(testObject, UnKnownDatabaseInfo.INSTANCE);
    Object databaseInfo = databaseTraceValue.getMethod("_$PINPOINT$_getTraceDatabaseInfo").invoke(testObject);
    Assert.assertSame(UnKnownDatabaseInfo.INSTANCE, databaseInfo);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Instrumentor(com.navercorp.pinpoint.bootstrap.instrument.Instrumentor) UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) InstrumentException(com.navercorp.pinpoint.bootstrap.instrument.InstrumentException) Method(java.lang.reflect.Method) TransformCallback(com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) TestClassLoader(com.navercorp.pinpoint.test.classloader.TestClassLoader) Test(org.junit.Test) JavassistClassTest(com.navercorp.pinpoint.test.javasssit.JavassistClassTest)

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