smartcat-labs / cassandra-diagnostics

Cassandra Node Diagnostics Tools
Apache License 2.0
51 stars 6 forks source link

Extract statement in slow query module not working #93

Closed nbozic-zz closed 7 years ago

nbozic-zz commented 8 years ago

When slow query is logged only statement type is extracted and in influx we see empty string for statement.

f1yegor commented 8 years ago

I've looked at issue and with current pointcut was able to reconstruct SelectStatement. But I'm thinking about another, more convenient pointcut for this purpose. Your ideas?

mgobec commented 8 years ago

@f1yegor Could you please elaborate? I'm not sure I understand. The issue here is that when we create query object in connector we set empty string to statement instead of the statement itself. We didn't have time to add this but any help is appreciated.

f1yegor commented 8 years ago

Something like `

private final CQLStatement statement;

QueryBuilder(CQLStatement statement) {
    this.statement = statement;
}

String build() {
    if (statement instanceof SelectStatement) {
        SelectStatement select = (SelectStatement) statement;
        Selection selection = select.getSelection();
        String columnsQuery = "";
        if (selection != null) {
            List<ColumnDefinition> columns = select.getSelection().getColumns();
            List<String> columnNames = new ArrayList<>(columns.size());
            for (ColumnDefinition column : columns) {
                columnNames.add(column.name.toCQLString());
            }
            columnsQuery = StringUtils.join(columnNames, ", ");
        }
        return "SELECT " + columnsQuery + " FROM " + select.keyspace() + "." + select.columnFamily();
    }
    return "";
}

` and then use as statement query.

mgobec commented 8 years ago

This looks like an extra effort just to get the statement which we already have at process method in QueryProcessor and there would need to be a significant effort to implement full select or upsert statements because of all the parameters. For example your code is missing WHERE params which are useful when investigating slow queries. I think @nivancevic did an investigation and we should be able to use the queryString parameter from process method and provide it to the wrapper using bytebuddy. @nivancevic Any comments on this?

f1yegor commented 8 years ago

Yes, I missed WHERE for further implementation. Looked at implementation of ByteBuddy. It would be challenging or impossible, especially because processStatement called from several places. Would be interesting to look at good solution.

nbozic-zz commented 7 years ago

Fixed in #173 where we moved whole logic from ByteBuddy byte code manipulation to custom QueryHandler.

@f1yegor Check out release candidate 2.0.0-rc1 on BinTray.