Skip to content

Commit

Permalink
Merge branch 'nbozic-final-144-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
nbozicns committed May 5, 2017
2 parents 82f8f43 + ded4638 commit 114395f
Show file tree
Hide file tree
Showing 35 changed files with 625 additions and 105 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Default query execution time threshold is 25 milliseconds.

#### Request Rate Module

Request Rate Module uses codahale metrics library to create rate measurement of executed queries. Rates are reported for select and upsert statements using configured reporters in configured periods.
Request Rate Module uses codahale metrics library to create rate measurement of executed queries. Rates are reported for configurable statement types and consistency levels using configured reporters in configured periods.
Default reporting interval is 1 second.

#### Metrics Module
Expand Down
2 changes: 1 addition & 1 deletion cassandra-diagnostics-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.smartcat</groupId>
<artifactId>cassandra-diagnostics</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
</parent>
<artifactId>cassandra-diagnostics-commons</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,79 @@ public enum StatementType {
UNKNOWN
}

/**
* Defines possible consistency levels.
*/
public enum ConsistencyLevel {
/**
* ANY consistency.
*/
ANY,

/**
* ONE consistency.
*/
ONE,

/**
* TWO consistency.
*/
TWO,

/**
* THREE consistency.
*/
THREE,

/**
* QUORUM consistency.
*/
QUORUM,

/**
* ALL consistency.
*/
ALL,

/**
* LOCAL_QUORUM consistency.
*/
LOCAL_QUORUM,

/**
* EACH_QUORUM consistency.
*/
EACH_QUORUM,

/**
* SERIAL consistency.
*/
SERIAL,

/**
* LOCAL_SERIAL consistency.
*/
LOCAL_SERIAL,

/**
* LOCAL_ONE consistency.
*/
LOCAL_ONE,

/**
* Consistency level is unknown.
*/
UNKNOWN
}

private long startTimeInMilliseconds;
private long executionTimeInMilliseconds;
private String clientAddress;
private StatementType statementType;
private String keyspace;
private String tableName;
private String statement;
private ConsistencyLevel consistencyLevel;

/**
* Query's execution start time.
Expand Down Expand Up @@ -105,16 +171,26 @@ public String statement() {
return statement;
}

/**
* Consistency level.
*
* @return consistencyLevel
*/
public ConsistencyLevel consistencyLevel() {
return consistencyLevel;
}

private Query(final long startTimeInMilliseconds, final long executionTimeInMilliseconds,
final String clientAddress, final StatementType statementType, final String keyspace,
final String tableName, final String statement) {
final String tableName, final String statement, final ConsistencyLevel consistencyLevel) {
this.startTimeInMilliseconds = startTimeInMilliseconds;
this.executionTimeInMilliseconds = executionTimeInMilliseconds;
this.clientAddress = clientAddress;
this.statementType = statementType;
this.keyspace = keyspace;
this.tableName = tableName;
this.statement = statement;
this.consistencyLevel = consistencyLevel;
}

/**
Expand All @@ -127,20 +203,22 @@ private Query(final long startTimeInMilliseconds, final long executionTimeInMill
* @param keyspace query's key space
* @param tableName query's table name
* @param statement query's CQL statement
* @param consistencyLevel query's consistencyLevel
* @return a new Query instance
*/
public static Query create(final long startTimeInMilliseconds, final long executionTimeInMilliseconds,
final String clientAddress, final StatementType statementType, final String keyspace,
final String tableName, final String statement) {
final String tableName, final String statement, final ConsistencyLevel consistencyLevel) {
return new Query(startTimeInMilliseconds, executionTimeInMilliseconds, clientAddress, statementType, keyspace,
tableName, statement);
tableName, statement, consistencyLevel);
}

@Override
public String toString() {
return "Query [ " + "startTimeInMilliseconds=" + startTimeInMilliseconds + ", executionTimeInMilliseconds="
+ executionTimeInMilliseconds + ", clientAddress=" + clientAddress + ", statementType=" + statementType
.name() + ", statement=" + statement + ", keyspace=" + keyspace + ", tableName=" + tableName + " ]";
.name() + ", statement=" + statement + ", keyspace=" + keyspace + ", tableName=" + tableName + ", "
+ "consistencyLevel=" + consistencyLevel.name() + " ]";
}

}
2 changes: 1 addition & 1 deletion cassandra-diagnostics-connector21/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.smartcat</groupId>
<artifactId>cassandra-diagnostics</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
</parent>
<artifactId>cassandra-diagnostics-connector21</artifactId>
<description>Cassandra Diagnostics Connector for Cassandra 2.1.x.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;

import io.smartcat.cassandra.diagnostics.Query;
import io.smartcat.cassandra.diagnostics.Query.ConsistencyLevel;

/**
* This class is a Diagnostics wrapper for {@link org.apache.cassandra.cql3.QueryProcessor}.
Expand Down Expand Up @@ -172,18 +173,33 @@ private Query createQuery(final long startTime, final long execTime, final Strin
private Query createQuery(final long startTime, final long execTime, final String queryString,
final SelectStatement statement, final QueryState queryState, final QueryOptions options) {
return Query.create(startTime, execTime, queryState.getClientState().getRemoteAddress().toString(),
Query.StatementType.SELECT, statement.keyspace(), statement.columnFamily(), queryString);
Query.StatementType.SELECT, statement.keyspace(), statement.columnFamily(), queryString,
extractConsistencyLevel(options));
}

private Query createQuery(final long startTime, final long execTime, final String queryString,
final ModificationStatement statement, final QueryState queryState, final QueryOptions options) {
return Query.create(startTime, execTime, queryState.getClientState().getRemoteAddress().toString(),
Query.StatementType.UPDATE, statement.keyspace(), statement.columnFamily(), queryString);
Query.StatementType.UPDATE, statement.keyspace(), statement.columnFamily(), queryString,
extractConsistencyLevel(options));
}

private Query createGenericQuery(final long startTime, final long execTime, final String queryString,
final CQLStatement statement, final QueryState queryState, final QueryOptions options) {
return Query.create(startTime, execTime, queryState.getClientState().getRemoteAddress().toString(),
Query.StatementType.UNKNOWN, "", "", queryString);
Query.StatementType.UNKNOWN, "", "", queryString, extractConsistencyLevel(options));
}

private ConsistencyLevel extractConsistencyLevel(final QueryOptions queryOptions) {
ConsistencyLevel queryConsistencyLevel = ConsistencyLevel.UNKNOWN;

for (ConsistencyLevel consistencyLevel : ConsistencyLevel.values()) {
if (consistencyLevel.name().equals(queryOptions.getConsistency().name())) {
queryConsistencyLevel = consistencyLevel;
break;
}
}

return queryConsistencyLevel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.apache.cassandra.cql3.QueryOptions;
import org.apache.cassandra.cql3.statements.SelectStatement;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.QueryState;
import org.junit.Test;
Expand Down Expand Up @@ -57,6 +58,7 @@ public void report(Query query) {
when(queryState.getClientState()).thenReturn(clientState);

QueryOptions options = mock(QueryOptions.class);
when(options.getConsistency()).thenReturn(ConsistencyLevel.ONE);

wrapper.processPrepared(statement, queryState, options, System.currentTimeMillis(), null, null);

Expand All @@ -66,6 +68,7 @@ public void report(Query query) {
assertThat(reportedQuery.statementType()).isEqualTo(Query.StatementType.SELECT);
assertThat(reportedQuery.keyspace()).isEqualTo("test_keyspace");
assertThat(reportedQuery.tableName()).isEqualTo("test_table");
assertThat(reportedQuery.consistencyLevel()).isEqualTo(Query.ConsistencyLevel.ONE);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion cassandra-diagnostics-connector30/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smartcat</groupId>
<artifactId>cassandra-diagnostics</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
</parent>

<artifactId>cassandra-diagnostics-connector30</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;

import io.smartcat.cassandra.diagnostics.Query;
import io.smartcat.cassandra.diagnostics.Query.ConsistencyLevel;

/**
* This class is a Diagnostics wrapper for {@link org.apache.cassandra.cql3.QueryProcessor}.
Expand Down Expand Up @@ -172,18 +173,33 @@ private Query createQuery(final long startTime, final long execTime, final Strin
private Query createQuery(final long startTime, final long execTime, final String queryString,
final SelectStatement statement, final QueryState queryState, final QueryOptions options) {
return Query.create(startTime, execTime, queryState.getClientState().getRemoteAddress().toString(),
Query.StatementType.SELECT, statement.keyspace(), statement.columnFamily(), queryString);
Query.StatementType.SELECT, statement.keyspace(), statement.columnFamily(), queryString,
extractConsistencyLevel(options));
}

private Query createQuery(final long startTime, final long execTime, final String queryString,
final ModificationStatement statement, final QueryState queryState, final QueryOptions options) {
return Query.create(startTime, execTime, queryState.getClientState().getRemoteAddress().toString(),
Query.StatementType.UPDATE, statement.keyspace(), statement.columnFamily(), queryString);
Query.StatementType.UPDATE, statement.keyspace(), statement.columnFamily(), queryString,
extractConsistencyLevel(options));
}

private Query createGenericQuery(final long startTime, final long execTime, final String queryString,
final CQLStatement statement, final QueryState queryState, final QueryOptions options) {
return Query.create(startTime, execTime, queryState.getClientState().getRemoteAddress().toString(),
Query.StatementType.UNKNOWN, "", "", queryString);
Query.StatementType.UNKNOWN, "", "", queryString, extractConsistencyLevel(options));
}

private ConsistencyLevel extractConsistencyLevel(final QueryOptions queryOptions) {
ConsistencyLevel queryConsistencyLevel = ConsistencyLevel.UNKNOWN;

for (ConsistencyLevel consistencyLevel : ConsistencyLevel.values()) {
if (consistencyLevel.name().equals(queryOptions.getConsistency().name())) {
queryConsistencyLevel = consistencyLevel;
break;
}
}

return queryConsistencyLevel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.apache.cassandra.cql3.QueryOptions;
import org.apache.cassandra.cql3.statements.SelectStatement;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.service.QueryState;
import org.junit.Test;
Expand Down Expand Up @@ -57,6 +58,7 @@ public void report(Query query) {
when(queryState.getClientState()).thenReturn(clientState);

QueryOptions options = mock(QueryOptions.class);
when(options.getConsistency()).thenReturn(ConsistencyLevel.ONE);

wrapper.processPrepared(statement, queryState, options, System.currentTimeMillis(), null, null);

Expand All @@ -66,6 +68,7 @@ public void report(Query query) {
assertThat(reportedQuery.statementType()).isEqualTo(Query.StatementType.SELECT);
assertThat(reportedQuery.keyspace()).isEqualTo("test_keyspace");
assertThat(reportedQuery.tableName()).isEqualTo("test_table");
assertThat(reportedQuery.consistencyLevel()).isEqualTo(Query.ConsistencyLevel.ONE);
}

@Test
Expand Down
8 changes: 6 additions & 2 deletions cassandra-diagnostics-core/COREMODULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ Request Rate Module counts request rate of executed queries. Rates are reported

#### Configuration

Measurement name is by default `request_rate` with `_update` and `_select` suffixes for upsert and select statements respectively. For precise measurements use a default reporting period of 1 second. If higher reporting period is used reported value represents average requests/second for the reporting period.
Measurement name is by default `request_rate`. You can configure which requests to report with `requestsToReport` which is a list of statement type - consistency level pairs. By default if you do not specify anything `*:*` will be used which counts all requests ignoring separation per statement type and consistency levels. You can configure only specific statement type ignoring consistency level with `SELECT:*` or you can opt to track all statament types of specific consistency level with `*:ONE`. For precise measurements use a default reporting period of 1 second. If higher reporting period is used reported value represents average requests/second for the reporting period.

```
- module: io.smartcat.cassandra.diagnostics.module.requestrate.RequestRateModule
measurement: request_rate #optional
options:
period: 1 #optional
timeunit: SECONDS #optional
requestsToReport: # optional
- SELECT:ALL
- UPDATE:*
reporters:
- io.smartcat.cassandra.diagnostics.reporter.LogReporter
```
Expand All @@ -88,7 +91,8 @@ Minimal configuration requires specifying `metricsPatterns` with required metric
jmxSslEnabled: false #optional
jmxSslUsername: username #optional, set if ssl enabled
jmxSslPassword: password #optional, set if ssl enabled
metricsPackageName: "org.apache.cassandra.metrics" #optional
metricsPackageNames:
- "org.apache.cassandra.metrics" #optional
metricsSeparator: "_" # optional, metrics measurement name separator
metricsPatterns:
- "^org.apache.cassandra.metrics.Cache.+"
Expand Down
2 changes: 1 addition & 1 deletion cassandra-diagnostics-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.smartcat</groupId>
<artifactId>cassandra-diagnostics</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
</parent>
<artifactId>cassandra-diagnostics-core</artifactId>
<packaging>jar</packaging>
Expand Down
Loading

0 comments on commit 114395f

Please sign in to comment.