Search in sources :

Example 1 with ParsingResult

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

the class DefaultCachingSqlNormalizer method normalizedSql.

@Override
public boolean normalizedSql(ParsingResult parsingResult) {
    if (parsingResult == null) {
        return false;
    }
    if (parsingResult == EMPTY_OBJECT) {
        return false;
    }
    if (parsingResult.getId() != ParsingResult.ID_NOT_EXIST) {
        // already cached
        return false;
    }
    if (!(parsingResult instanceof ParsingResultInternal)) {
        if (logger.isWarnEnabled()) {
            logger.warn("unsupported ParsingResult Type type {}", parsingResult);
        }
        throw new IllegalArgumentException("unsupported ParsingResult Type");
    }
    final ParsingResultInternal parsingResultInternal = (ParsingResultInternal) parsingResult;
    final String originalSql = parsingResultInternal.getOriginalSql();
    final NormalizedSql normalizedSql = this.sqlParser.normalizedSql(originalSql);
    final Result cachingResult = this.sqlCache.put(normalizedSql.getNormalizedSql());
    // set normalizedSql
    // set sqlId
    final boolean success = parsingResultInternal.setId(cachingResult.getId());
    if (!success) {
        if (logger.isWarnEnabled()) {
            logger.warn("invalid state. setSqlId fail setId:{}, ParsingResultInternal:{}", cachingResult.getId(), parsingResultInternal);
        }
    }
    parsingResultInternal.setSql(normalizedSql.getNormalizedSql());
    parsingResultInternal.setOutput(normalizedSql.getParseParameter());
    return cachingResult.isNewValue();
}
Also used : ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult)

Example 2 with ParsingResult

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

the class PreparedStatementCreateInterceptor method doInAfterTrace.

@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    if (result instanceof ParsingResultAccessor) {
        ParsingResult parsingResult = ((ParsingResultAccessor) result)._$PINPOINT$_getParsingResult();
        recorder.recordSqlParsingResult(parsingResult);
    }
    recorder.recordException(throwable);
    recorder.recordApi(methodDescriptor);
}
Also used : ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)

Example 3 with ParsingResult

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

the class PreparedStatementCreateInterceptor method prepareAfterTrace.

@Override
protected void prepareAfterTrace(Object target, Object[] args, Object result, Throwable throwable) {
    final boolean success = InterceptorUtils.isSuccess(throwable);
    if (success) {
        if (target instanceof DatabaseInfoAccessor) {
            // set databaseInfo to PreparedStatement only when preparedStatement is generated successfully.
            DatabaseInfo databaseInfo = ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo();
            if (databaseInfo != null) {
                if (result instanceof DatabaseInfoAccessor) {
                    ((DatabaseInfoAccessor) result)._$PINPOINT$_setDatabaseInfo(databaseInfo);
                }
            }
        }
        if (result instanceof ParsingResultAccessor) {
            // 1. Don't check traceContext. preparedStatement can be created in other thread.
            // 2. While sampling is active, the thread which creates preparedStatement could not be a sampling target. So record sql anyway. 
            String sql = (String) args[0];
            ParsingResult parsingResult = traceContext.parseSql(sql);
            if (parsingResult != null) {
                ((ParsingResultAccessor) result)._$PINPOINT$_setParsingResult(parsingResult);
            } else {
                if (logger.isErrorEnabled()) {
                    logger.error("sqlParsing fail. parsingResult is null sql:{}", sql);
                }
            }
        }
    }
}
Also used : ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)

Example 4 with ParsingResult

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

the class CassandraPreparedStatementCreateInterceptor method prepareAfterTrace.

@Override
protected void prepareAfterTrace(Object target, Object[] args, Object result, Throwable throwable) {
    final boolean success = InterceptorUtils.isSuccess(throwable);
    if (success) {
        if (target instanceof DatabaseInfoAccessor) {
            // set databaseInfo to PreparedStatement only when
            // preparedStatement is generated successfully.
            DatabaseInfo databaseInfo = ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo();
            if (databaseInfo != null) {
                if (result instanceof DatabaseInfoAccessor) {
                    ((DatabaseInfoAccessor) result)._$PINPOINT$_setDatabaseInfo(databaseInfo);
                }
            }
        }
        if (result instanceof ParsingResultAccessor) {
            String sql;
            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) result)._$PINPOINT$_setParsingResult(parsingResult);
            } else {
                if (logger.isErrorEnabled()) {
                    logger.error("sqlParsing fail. parsingResult is null sql:{}", sql);
                }
            }
        }
    }
}
Also used : ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor) RegularStatement(com.datastax.driver.core.RegularStatement)

Example 5 with ParsingResult

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

the class CassandraPreparedStatementCreateInterceptor method doInAfterTrace.

@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    if (result instanceof ParsingResultAccessor) {
        ParsingResult parsingResult = ((ParsingResultAccessor) result)._$PINPOINT$_getParsingResult();
        recorder.recordSqlParsingResult(parsingResult);
    }
    recorder.recordException(throwable);
    recorder.recordApi(methodDescriptor);
}
Also used : ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)

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