Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backfills tests for async spans in the dependencies graph #1478

Merged
merged 1 commit into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -34,6 +34,7 @@

import static zipkin.TestObjects.DAY;
import static zipkin.TestObjects.TODAY;
import static zipkin.internal.ApplyTimestampAndDuration.guessTimestamp;
import static zipkin.internal.Util.midnightUTC;

public class CassandraDependenciesTest extends DependenciesTest {
Expand Down Expand Up @@ -68,7 +69,7 @@ public void processDependencies(List<Span> spans) {
List<DependencyLink> links = mem.spanStore().getDependencies(TODAY + DAY, null);

// This gets or derives a timestamp from the spans
long midnight = midnightUTC(MergeById.apply(spans).get(0).timestamp / 1000);
long midnight = midnightUTC(guessTimestamp(MergeById.apply(spans).get(0)) / 1000);
new CassandraDependenciesWriter(storage.session.get()).write(links, midnight);
}

Expand Down
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 @@ -27,6 +27,7 @@

import static zipkin.TestObjects.DAY;
import static zipkin.TestObjects.TODAY;
import static zipkin.internal.ApplyTimestampAndDuration.guessTimestamp;
import static zipkin.internal.Util.midnightUTC;

public abstract class ElasticsearchDependenciesTest extends DependenciesTest {
Expand All @@ -50,7 +51,7 @@ public abstract class ElasticsearchDependenciesTest extends DependenciesTest {
List<DependencyLink> links = mem.spanStore().getDependencies(TODAY + DAY, null);

// This gets or derives a timestamp from the spans
long midnight = midnightUTC(MergeById.apply(spans).get(0).timestamp / 1000);
long midnight = midnightUTC(guessTimestamp(MergeById.apply(spans).get(0)) / 1000);
writeDependencyLinks(links, midnight);
}

Expand Down
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 @@ -28,6 +28,7 @@

import static zipkin.TestObjects.DAY;
import static zipkin.TestObjects.TODAY;
import static zipkin.internal.ApplyTimestampAndDuration.guessTimestamp;
import static zipkin.internal.Util.midnightUTC;

public abstract class ElasticsearchDependenciesTest extends DependenciesTest {
Expand All @@ -51,7 +52,7 @@ public abstract class ElasticsearchDependenciesTest extends DependenciesTest {
List<DependencyLink> links = mem.spanStore().getDependencies(TODAY + DAY, null);

// This gets or derives a timestamp from the spans
long midnight = midnightUTC(MergeById.apply(spans).get(0).timestamp / 1000);
long midnight = midnightUTC(guessTimestamp(MergeById.apply(spans).get(0)) / 1000);
writeDependencyLinks(links, midnight);
}

Expand Down
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();
}
}