/** * Wrapper for session manager execute async method. * This method wraps the original method and, in addition, measures the statement * execution time and reports the query towards the diagnostics core. * * @param statement Statement * @param startTime execution start time * @param result execution's result future */ public void processStatement(final Statement statement, long startTime, ResultSetFuture result) { report(startTime, statement, result); }
private String statementQueryString(final Statement statement) { String query; if (statement instanceof RegularStatement) { query = statementQueryString((RegularStatement) statement); } else if (statement instanceof BoundStatement) { query = statementQueryString((BoundStatement) statement); } else if (statement instanceof BatchStatement) { query = statementQueryString((BatchStatement) statement); } else { query = "unknown;"; } return query; }
private Query extractQuery(final long startTime, final long execTime, final Statement statement) { final String queryString = statementQueryString(statement); final Query.StatementType queryType = queryType(queryString); return Query.create(startTime, execTime, host, queryType, statement.getKeyspace(), "", queryString, extractConsistencyLevel(statement)); }
/** * Initialize connector instance using the provided instrumentation. * * @param inst Instrumentation reference * @param queryReporter QueryReporter implementation reference * @param configuration Connector configuration * @param globalConfiguration global configuration general for diagnostics */ public void init(Instrumentation inst, QueryReporter queryReporter, ConnectorConfiguration configuration, GlobalConfiguration globalConfiguration) { executeStatementWrapper = new ExecuteStatementWrapper(queryReporter, configuration, globalConfiguration); setIntercepters(inst); }
/** * Code executed after the intercepted method. * * @param startTime execution start time recorded by the enter method. * @param statement CQL statement to be executed * @param result CQL result future */ @Advice.OnMethodExit public static void exit(@Advice.Enter long startTime, @Advice.Argument(0) Statement statement, @Advice.Return ResultSetFuture result) { ConnectorImpl.executeStatementWrapper().processStatement(statement, startTime, result); } }
private String statementQueryString(final BatchStatement batchStatement) { StringBuffer sb = new StringBuffer(); sb.append("BEGIN BATCH "); for (Statement statement : batchStatement.getStatements()) { sb.append(statementQueryString(statement)); } sb.append(" APPLY BATCH;"); return sb.toString(); }
/** * Submits a query reports asynchronously. * * @param startTime execution start time, in milliseconds * @param statement CQL statement * @param result ResultSetFuture */ private void report(final long startTime, final Statement statement, final ResultSetFuture result) { report(new Runnable() { @Override public void run() { try { // wait for the statement to be executed result.getUninterruptibly(); final long execTime = System.currentTimeMillis() - startTime; Query query = extractQuery(startTime, execTime, statement); logger.trace("Reporting query: {}.", query); queryReporter.report(query); } catch (Exception e) { logger.warn("An error occured while reporting query", e); } } }); }