Search in sources :

Example 76 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class InternalElasticsearchClientTest method toSpanBytes.

@Test
public void toSpanBytes() {
    Span span = Span.builder().traceId(20L).traceIdHigh(30).id(20L).name("get").timestamp(TODAY * 1000).build();
    byte[] result = InternalElasticsearchClient.toSpanBytes(span, TODAY);
    assertThat(Codec.JSON.readSpan(result)).isEqualTo(span);
}
Also used : Span(zipkin.Span) Test(org.junit.Test)

Example 77 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class HttpBulkSpanIndexerTest method prefixWithTimestampMillis.

@Test
public void prefixWithTimestampMillis() {
    Span span = Span.builder().traceId(20L).id(20L).name("get").timestamp(TODAY * 1000).build();
    byte[] result = HttpBulkSpanIndexer.prefixWithTimestampMillis(Codec.JSON.writeSpan(span), TODAY);
    String json = new String(result);
    assertThat(json).startsWith("{\"timestamp_millis\":" + Long.toString(TODAY) + ",\"traceId\":");
    assertThat(Codec.JSON.readSpan(json.getBytes())).isEqualTo(// ignores timestamp_millis field
    span);
}
Also used : Span(zipkin.Span) Test(org.junit.Test)

Example 78 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class CorrectForClockSkew method adjustTimestamps.

/** If any annotation has an IP with skew associated, adjust accordingly. */
static Span adjustTimestamps(Span span, ClockSkew skew) {
    List<Annotation> annotations = null;
    Long annotationTimestamp = null;
    for (int i = 0, length = span.annotations.size(); i < length; i++) {
        Annotation a = span.annotations.get(i);
        if (a.endpoint == null)
            continue;
        if (ipsMatch(skew.endpoint, a.endpoint)) {
            if (annotations == null)
                annotations = new ArrayList<>(span.annotations);
            if (span.timestamp != null && a.timestamp == span.timestamp) {
                annotationTimestamp = a.timestamp;
            }
            annotations.set(i, a.toBuilder().timestamp(a.timestamp - skew.skew).build());
        }
    }
    if (annotations != null) {
        Span.Builder builder = span.toBuilder().annotations(annotations);
        if (annotationTimestamp != null) {
            builder.timestamp(annotationTimestamp - skew.skew);
        }
        return builder.build();
    }
    // Search for a local span on the skewed endpoint
    for (int i = 0, length = span.binaryAnnotations.size(); i < length; i++) {
        BinaryAnnotation b = span.binaryAnnotations.get(i);
        if (b.endpoint == null)
            continue;
        if (b.key.equals(Constants.LOCAL_COMPONENT) && ipsMatch(skew.endpoint, b.endpoint)) {
            return span.toBuilder().timestamp(span.timestamp - skew.skew).build();
        }
    }
    return span;
}
Also used : BinaryAnnotation(zipkin.BinaryAnnotation) ArrayList(java.util.ArrayList) Span(zipkin.Span) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation) Endpoint(zipkin.Endpoint)

Example 79 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class CorrectForClockSkew method apply.

public static List<Span> apply(List<Span> spans) {
    for (Span s : spans) {
        if (s.parentId == null) {
            Node<Span> tree = Node.constructTree(spans);
            adjust(tree, null);
            List<Span> result = new ArrayList<>(spans.size());
            for (Iterator<Node<Span>> i = tree.traverse(); i.hasNext(); ) {
                result.add(i.next().value());
            }
            return result;
        }
    }
    return spans;
}
Also used : ArrayList(java.util.ArrayList) Span(zipkin.Span)

Example 80 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class DependenciesTest method manyLinks.

/** Ensure there's no query limit problem around links */
@Test
public void manyLinks() {
    // 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++) {
        Endpoint web = WEB_ENDPOINT.toBuilder().serviceName("web-" + i).build();
        Endpoint app = APP_ENDPOINT.toBuilder().serviceName("app-" + i).build();
        Endpoint db = DB_ENDPOINT.toBuilder().serviceName("db-" + i).build();
        spans.add(Span.builder().traceId(i).id(10L).name("get").timestamp((TODAY + 50L) * 1000).duration(250L * 1000).addAnnotation(Annotation.create((TODAY + 50) * 1000, CLIENT_SEND, web)).addAnnotation(Annotation.create((TODAY + 100) * 1000, SERVER_RECV, app)).addAnnotation(Annotation.create((TODAY + 250) * 1000, SERVER_SEND, app)).addAnnotation(Annotation.create((TODAY + 300) * 1000, CLIENT_RECV, web)).build());
        spans.add(Span.builder().traceId(i).parentId(10L).id(11L).name("get").timestamp((TODAY + 150L) * 1000).duration(50L * 1000).addAnnotation(Annotation.create((TODAY + 150) * 1000, CLIENT_SEND, app)).addAnnotation(Annotation.create((TODAY + 200) * 1000, CLIENT_RECV, app)).addBinaryAnnotation(BinaryAnnotation.address(SERVER_ADDR, db)).build());
    }
    processDependencies(spans);
    List<DependencyLink> links = store().getDependencies(TODAY + 1000L, null);
    // web-? -> app-?, app-? -> db-?
    assertThat(links).hasSize(count * 2);
    assertThat(links).extracting(l -> l.callCount).allSatisfy(callCount -> assertThat(callCount).isEqualTo(1));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Annotation(zipkin.Annotation) CLIENT_ADDR(zipkin.Constants.CLIENT_ADDR) CLIENT_SEND(zipkin.Constants.CLIENT_SEND) LINKS(zipkin.TestObjects.LINKS) DEPENDENCIES(zipkin.TestObjects.DEPENDENCIES) ArrayList(java.util.ArrayList) Endpoint(zipkin.Endpoint) DAY(zipkin.TestObjects.DAY) Span(zipkin.Span) Arrays.asList(java.util.Arrays.asList) SERVER_SEND(zipkin.Constants.SERVER_SEND) WEB_ENDPOINT(zipkin.TestObjects.WEB_ENDPOINT) ApplyTimestampAndDuration(zipkin.internal.ApplyTimestampAndDuration) Before(org.junit.Before) TRACE(zipkin.TestObjects.TRACE) IOException(java.io.IOException) Test(org.junit.Test) BinaryAnnotation(zipkin.BinaryAnnotation) CLIENT_RECV(zipkin.Constants.CLIENT_RECV) DependencyLink(zipkin.DependencyLink) TODAY(zipkin.TestObjects.TODAY) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) LOCAL_COMPONENT(zipkin.Constants.LOCAL_COMPONENT) APP_ENDPOINT(zipkin.TestObjects.APP_ENDPOINT) Constants(zipkin.Constants) SERVER_ADDR(zipkin.Constants.SERVER_ADDR) CallbackCaptor(zipkin.internal.CallbackCaptor) SERVER_RECV(zipkin.Constants.SERVER_RECV) DB_ENDPOINT(zipkin.TestObjects.DB_ENDPOINT) Endpoint(zipkin.Endpoint) ArrayList(java.util.ArrayList) DependencyLink(zipkin.DependencyLink) Span(zipkin.Span) Endpoint(zipkin.Endpoint) 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