Search in sources :

Example 6 with ParsingResult

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

the class DefaultCachingSqlNormalizerTest method testNormalizedSql_cache_expire.

@Test
public void testNormalizedSql_cache_expire() throws Exception {
    CachingSqlNormalizer normalizer = new DefaultCachingSqlNormalizer(1);
    ParsingResult parsingResult = normalizer.wrapSql("select * from table1");
    boolean newCache = normalizer.normalizedSql(parsingResult);
    Assert.assertTrue("newCacheState", newCache);
    // cache expire
    ParsingResult parsingResult2 = normalizer.wrapSql("select * from table2");
    boolean cached = normalizer.normalizedSql(parsingResult2);
    Assert.assertTrue(cached);
    ParsingResult parsingResult1_recached = normalizer.wrapSql("select * from table3");
    boolean newCache_parsingResult1_recached = normalizer.normalizedSql(parsingResult1_recached);
    Assert.assertTrue(newCache_parsingResult1_recached);
}
Also used : ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) CachingSqlNormalizer(com.navercorp.pinpoint.profiler.metadata.CachingSqlNormalizer) DefaultCachingSqlNormalizer(com.navercorp.pinpoint.profiler.metadata.DefaultCachingSqlNormalizer) DefaultCachingSqlNormalizer(com.navercorp.pinpoint.profiler.metadata.DefaultCachingSqlNormalizer) Test(org.junit.Test)

Example 7 with ParsingResult

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

the class PreparedStatementExecuteQueryInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        DatabaseInfo databaseInfo = (target instanceof DatabaseInfoAccessor) ? ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo() : null;
        if (databaseInfo == null) {
            databaseInfo = UnKnownDatabaseInfo.INSTANCE;
        }
        recorder.recordServiceType(databaseInfo.getExecuteQueryType());
        recorder.recordEndPoint(databaseInfo.getMultipleHost());
        recorder.recordDestinationId(databaseInfo.getDatabaseId());
        ParsingResult parsingResult = null;
        if (target instanceof ParsingResultAccessor) {
            parsingResult = ((ParsingResultAccessor) target)._$PINPOINT$_getParsingResult();
        }
        Map<Integer, String> bindValue = null;
        if (target instanceof BindValueAccessor) {
            bindValue = ((BindValueAccessor) target)._$PINPOINT$_getBindValue();
        }
        if (bindValue != null) {
            String bindString = toBindVariable(bindValue);
            recorder.recordSqlParsingResult(parsingResult, bindString);
        } else {
            recorder.recordSqlParsingResult(parsingResult);
        }
        recorder.recordApi(descriptor);
        //            trace.recordApi(apiId);
        // Need to change where to invoke clean().
        // There is cleanParameters method but it's not necessary to intercept that method.
        // iBatis intentionally does not invoke it in most cases. 
        clean(target);
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn(e.getMessage(), e);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) BindValueAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)

Example 8 with ParsingResult

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

the class CassandraStatementExecuteQueryInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        DatabaseInfo databaseInfo = (target instanceof DatabaseInfoAccessor) ? ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo() : null;
        if (databaseInfo == null) {
            databaseInfo = UnKnownDatabaseInfo.INSTANCE;
        }
        recorder.recordServiceType(databaseInfo.getExecuteQueryType());
        recorder.recordEndPoint(databaseInfo.getMultipleHost());
        recorder.recordDestinationId(databaseInfo.getDatabaseId());
        String sql;
        if (args[0] instanceof BoundStatement) {
            sql = ((BoundStatement) args[0]).preparedStatement().getQueryString();
        } else if (args[0] instanceof RegularStatement) {
            sql = ((RegularStatement) args[0]).getQueryString();
        } else {
            // we have string
            sql = (String) args[0];
        }
        ParsingResult parsingResult = traceContext.parseSql(sql);
        if (parsingResult != null) {
            ((ParsingResultAccessor) target)._$PINPOINT$_setParsingResult(parsingResult);
        } else {
            if (logger.isErrorEnabled()) {
                logger.error("sqlParsing fail. parsingResult is null sql:{}", sql);
            }
        }
        Map<Integer, String> bindValue = ((BindValueAccessor) target)._$PINPOINT$_getBindValue();
        // Extracting bind variables from already-serialized is too risky
        if (bindValue != null && !bindValue.isEmpty()) {
            String bindString = toBindVariable(bindValue);
            recorder.recordSqlParsingResult(parsingResult, bindString);
        } else {
            recorder.recordSqlParsingResult(parsingResult);
        }
        recorder.recordApi(descriptor);
        clean(target);
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn(e.getMessage(), e);
        }
    }
}
Also used : UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) BindValueAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor) RegularStatement(com.datastax.driver.core.RegularStatement) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 9 with ParsingResult

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

the class WrappedSpanEventRecorder method recordSqlInfo.

@Override
public ParsingResult recordSqlInfo(String sql) {
    if (sql == null) {
        return null;
    }
    ParsingResult parsingResult = sqlMetaDataService.parseSql(sql);
    recordSqlParsingResult(parsingResult);
    return parsingResult;
}
Also used : ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult)

Example 10 with ParsingResult

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

the class DefaultCachingSqlNormalizerTest method testNormalizedSql.

@Test
public void testNormalizedSql() throws Exception {
    CachingSqlNormalizer normalizer = new DefaultCachingSqlNormalizer(1);
    ParsingResult parsingResult = normalizer.wrapSql("select * from dual");
    boolean newCache = normalizer.normalizedSql(parsingResult);
    Assert.assertTrue("newCacheState", newCache);
    boolean notCached = normalizer.normalizedSql(parsingResult);
    Assert.assertFalse("alreadyCached", notCached);
    ParsingResult alreadyCached = normalizer.wrapSql("select * from dual");
    boolean notCached2 = normalizer.normalizedSql(alreadyCached);
    Assert.assertFalse("alreadyCached2", notCached2);
}
Also used : ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) CachingSqlNormalizer(com.navercorp.pinpoint.profiler.metadata.CachingSqlNormalizer) DefaultCachingSqlNormalizer(com.navercorp.pinpoint.profiler.metadata.DefaultCachingSqlNormalizer) DefaultCachingSqlNormalizer(com.navercorp.pinpoint.profiler.metadata.DefaultCachingSqlNormalizer) Test(org.junit.Test)

Aggregations

ParsingResult (com.navercorp.pinpoint.bootstrap.context.ParsingResult)11 ParsingResultAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)6 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)4 DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)4 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)4 Test (org.junit.Test)3 RegularStatement (com.datastax.driver.core.RegularStatement)2 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)2 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)2 BindValueAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor)2 CachingSqlNormalizer (com.navercorp.pinpoint.profiler.metadata.CachingSqlNormalizer)2 DefaultCachingSqlNormalizer (com.navercorp.pinpoint.profiler.metadata.DefaultCachingSqlNormalizer)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 EnhancedDataSender (com.navercorp.pinpoint.profiler.sender.EnhancedDataSender)1 TBase (org.apache.thrift.TBase)1