Skip to content

Commit

Permalink
Backfills tests for async spans in the dependencies graph
Browse files Browse the repository at this point in the history
This unveiled a small bug left unnoticed.
  • Loading branch information
Adrian Cole committed Jan 9, 2017
1 parent 6e998f7 commit 4d1c63e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
5 changes: 3 additions & 2 deletions zipkin/src/main/java/zipkin/storage/QueryRequest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015-2016 The OpenZipkin Authors
* Copyright 2015-2017 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -24,6 +24,7 @@
import zipkin.BinaryAnnotation;
import zipkin.Endpoint;
import zipkin.Span;
import zipkin.internal.ApplyTimestampAndDuration;
import zipkin.internal.Nullable;

import static zipkin.Constants.CORE_ANNOTATIONS;
Expand Down Expand Up @@ -356,7 +357,7 @@ public int hashCode() {

/** Tests the supplied trace against the current request */
public boolean test(List<Span> spans) {
Long timestamp = spans.get(0).timestamp;
Long timestamp = ApplyTimestampAndDuration.guessTimestamp(spans.get(0));
if (timestamp == null ||
timestamp < (endTs - lookback) * 1000 ||
timestamp > endTs * 1000) {
Expand Down
51 changes: 47 additions & 4 deletions zipkin/src/test/java/zipkin/storage/DependenciesTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015-2016 The OpenZipkin Authors
* Copyright 2015-2017 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -33,6 +33,7 @@
import static zipkin.Constants.CLIENT_ADDR;
import static zipkin.Constants.CLIENT_RECV;
import static zipkin.Constants.CLIENT_SEND;
import static zipkin.Constants.LOCAL_COMPONENT;
import static zipkin.Constants.SERVER_ADDR;
import static zipkin.Constants.SERVER_RECV;
import static zipkin.Constants.SERVER_SEND;
Expand Down Expand Up @@ -476,7 +477,7 @@ public void intermediateSpans() {
Span.builder().traceId(20L).parentId(20L).id(21L).name("call")
.timestamp((TODAY + 25) * 1000).duration(325L * 1000)
.addBinaryAnnotation(
BinaryAnnotation.create(Constants.LOCAL_COMPONENT, "depth2", WEB_ENDPOINT)).build(),
BinaryAnnotation.create(LOCAL_COMPONENT, "depth2", WEB_ENDPOINT)).build(),
Span.builder().traceId(20L).parentId(21L).id(22L).name("get")
.timestamp((TODAY + 50) * 1000).duration(250L * 1000)
.addAnnotation(Annotation.create((TODAY + 50) * 1000, CLIENT_SEND, WEB_ENDPOINT))
Expand All @@ -486,11 +487,11 @@ public void intermediateSpans() {
Span.builder().traceId(20L).parentId(22L).id(23L).name("call")
.timestamp((TODAY + 110) * 1000).duration(130L * 1000)
.addBinaryAnnotation(
BinaryAnnotation.create(Constants.LOCAL_COMPONENT, "depth4", APP_ENDPOINT)).build(),
BinaryAnnotation.create(LOCAL_COMPONENT, "depth4", APP_ENDPOINT)).build(),
Span.builder().traceId(20L).parentId(23L).id(24L).name("call")
.timestamp((TODAY + 125) * 1000).duration(105L * 1000)
.addBinaryAnnotation(
BinaryAnnotation.create(Constants.LOCAL_COMPONENT, "depth5", APP_ENDPOINT)).build(),
BinaryAnnotation.create(LOCAL_COMPONENT, "depth5", APP_ENDPOINT)).build(),
Span.builder().traceId(20L).parentId(24L).id(25L).name("get")
.timestamp((TODAY + 150) * 1000).duration(50L * 1000)
.addAnnotation(Annotation.create((TODAY + 150) * 1000, CLIENT_SEND, APP_ENDPOINT))
Expand Down Expand Up @@ -558,6 +559,48 @@ public void unmergedSpans() {
);
}

/**
* Span starts on one host and ends on the other. In both cases, a response is neither sent nor
* received.
*/
@Test
public void oneway() {
List<Span> trace = asList(
Span.builder().traceId(10L).id(10L).name("")
.addAnnotation(Annotation.create((TODAY + 50) * 1000, CLIENT_SEND, WEB_ENDPOINT))
.addAnnotation(Annotation.create((TODAY + 100) * 1000, SERVER_RECV, APP_ENDPOINT))
.build()
);

processDependencies(trace);

assertThat(store().getDependencies(TODAY + 1000L, null)).containsOnly(
DependencyLink.create("web", "app", 1)
);
}

/** Async span starts from an uninstrumented source. */
@Test
public void oneway_noClient() {
Endpoint kafka = Endpoint.create("kafka", 172 << 24 | 17 << 16 | 4);

List<Span> trace = asList(
Span.builder().traceId(10L).id(10L).name("receive")
.addAnnotation(Annotation.create((TODAY) * 1000, SERVER_RECV, APP_ENDPOINT))
.addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, kafka))
.build(),
Span.builder().traceId(10L).parentId(10L).id(11L).name("process")
.timestamp((TODAY + 25) * 1000).duration(325L * 1000)
.addBinaryAnnotation(BinaryAnnotation.create(LOCAL_COMPONENT, "", APP_ENDPOINT)).build()
);

processDependencies(trace);

assertThat(store().getDependencies(TODAY + 1000L, null)).containsOnly(
DependencyLink.create("kafka", "app", 1)
);
}

/** rebases a trace backwards a day with different trace and span id. */
List<Span> subtractDay(List<Span> trace) {
return trace.stream()
Expand Down
21 changes: 20 additions & 1 deletion zipkin/src/test/java/zipkin/storage/QueryRequestTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015-2016 The OpenZipkin Authors
* Copyright 2015-2017 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -16,9 +16,15 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import zipkin.Annotation;
import zipkin.Constants;
import zipkin.Span;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static zipkin.Constants.SERVER_RECV;
import static zipkin.TestObjects.APP_ENDPOINT;
import static zipkin.TestObjects.TODAY;
import static zipkin.TraceKeys.HTTP_METHOD;

public class QueryRequestTest {
Expand Down Expand Up @@ -178,4 +184,17 @@ public void maxDuration_greaterThanOrEqualToMinDuration() {

QueryRequest.builder().serviceName("foo").minDuration(1L).maxDuration(0L).build();
}

/** When a span comes in without a timestamp, use the implicit one based on annotations. */
@Test
public void matchesImplicitTimestamp() {
Span asyncReceive = Span.builder().traceId(10L).id(10L).name("receive")
.addAnnotation(Annotation.create((TODAY) * 1000, SERVER_RECV, APP_ENDPOINT))
.build();

QueryRequest request = QueryRequest.builder().endTs(TODAY).build();

assertThat(request.test(asList(asyncReceive)))
.isTrue();
}
}

0 comments on commit 4d1c63e

Please sign in to comment.