Search in sources :

Example 41 with Kind

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

the class ITSpanStore method getTraces_differentiateOnServiceName.

/**
 * This test makes sure that annotation queries pay attention to which host recorded data
 */
@Test
protected void getTraces_differentiateOnServiceName(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    Endpoint frontend = suffixServiceName(TestObjects.FRONTEND, testSuffix);
    Endpoint backend = suffixServiceName(TestObjects.BACKEND, testSuffix);
    Span trace1 = Span.newBuilder().traceId(newTraceId()).name("1").id(1).kind(CLIENT).timestamp((TODAY + 1) * 1000L).duration(3000L).localEndpoint(frontend).addAnnotation(((TODAY + 1) * 1000L) + 500, "web").putTag("local", "web").putTag("web-b", "web").build();
    Span trace1Server = Span.newBuilder().traceId(trace1.traceId()).name("1").id(1).kind(SERVER).shared(true).localEndpoint(backend).timestamp((TODAY + 2) * 1000L).duration(1000L).build();
    Span trace2 = Span.newBuilder().traceId(newTraceId()).name("2").id(2).timestamp((TODAY + 11) * 1000L).duration(3000L).kind(CLIENT).localEndpoint(backend).addAnnotation(((TODAY + 11) * 1000) + 500, "app").putTag("local", "app").putTag("app-b", "app").build();
    Span trace2Server = Span.newBuilder().traceId(trace2.traceId()).name("2").id(2).shared(true).kind(SERVER).localEndpoint(frontend).timestamp((TODAY + 12) * 1000L).duration(1000L).build();
    accept(trace1, trace1Server, trace2, trace2Server);
    // Sanity check
    assertGetTraceReturns(trace1.traceId(), asList(trace1, trace1Server));
    assertGetTraceReturns(trace2.traceId(), asList(trace2, trace2Server));
    assertGetTracesReturns(requestBuilder().build(), asList(trace1, trace1Server), asList(trace2, trace2Server));
    // We only return traces where the service specified caused the data queried.
    assertGetTracesReturns(requestBuilder().serviceName(frontend.serviceName()).parseAnnotationQuery("web").build(), asList(trace1, trace1Server));
    assertGetTracesReturnsEmpty(requestBuilder().serviceName(backend.serviceName()).parseAnnotationQuery("web").build());
    assertGetTracesReturns(requestBuilder().serviceName(backend.serviceName()).parseAnnotationQuery("app").build(), asList(trace2, trace2Server));
    assertGetTracesReturnsEmpty(requestBuilder().serviceName(frontend.serviceName()).parseAnnotationQuery("app").build());
    // tags are returned on annotation queries
    assertGetTracesReturns(requestBuilder().serviceName(frontend.serviceName()).parseAnnotationQuery("web-b").build(), asList(trace1, trace1Server));
    assertGetTracesReturnsEmpty(requestBuilder().serviceName(backend.serviceName()).parseAnnotationQuery("web-b").build());
    assertGetTracesReturns(requestBuilder().serviceName(backend.serviceName()).parseAnnotationQuery("app-b").build(), asList(trace2, trace2Server));
    assertGetTracesReturnsEmpty(requestBuilder().serviceName(frontend.serviceName()).parseAnnotationQuery("app-b").build());
    // We only return traces where the service specified caused the tag queried.
    assertGetTracesReturns(requestBuilder().serviceName(frontend.serviceName()).parseAnnotationQuery("local=web").build(), asList(trace1, trace1Server));
    assertGetTracesReturnsEmpty(requestBuilder().serviceName(backend.serviceName()).parseAnnotationQuery("local=web").build());
    assertGetTracesReturns(requestBuilder().serviceName(backend.serviceName()).parseAnnotationQuery("local=app").build(), asList(trace2, trace2Server));
    assertGetTracesReturnsEmpty(requestBuilder().serviceName(frontend.serviceName()).parseAnnotationQuery("local=app").build());
}
Also used : Endpoint(zipkin2.Endpoint) TestObjects.newClientSpan(zipkin2.TestObjects.newClientSpan) Span(zipkin2.Span) Test(org.junit.jupiter.api.Test)

Example 42 with Kind

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

the class ITSpanStore method getTraces_differentiatesDebugFromShared.

/**
 * Prevents subtle bugs which can result in mixed-length traces from linking.
 */
@Test
protected void getTraces_differentiatesDebugFromShared(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    Span clientSpan = newClientSpan(testSuffix).toBuilder().debug(true).build();
    Span serverSpan = clientSpan.toBuilder().kind(SERVER).debug(null).shared(true).build();
    accept(clientSpan, serverSpan);
    // assertGetTracesReturns does recursive comparison
    assertGetTracesReturns(requestBuilder().build(), asList(clientSpan, serverSpan));
}
Also used : TestObjects.newClientSpan(zipkin2.TestObjects.newClientSpan) Span(zipkin2.Span) Test(org.junit.jupiter.api.Test)

Example 43 with Kind

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

the class ITDependencies method getDependenciesAllInstrumented.

/**
 * When all servers are instrumented, they all record {@link Kind#SERVER} and the {@link
 * Span#localEndpoint()} indicates the service.
 */
@Test
protected void getDependenciesAllInstrumented(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    String traceId = newTraceId();
    String frontend = appendSuffix(TestObjects.FRONTEND.serviceName(), testSuffix);
    String backend = appendSuffix(TestObjects.BACKEND.serviceName(), testSuffix);
    String db = appendSuffix(TestObjects.DB.serviceName(), testSuffix);
    Endpoint one = Endpoint.newBuilder().serviceName(frontend).ip("127.0.0.1").build();
    Endpoint onePort3001 = one.toBuilder().port(3001).build();
    Endpoint two = Endpoint.newBuilder().serviceName(backend).ip("127.0.0.2").build();
    Endpoint twoPort3002 = two.toBuilder().port(3002).build();
    Endpoint three = Endpoint.newBuilder().serviceName(db).ip("127.0.0.3").build();
    List<Span> trace = asList(Span.newBuilder().traceId(traceId).id("10").name("get").kind(Kind.SERVER).timestamp(TODAY * 1000L).duration(350 * 1000L).localEndpoint(one).build(), Span.newBuilder().traceId(traceId).parentId("10").id("20").name("get").kind(Kind.CLIENT).timestamp((TODAY + 50) * 1000L).duration(250 * 1000L).localEndpoint(onePort3001).build(), Span.newBuilder().traceId(traceId).parentId("10").id("20").name("get").shared(true).kind(Kind.SERVER).timestamp((TODAY + 100) * 1000L).duration(150 * 1000L).localEndpoint(two).build(), Span.newBuilder().traceId(traceId).parentId("20").id("30").name("query").kind(Kind.CLIENT).timestamp((TODAY + 150) * 1000L).duration(50 * 1000L).localEndpoint(twoPort3002).build(), Span.newBuilder().traceId(traceId).parentId("20").id("30").name("query").shared(true).kind(Kind.SERVER).timestamp((TODAY + 160) * 1000L).duration(20 * 1000L).localEndpoint(three).build());
    processDependencies(trace);
    assertThat(store().getDependencies(endTs(trace), DAY).execute()).containsOnly(DependencyLink.newBuilder().parent(frontend).child(backend).callCount(1).build(), DependencyLink.newBuilder().parent(backend).child(db).callCount(1).build());
}
Also used : Endpoint(zipkin2.Endpoint) Span(zipkin2.Span) V1Span(zipkin2.v1.V1Span) Test(org.junit.jupiter.api.Test)

Example 44 with Kind

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

the class ITDependenciesHeavy method manyLinks.

/**
 * Ensure there's no query limit problem around links
 */
@Test
protected void manyLinks() throws Exception {
    // Larger than 10, which is the default ES search limit that tripped this
    int count = 1000;
    List<Span> spans = new ArrayList<>(count);
    for (int i = 1; i <= count; i++) {
        String traceId = newTraceId();
        Endpoint web = FRONTEND.toBuilder().serviceName("web-" + i).build();
        Endpoint app = BACKEND.toBuilder().serviceName("app-" + i).build();
        Endpoint db = DB.toBuilder().serviceName("db-" + i).build();
        spans.add(Span.newBuilder().traceId(traceId).id("10").name("get").timestamp((TODAY + 50L) * 1000L).duration(250L * 1000L).kind(Kind.CLIENT).localEndpoint(web).build());
        spans.add(Span.newBuilder().traceId(traceId).id("10").name("get").shared(true).timestamp((TODAY + 100) * 1000L).duration(150 * 1000L).kind(Kind.SERVER).localEndpoint(app).build());
        spans.add(Span.newBuilder().traceId(traceId).parentId("10").id("11").name("get").timestamp((TODAY + 150L) * 1000L).duration(50L * 1000L).kind(Kind.CLIENT).localEndpoint(app).remoteEndpoint(db).build());
    }
    processDependencies(spans);
    List<DependencyLink> links = store().getDependencies(endTs(spans), DAY).execute();
    // web-? -> app-?, app-? -> db-?
    assertThat(links).hasSize(count * 2);
    assertThat(links).extracting(DependencyLink::callCount).allSatisfy(callCount -> assertThat(callCount).isEqualTo(1));
}
Also used : Endpoint(zipkin2.Endpoint) ArrayList(java.util.ArrayList) DependencyLink(zipkin2.DependencyLink) Span(zipkin2.Span) Endpoint(zipkin2.Endpoint) Test(org.junit.jupiter.api.Test)

Example 45 with Kind

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

the class V2SpanWriter method sizeInBytes.

@Override
public int sizeInBytes(Span value) {
    // {"traceId":""
    int sizeInBytes = 13;
    sizeInBytes += value.traceId().length();
    if (value.parentId() != null) {
        // ,"parentId":"0123456789abcdef"
        sizeInBytes += 30;
    }
    // ,"id":"0123456789abcdef"
    sizeInBytes += 24;
    if (value.kind() != null) {
        // ,"kind":""
        sizeInBytes += 10;
        sizeInBytes += value.kind().name().length();
    }
    if (value.name() != null) {
        // ,"name":""
        sizeInBytes += 10;
        sizeInBytes += jsonEscapedSizeInBytes(value.name());
    }
    if (value.timestampAsLong() != 0L) {
        // ,"timestamp":
        sizeInBytes += 13;
        sizeInBytes += asciiSizeInBytes(value.timestampAsLong());
    }
    if (value.durationAsLong() != 0L) {
        // ,"duration":
        sizeInBytes += 12;
        sizeInBytes += asciiSizeInBytes(value.durationAsLong());
    }
    if (value.localEndpoint() != null) {
        // ,"localEndpoint":
        sizeInBytes += 17;
        sizeInBytes += endpointSizeInBytes(value.localEndpoint(), false);
    }
    if (value.remoteEndpoint() != null) {
        // ,"remoteEndpoint":
        sizeInBytes += 18;
        sizeInBytes += endpointSizeInBytes(value.remoteEndpoint(), false);
    }
    if (!value.annotations().isEmpty()) {
        // ,"annotations":[]
        sizeInBytes += 17;
        int length = value.annotations().size();
        // comma to join elements
        if (length > 1)
            sizeInBytes += length - 1;
        for (int i = 0; i < length; i++) {
            Annotation a = value.annotations().get(i);
            sizeInBytes += annotationSizeInBytes(a.timestamp(), a.value(), 0);
        }
    }
    if (!value.tags().isEmpty()) {
        // ,"tags":{}
        sizeInBytes += 10;
        int tagCount = value.tags().size();
        // comma to join elements
        if (tagCount > 1)
            sizeInBytes += tagCount - 1;
        for (Map.Entry<String, String> entry : value.tags().entrySet()) {
            // "":""
            sizeInBytes += 5;
            sizeInBytes += jsonEscapedSizeInBytes(entry.getKey());
            sizeInBytes += jsonEscapedSizeInBytes(entry.getValue());
        }
    }
    if (Boolean.TRUE.equals(value.debug())) {
        // ,"debug":true
        sizeInBytes += 13;
    }
    if (Boolean.TRUE.equals(value.shared())) {
        // ,"shared":true
        sizeInBytes += 14;
    }
    // }
    return ++sizeInBytes;
}
Also used : Map(java.util.Map) Endpoint(zipkin2.Endpoint) Annotation(zipkin2.Annotation)

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