Search in sources :

Example 16 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class TraceTest method cleanupComparator_transitiveKindComparison.

/**
 * Comparators are meant to be transitive. This exploits edge cases to fool our comparator.
 */
@Test
public void cleanupComparator_transitiveKindComparison() {
    List<Span> trace = new ArrayList<>();
    Endpoint aEndpoint = Endpoint.newBuilder().serviceName("a").build();
    Endpoint bEndpoint = Endpoint.newBuilder().serviceName("b").build();
    Span template = Span.newBuilder().traceId("a").id("a").build();
    // when there are at least 32 elements.
    for (int i = 0, length = 7; i < length; i++) {
        trace.add(template.toBuilder().shared(true).localEndpoint(bEndpoint).build());
        trace.add(template.toBuilder().kind(Kind.CLIENT).localEndpoint(bEndpoint).build());
        trace.add(template.toBuilder().localEndpoint(aEndpoint).build());
        trace.add(template);
        trace.add(template.toBuilder().kind(Kind.CLIENT).localEndpoint(aEndpoint).build());
    }
    Collections.sort(trace, Trace.CLEANUP_COMPARATOR);
    assertThat(new LinkedHashSet<>(trace)).extracting(Span::shared, Span::kind, s -> s.localServiceName()).containsExactly(tuple(null, Kind.CLIENT, "a"), tuple(null, Kind.CLIENT, "b"), tuple(null, null, null), tuple(null, null, "a"), tuple(true, null, "b"));
}
Also used : List(java.util.List) Endpoint(zipkin2.Endpoint) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Arrays.asList(java.util.Arrays.asList) Kind(zipkin2.Span.Kind) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Span(zipkin2.Span) Test(org.junit.Test) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Endpoint(zipkin2.Endpoint) ArrayList(java.util.ArrayList) Span(zipkin2.Span) Endpoint(zipkin2.Endpoint) Test(org.junit.Test)

Example 17 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class InMemoryStorageTest method replayOverwrites.

/**
 * It should be safe to run dependency link jobs twice
 */
@Test
public void replayOverwrites() throws IOException {
    Span span = Span.newBuilder().traceId("10").id("10").name("receive").kind(Span.Kind.CONSUMER).localEndpoint(Endpoint.newBuilder().serviceName("app").build()).remoteEndpoint(Endpoint.newBuilder().serviceName("kafka").build()).timestamp(TODAY * 1000).build();
    storage.accept(asList(span)).execute();
    storage.accept(asList(span)).execute();
    assertThat(storage.getDependencies(TODAY + 1000L, TODAY).execute()).containsOnly(DependencyLink.newBuilder().parent("kafka").child("app").callCount(1L).build());
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 18 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class SpanConverterTest method lateRemoteEndpoint_ss.

/**
 * Late flushed data on a v2 span
 */
@Test
public void lateRemoteEndpoint_ss() {
    Span v2 = Span.newBuilder().traceId("1").id("2").name("get").kind(Kind.SERVER).localEndpoint(BACKEND).remoteEndpoint(FRONTEND).addAnnotation(1472470996199000L, "ss").build();
    V1Span v1 = V1Span.newBuilder().traceId(1L).id(2L).name("get").addAnnotation(1472470996199000L, "ss", BACKEND).addBinaryAnnotation("ca", FRONTEND).build();
    assertThat(v2SpanConverter.convert(v2)).usingRecursiveComparison().isEqualTo(v1);
    assertThat(v1SpanConverter.convert(v1)).containsExactly(v2);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 19 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class SpanConverterTest method server_incomplete_shared.

@Test
public void server_incomplete_shared() {
    Span v2 = Span.newBuilder().traceId("1").parentId('2').id("3").name("get").kind(Kind.SERVER).shared(true).localEndpoint(BACKEND).timestamp(1472470996199000L).build();
    V1Span v1 = V1Span.newBuilder().traceId("1").parentId('2').id("3").name("get").addAnnotation(1472470996199000L, "sr", BACKEND).build();
    assertThat(v2SpanConverter.convert(v2)).usingRecursiveComparison().isEqualTo(v1);
    assertThat(v1SpanConverter.convert(v1)).containsExactly(v2);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 20 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class SpanConverterTest method clientAndServer.

@Test
public void clientAndServer() {
    V1Span v1 = V1Span.newBuilder().traceId(1L).parentId(2L).id(3L).name("get").timestamp(1472470996199000L).duration(207000L).addAnnotation(1472470996199000L, "cs", FRONTEND).addAnnotation(1472470996238000L, "ws", FRONTEND).addAnnotation(1472470996250000L, "sr", BACKEND).addAnnotation(1472470996350000L, "ss", BACKEND).addAnnotation(1472470996403000L, "wr", FRONTEND).addAnnotation(1472470996406000L, "cr", FRONTEND).addBinaryAnnotation("http.path", "/api", FRONTEND).addBinaryAnnotation("http.path", "/BACKEND", BACKEND).addBinaryAnnotation("clnt/finagle.version", "6.45.0", FRONTEND).addBinaryAnnotation("srv/finagle.version", "6.44.0", BACKEND).addBinaryAnnotation("ca", FRONTEND).addBinaryAnnotation("sa", BACKEND).build();
    Span.Builder newBuilder = Span.newBuilder().traceId("1").parentId("2").id("3").name("get");
    // the v1 side owns timestamp and duration
    Span clientV2 = newBuilder.clone().kind(Kind.CLIENT).localEndpoint(FRONTEND).remoteEndpoint(BACKEND).timestamp(1472470996199000L).duration(207000L).addAnnotation(1472470996238000L, "ws").addAnnotation(1472470996403000L, "wr").putTag("http.path", "/api").putTag("clnt/finagle.version", "6.45.0").build();
    // notice v1 tags are different than the v1, and the v1's annotations aren't here
    Span serverV2 = newBuilder.clone().kind(Kind.SERVER).shared(true).localEndpoint(BACKEND).remoteEndpoint(FRONTEND).timestamp(1472470996250000L).duration(100000L).putTag("http.path", "/BACKEND").putTag("srv/finagle.version", "6.44.0").build();
    assertThat(v1SpanConverter.convert(v1)).containsExactly(clientV2, serverV2);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Aggregations

Span (zipkin2.Span)82 Test (org.junit.Test)54 Endpoint (zipkin2.Endpoint)25 Test (org.junit.jupiter.api.Test)17 V1Span (zipkin2.v1.V1Span)10 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)8 IOException (java.io.IOException)6 Map (java.util.Map)5 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)5 Tracer (brave.Tracer)4 Tracing (brave.Tracing)4 Trace (com.google.devtools.cloudtrace.v1.Trace)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Before (org.junit.Before)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Span (brave.Span)3 Sampler (brave.sampler.Sampler)3 Annotation (zipkin2.Annotation)3