Skip to content

Commit

Permalink
clarifies index timestamp creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Oct 18, 2017
1 parent a8cf1a5 commit 40fff73
Showing 1 changed file with 27 additions and 26 deletions.
Expand Up @@ -102,22 +102,27 @@ final class CassandraSpanConsumer implements SpanConsumer {
public Call<Void> accept(List<Span> spans) {
for (Span s : spans) {
// indexing occurs by timestamp, so derive one if not present.
long timestamp = s.timestamp() != null ? s.timestamp() : guessTimestamp(s);
storeSpan(s, timestamp);
long ts_micro = s.timestamp() != null ? s.timestamp() : guessTimestamp(s);
UUID ts_uuid = new UUID(
UUIDs.startOf(ts_micro / 1000L).getMostSignificantBits(),
UUIDs.random().getLeastSignificantBits());

storeSpan(s, ts_uuid);

String span = null != s.name() ? s.name() : "";
if (null != s.remoteServiceName()) { // allows getServices to return remote service names
storeServiceSpanName(s.remoteServiceName(), span);
}

String service = s.localServiceName();
if (null == service) continue;
storeServiceSpanName(service, span);

// Contract for Repository.storeTraceServiceSpanName is to store the span twice, once with
// the span name and another with empty string.
String localServiceName = s.localServiceName();
String spanName = null != s.name() ? s.name() : "";
if (null != localServiceName) {
storeTraceServiceSpanName(localServiceName, spanName, timestamp, s.duration(), s.traceId());
if (!spanName.isEmpty()) { // Allows lookup without the span name
storeTraceServiceSpanName(localServiceName, "", timestamp, s.duration(), s.traceId());
}
storeServiceSpanName(localServiceName, spanName);
}
if (null != s.remoteServiceName()) { // allows getServices to return remote service names
storeServiceSpanName(s.remoteServiceName(), spanName);
storeTraceServiceSpanName(s.traceId(), service, span, ts_micro, ts_uuid, s.duration());
if (!span.isEmpty()) { // Allows lookup without the span name
storeTraceServiceSpanName(s.traceId(), service, "", ts_micro, ts_uuid, s.duration());
}
}
return Call.create(null /* Void == null */);
Expand All @@ -126,15 +131,13 @@ public Call<Void> accept(List<Span> spans) {
/**
* Store the span in the underlying storage for later retrieval.
*/
void storeSpan(Span span, long timestamp) {
void storeSpan(Span span, UUID ts_uuid) {
try {
boolean traceIdHigh = !strictTraceId && span.traceId().length() == 32;

// start with the partition key
BoundStatement bound = bindWithName(insertSpan, "insert-span")
.setUUID("ts_uuid", new UUID(
UUIDs.startOf(timestamp / 1000).getMostSignificantBits(),
UUIDs.random().getLeastSignificantBits()))
.setUUID("ts_uuid", ts_uuid)
.setString("trace_id", traceIdHigh ? span.traceId().substring(16) : span.traceId())
.setString("id", span.id());

Expand Down Expand Up @@ -189,24 +192,22 @@ void storeSpan(Span span, long timestamp) {
}

void storeTraceServiceSpanName(
String traceId,
String serviceName,
String spanName,
long timestamp_micro,
Long duration,
String traceId) {
long ts_micro,
UUID ts_uuid,
Long duration) {

int bucket = durationIndexBucket(timestamp_micro);
UUID ts = new UUID(
UUIDs.startOf(timestamp_micro / 1000).getMostSignificantBits(),
UUIDs.random().getLeastSignificantBits());
int bucket = durationIndexBucket(ts_micro);
try {
BoundStatement bound =
bindWithName(insertTraceServiceSpanName, "insert-trace-service-span-name")
.setString("trace_id", traceId)
.setString("service", serviceName)
.setString("span", spanName)
.setInt("bucket", bucket)
.setUUID("ts", ts)
.setString("trace_id", traceId);
.setUUID("ts", ts_uuid);

if (null != duration) {
// round up to tens of milliseconds (or hundredths of seconds)
Expand Down

0 comments on commit 40fff73

Please sign in to comment.