Search in sources :

Example 16 with Endpoint

use of zipkin.Endpoint 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)

Example 17 with Endpoint

use of zipkin.Endpoint in project zipkin by openzipkin.

the class SpanStoreTest method whenSpanTimestampIsMissingClientSendIsPreferred.

/**
   * Spans report depth-first. Make sure the client timestamp is preferred when instrumentation
   * don't add a timestamp.
   */
@Test
public void whenSpanTimestampIsMissingClientSendIsPreferred() {
    Endpoint frontend = Endpoint.create("frontend", 192 << 24 | 168 << 16 | 2);
    Annotation cs = Annotation.create((today + 50) * 1000, CLIENT_SEND, frontend);
    Annotation cr = Annotation.create((today + 150) * 1000, CLIENT_RECV, frontend);
    Endpoint backend = Endpoint.create("backend", 192 << 24 | 168 << 16 | 2);
    Annotation sr = Annotation.create((today + 95) * 1000, SERVER_RECV, backend);
    Annotation ss = Annotation.create((today + 100) * 1000, SERVER_SEND, backend);
    Span span = Span.builder().traceId(1).name("method1").id(666).build();
    // Simulate the server-side of a shared span arriving first
    accept(span.toBuilder().addAnnotation(sr).addAnnotation(ss).build());
    accept(span.toBuilder().addAnnotation(cs).addAnnotation(cr).build());
    // Make sure that the client's timestamp won
    assertThat(store().getTrace(span1.traceIdHigh, span.traceId)).containsExactly(span.toBuilder().timestamp(cs.timestamp).duration(cr.timestamp - cs.timestamp).annotations(asList(cs, sr, ss, cr)).build());
}
Also used : Endpoint(zipkin.Endpoint) Span(zipkin.Span) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation) Test(org.junit.Test)

Example 18 with Endpoint

use of zipkin.Endpoint in project zipkin by openzipkin.

the class DependenciesTest method oneway_noClient.

/** 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));
}
Also used : Endpoint(zipkin.Endpoint) Span(zipkin.Span) Test(org.junit.Test)

Example 19 with Endpoint

use of zipkin.Endpoint in project zipkin by openzipkin.

the class DependenciesTest method noCoreAnnotations.

/** This test confirms that core ("sr", "cs", "cr", "ss") annotations are not required. */
@Test
public void noCoreAnnotations() {
    Endpoint someClient = Endpoint.create("some-client", 172 << 24 | 17 << 16 | 4);
    List<Span> trace = asList(Span.builder().traceId(20L).id(20L).name("get").timestamp(TODAY * 1000).duration(350L * 1000).addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, someClient)).addBinaryAnnotation(BinaryAnnotation.address(SERVER_ADDR, WEB_ENDPOINT)).build(), Span.builder().traceId(20L).parentId(20L).id(21L).name("get").timestamp((TODAY + 50) * 1000).duration(250L * 1000).addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, WEB_ENDPOINT)).addBinaryAnnotation(BinaryAnnotation.address(SERVER_ADDR, APP_ENDPOINT)).build(), Span.builder().traceId(20L).parentId(21L).id(22L).name("get").timestamp((TODAY + 150) * 1000).duration(50L * 1000).addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, APP_ENDPOINT)).addBinaryAnnotation(BinaryAnnotation.address(SERVER_ADDR, DB_ENDPOINT)).build());
    processDependencies(trace);
    assertThat(store().getDependencies(TODAY + 1000, null)).containsOnly(DependencyLink.create("some-client", "web", 1), DependencyLink.create("web", "app", 1), DependencyLink.create("app", "db", 1));
}
Also used : Endpoint(zipkin.Endpoint) Span(zipkin.Span) Test(org.junit.Test)

Example 20 with Endpoint

use of zipkin.Endpoint in project zipkin by openzipkin.

the class DependenciesTest method getDependencies_noTimestamps.

/**
   * Legacy instrumentation don't set Span.timestamp or duration. Make sure dependencies still work.
   */
@Test
public void getDependencies_noTimestamps() {
    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").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").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").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 = ApplyTimestampAndDuration.apply(trace.get(0)).duration;
    assertThat(store().getDependencies((trace.get(0).annotations.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)

Aggregations

Endpoint (zipkin.Endpoint)24 Test (org.junit.Test)20 Span (zipkin.Span)16 BinaryAnnotation (zipkin.BinaryAnnotation)8 Annotation (zipkin.Annotation)6 ArrayList (java.util.ArrayList)3 List (java.util.List)2 QueryRequest (zipkin.storage.QueryRequest)2 SpanStoreTest (zipkin.storage.SpanStoreTest)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 LinkedHashMap (java.util.LinkedHashMap)1 Collectors.toList (java.util.stream.Collectors.toList)1 Buffer (okio.Buffer)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Condition (org.jooq.Condition)1