Skip to content

Commit

Permalink
Add Cassandra tracing module
Browse files Browse the repository at this point in the history
  • Loading branch information
llinder committed Apr 24, 2017
1 parent a656093 commit 6dafbc6
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 9 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ task wrapper(type: Wrapper) {

subprojects {


group = "smartthings"
version = rootProject.file('version.txt').text.trim()

Expand All @@ -37,7 +36,6 @@ subprojects {
apply plugin: 'com.github.ben-manes.versions'
apply from: rootProject.file('gradle/publishing.gradle')


sourceCompatibility = "1.8"
targetCompatibility = "1.8"

Expand Down
12 changes: 12 additions & 0 deletions ratpack-cassandra-tracing/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dependencies {
compile "io.ratpack:ratpack-core:${ratpackVersion}"
compile "io.ratpack:ratpack-guice:${ratpackVersion}"

compile 'com.datastax.cassandra:cassandra-driver-core:3.1.0'
compile 'smartthings.brave:smartthings-brave-cassandra-latencytracker:0.1.14'
compile project(':ratpack-cassandra')

testCompile "io.ratpack:ratpack-groovy-test:${ratpackVersion}"
//Note cassandra unit pulls in netty-all which may need changed if the version conflicts with Ratpacks
testCompile 'org.cassandraunit:cassandra-unit:3.0.0.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package smartthings.ratpack.cassandra.zipkin;

import com.datastax.driver.core.Session;
import com.google.inject.Scopes;
import smartthings.ratpack.cassandra.CassandraHealthCheck;
import smartthings.ratpack.cassandra.CassandraModule;
import smartthings.ratpack.cassandra.CassandraService;
import smartthings.ratpack.cassandra.RatpackSession;

public class CassandraTracingModule extends CassandraModule {

@Override
protected void configure() {
bind(TracedSession.class).in(Scopes.SINGLETON);
bind(Session.class).to(TracedSession.class);
bind(RatpackSession.class).to(TracedSession.class);
bind(CassandraService.class).in(Scopes.SINGLETON);
bind(CassandraHealthCheck.class).in(Scopes.SINGLETON);
}

public static class Config extends CassandraModule.Config {
String serviceName;

public String getServiceName() {
return serviceName;
}

public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package smartthings.ratpack.cassandra.zipkin;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import com.github.kristofa.brave.Brave;
import com.google.inject.Inject;
import smartthings.ratpack.cassandra.AbstractSession;

public final class TracedSession extends AbstractSession {

private final Brave brave;
private final Cluster cluster;
private final String keyspace;
private final CassandraTracingModule.Config config;

@Inject
public TracedSession(Cluster cluster, Brave brave, CassandraTracingModule.Config config) {
super(cluster, config.getKeyspace());
this.brave = brave;
this.cluster = cluster;
this.keyspace = config.getKeyspace();
this.config = config;
}

protected Session createDelegate() {
Session session = (keyspace != null && !keyspace.equals("")) ? cluster.connect(keyspace) : cluster.connect();

return smartthings.brave.cassandra.TracedSession.create(session, brave, config.getServiceName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.datastax.driver.core.Statement;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Map;
import java.util.Optional;
import ratpack.exec.Promise;
import ratpack.service.Service;
import ratpack.service.StartEvent;
Expand All @@ -26,17 +25,17 @@
public abstract class AbstractSession implements RatpackSession, Session, Service {

private final Cluster cluster;
private final Optional<String> keyspace;
private final String keyspace;
private Session delegate;

AbstractSession(Cluster cluster) {
public AbstractSession(Cluster cluster) {
this.cluster = cluster;
this.keyspace = Optional.empty();
this.keyspace = null;
}

AbstractSession(Cluster cluster, String keyspace) {
public AbstractSession(Cluster cluster, String keyspace) {
this.cluster = cluster;
this.keyspace = Optional.of(keyspace);
this.keyspace = keyspace;
}

@Override
Expand Down Expand Up @@ -212,6 +211,6 @@ protected final Session getDelegate() {
}

protected Session createDelegate() {
return (keyspace.isPresent()) ? cluster.connect(keyspace.get()) : cluster.connect();
return (keyspace != null && !keyspace.equals("")) ? cluster.connect(keyspace) : cluster.connect();
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include 'ratpack-cassandra'
include 'ratpack-cassandra-rx'
include 'ratpack-cassandra-migrate'
include 'ratpack-cassandra-tracing'

rootProject.name='ratpack-cassandra-parent'

0 comments on commit 6dafbc6

Please sign in to comment.