Search in sources :

Example 81 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class DependenciesTest method getDependenciesAllInstrumented.

/**
   * When all servers are instrumented, they all log a {@link Constants#SERVER_RECV ("sr")}
   * annotation, indicating the service.
   */
@Test
public void getDependenciesAllInstrumented() {
    Endpoint one = Endpoint.create("trace-producer-one", 127 << 24 | 1);
    Endpoint onePort3001 = one.toBuilder().port((short) 3001).build();
    Endpoint two = Endpoint.create("trace-producer-two", 127 << 24 | 2);
    Endpoint twoPort3002 = two.toBuilder().port((short) 3002).build();
    Endpoint three = Endpoint.create("trace-producer-three", 127 << 24 | 3);
    List<Span> trace = asList(Span.builder().traceId(10L).id(10L).name("get").timestamp(1445136539256150L).duration(1152579L).addAnnotation(Annotation.create(1445136539256150L, SERVER_RECV, one)).addAnnotation(Annotation.create(1445136540408729L, SERVER_SEND, one)).build(), Span.builder().traceId(10L).parentId(10L).id(20L).name("get").timestamp(1445136539764798L).duration(639337L).addAnnotation(Annotation.create(1445136539764798L, CLIENT_SEND, onePort3001)).addAnnotation(Annotation.create(1445136539816432L, SERVER_RECV, two)).addAnnotation(Annotation.create(1445136540401414L, SERVER_SEND, two)).addAnnotation(Annotation.create(1445136540404135L, CLIENT_RECV, onePort3001)).build(), Span.builder().traceId(10L).parentId(20L).id(30L).name("get").timestamp(1445136540025751L).duration(371298L).addAnnotation(Annotation.create(1445136540025751L, CLIENT_SEND, twoPort3002)).addAnnotation(Annotation.create(1445136540072846L, SERVER_RECV, three)).addAnnotation(Annotation.create(1445136540394644L, SERVER_SEND, three)).addAnnotation(Annotation.create(1445136540397049L, CLIENT_RECV, twoPort3002)).build());
    processDependencies(trace);
    long traceDuration = trace.get(0).duration;
    assertThat(store().getDependencies((trace.get(0).timestamp + traceDuration) / 1000, traceDuration / 1000)).containsOnly(DependencyLink.create("trace-producer-one", "trace-producer-two", 1), DependencyLink.create("trace-producer-two", "trace-producer-three", 1));
}
Also used : Endpoint(zipkin.Endpoint) Span(zipkin.Span) Test(org.junit.Test)

Example 82 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class SpanStoreTest method readsBackLargeValues.

/**
   * While large spans are discouraged, and maybe not indexed, we should be able to read them back.
   */
@Test
public void readsBackLargeValues() {
    char[] kilobyteOfText = new char[1024];
    Arrays.fill(kilobyteOfText, 'a');
    // Make a span that's over 1KiB in size
    Span span = Span.builder().traceId(1L).name("big").id(1L).timestamp(today * 1000 + 100L).duration(200L).addBinaryAnnotation(BinaryAnnotation.create("a", new String(kilobyteOfText), ep)).build();
    accept(span);
    // read back to ensure the data wasn't truncated
    assertThat(store().getTraces(QueryRequest.builder().build())).containsExactly(asList(span));
    assertThat(store().getTrace(span.traceIdHigh, span.traceId)).isEqualTo(asList(span));
}
Also used : Span(zipkin.Span) Test(org.junit.Test)

Example 83 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class SpanStoreTest method getTraces_manyTraces.

/**
   * Formerly, a bug was present where cassandra didn't index more than bucket count traces per
   * millisecond. This stores a lot of spans to ensure indexes work under high-traffic scenarios.
   */
@Test
public void getTraces_manyTraces() {
    int traceCount = 1000;
    Span span = TestObjects.LOTS_OF_SPANS[0];
    BinaryAnnotation b = span.binaryAnnotations.get(0);
    accept(Arrays.copyOfRange(TestObjects.LOTS_OF_SPANS, 0, traceCount));
    assertThat(store().getTraces(new QueryRequest.Builder().limit(traceCount).build())).hasSize(traceCount);
    QueryRequest.Builder builder = QueryRequest.builder().limit(traceCount).serviceName(b.endpoint.serviceName);
    assertThat(store().getTraces(builder.build())).hasSize(traceCount);
    assertThat(store().getTraces(builder.spanName(span.name).build())).hasSize(traceCount);
    assertThat(store().getTraces(builder.addBinaryAnnotation(b.key, new String(b.value)).build())).hasSize(traceCount);
}
Also used : BinaryAnnotation(zipkin.BinaryAnnotation) Span(zipkin.Span) Endpoint(zipkin.Endpoint) Test(org.junit.Test)

Example 84 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class SpanStoreTest method getTraces_multipleAnnotationsBecomeAndFilter.

@Test
public void getTraces_multipleAnnotationsBecomeAndFilter() {
    Span foo = Span.builder().traceId(1).name("call1").id(1).timestamp((today + 1) * 1000).addAnnotation(Annotation.create((today + 1) * 1000, "foo", ep)).build();
    // would be foo bar, except lexicographically bar precedes foo
    Span barAndFoo = Span.builder().traceId(2).name("call2").id(2).timestamp((today + 2) * 1000).addAnnotation(Annotation.create((today + 2) * 1000, "bar", ep)).addAnnotation(Annotation.create((today + 2) * 1000, "foo", ep)).build();
    Span fooAndBazAndQux = Span.builder().traceId(3).name("call3").id(3).timestamp((today + 3) * 1000).addAnnotation(Annotation.create((today + 3) * 1000, "foo", ep)).addBinaryAnnotation(BinaryAnnotation.create("baz", "qux", ep)).build();
    Span barAndFooAndBazAndQux = Span.builder().traceId(4).name("call4").id(4).timestamp((today + 4) * 1000).addAnnotation(Annotation.create((today + 4) * 1000, "bar", ep)).addAnnotation(Annotation.create((today + 4) * 1000, "foo", ep)).addBinaryAnnotation(BinaryAnnotation.create("baz", "qux", ep)).build();
    accept(foo, barAndFoo, fooAndBazAndQux, barAndFooAndBazAndQux);
    assertThat(store().getTraces(QueryRequest.builder().serviceName("service").addAnnotation("foo").build())).containsExactly(asList(barAndFooAndBazAndQux), asList(fooAndBazAndQux), asList(barAndFoo), asList(foo));
    assertThat(store().getTraces(QueryRequest.builder().serviceName("service").addAnnotation("foo").addAnnotation("bar").build())).containsExactly(asList(barAndFooAndBazAndQux), asList(barAndFoo));
    assertThat(store().getTraces(QueryRequest.builder().serviceName("service").addAnnotation("foo").addAnnotation("bar").addBinaryAnnotation("baz", "qux").build())).containsExactly(asList(barAndFooAndBazAndQux));
}
Also used : Span(zipkin.Span) Test(org.junit.Test)

Example 85 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class SpanStoreTest method clientTimestampAndDurationWinInSharedSpan.

/**
   * This test shows that regardless of whether span.timestamp and duration are set directly or
   * derived from annotations, the client wins vs the server. This is important because the client
   * holds the critical path of a shared span.
   */
@Test
public void clientTimestampAndDurationWinInSharedSpan() {
    Endpoint client = Endpoint.create("client", 192 << 24 | 168 << 16 | 1);
    Endpoint server = Endpoint.create("server", 192 << 24 | 168 << 16 | 2);
    long clientTimestamp = (today + 100) * 1000;
    long clientDuration = 35 * 1000;
    // both client and server set span.timestamp, duration
    Span clientView = Span.builder().traceId(1).name("direct").id(666).timestamp(clientTimestamp).duration(clientDuration).addAnnotation(Annotation.create((today + 100) * 1000, CLIENT_SEND, client)).addAnnotation(Annotation.create((today + 135) * 1000, CLIENT_RECV, client)).build();
    Span serverView = Span.builder().traceId(1).name("direct").id(666).timestamp((today + 105) * 1000).duration(25 * 1000L).addAnnotation(Annotation.create((today + 105) * 1000, SERVER_RECV, server)).addAnnotation(Annotation.create((today + 130) * 1000, SERVER_SEND, server)).build();
    // neither client, nor server set span.timestamp, duration
    Span clientViewDerived = Span.builder().traceId(1).name("derived").id(666).addAnnotation(Annotation.create(clientTimestamp, CLIENT_SEND, client)).addAnnotation(Annotation.create(clientTimestamp + clientDuration, CLIENT_RECV, client)).build();
    Span serverViewDerived = Span.builder().traceId(1).name("derived").id(666).addAnnotation(Annotation.create((today + 105) * 1000, SERVER_RECV, server)).addAnnotation(Annotation.create((today + 130) * 1000, SERVER_SEND, server)).build();
    // server span hits the collection tier first
    accept(serverView, serverViewDerived);
    // intentionally different collection event
    accept(clientView, clientViewDerived);
    for (Span span : store().getTrace(clientView.traceIdHigh, clientView.traceId)) {
        assertThat(span.timestamp).isEqualTo(clientTimestamp);
        assertThat(span.duration).isEqualTo(clientDuration);
    }
}
Also used : Endpoint(zipkin.Endpoint) Span(zipkin.Span) Test(org.junit.Test)

Aggregations

Span (zipkin.Span)104 Test (org.junit.Test)84 Endpoint (zipkin.Endpoint)21 BinaryAnnotation (zipkin.BinaryAnnotation)12 ArrayList (java.util.ArrayList)11 Annotation (zipkin.Annotation)10 CodecTest (zipkin.CodecTest)9 CorrectForClockSkew.isLocalSpan (zipkin.internal.CorrectForClockSkew.isLocalSpan)9 ByteBuffer (java.nio.ByteBuffer)8 List (java.util.List)8 Buffer (okio.Buffer)8 LinkedHashMap (java.util.LinkedHashMap)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ImmutableList (com.google.common.collect.ImmutableList)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 LinkedList (java.util.LinkedList)4 Constants (zipkin.Constants)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 IOException (java.io.IOException)3 Arrays.asList (java.util.Arrays.asList)3