Search in sources :

Example 11 with Endpoint

use of zipkin.Endpoint in project zipkin by openzipkin.

the class ScribeSpanConsumerTest method decodesSpanGeneratedByFinagle.

/** Finagle's zipkin tracer breaks on a column width with a trailing newline */
@Test
public void decodesSpanGeneratedByFinagle() throws Exception {
    Scribe.LogEntry entry = new Scribe.LogEntry();
    entry.category = "zipkin";
    entry.message = "CgABq/sBMnzE048LAAMAAAAOZ2V0VHJhY2VzQnlJZHMKAATN0p+4EGfTdAoABav7ATJ8xNOPDwAGDAAAAAQKAAEABR/wq+2DeAsAAgAAAAJzcgwAAwgAAX8AAAEGAAIkwwsAAwAAAAx6aXBraW4tcXVlcnkAAAoAAQAFH/Cr7zj4CwACAAAIAGFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh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hYWFhYWFhYWFhYWFhYWFhYWFhDAADCAABfwAAAQYAAiTDCwADAAAADHppcGtpbi1xdWVyeQAACgABAAUf8KwLPyILAAIAAABOR2MoOSwwLlBTU2NhdmVuZ2UsMjAxNS0wOS0xNyAxMjozNzowMiArMDAwMCwzMDQubWlsbGlzZWNvbmRzKzc2Mi5taWNyb3NlY29uZHMpDAADCAABfwAAAQYAAiTDCwADAAAADHppcGtpbi1xdWVyeQAIAAQABKZ6AAoAAQAFH/CsDLfACwACAAAAAnNzDAADCAABfwAAAQYAAiTDCwADAAAADHppcGtpbi1xdWVyeQAADwAIDAAAAAULAAEAAAATc3J2L2ZpbmFnbGUudmVyc2lvbgsAAgAAAAY2LjI4LjAIAAMAAAAGDAAECAABfwAAAQYAAgAACwADAAAADHppcGtpbi1xdWVyeQAACwABAAAAD3Nydi9tdXgvZW5hYmxlZAsAAgAAAAEBCAADAAAAAAwABAgAAX8AAAEGAAIAAAsAAwAAAAx6aXBraW4tcXVlcnkAAAsAAQAAAAJzYQsAAgAAAAEBCAADAAAAAAwABAgAAX8AAAEGAAIkwwsAAwAAAAx6aXBraW4tcXVlcnkAAAsAAQAAAAJjYQsAAgAAAAEBCAADAAAAAAwABAgAAX8AAAEGAAL5YAsAAwAAAAx6aXBraW4tcXVlcnkAAAsAAQAAAAZudW1JZHMLAAIAAAAEAAAAAQgAAwAAAAMMAAQIAAF/AAABBgACJMMLAAMAAAAMemlwa2luLXF1ZXJ5AAACAAkAAA==\n";
    newScribeSpanConsumer(entry.category, consumer).log(asList(entry)).get();
    char[] as = new char[2048];
    Arrays.fill(as, 'a');
    String reallyLongAnnotation = new String(as);
    Endpoint zipkinQuery = Endpoint.builder().serviceName("zipkin-query").ipv4(127 << 24 | 1).port(9411).build();
    Endpoint zipkinQuery0 = zipkinQuery.toBuilder().port(null).build();
    assertThat(consumed).containsExactly(Span.builder().traceId(-6054243957716233329L).name("getTracesByIds").id(-3615651937927048332L).parentId(-6054243957716233329L).addAnnotation(Annotation.create(1442493420635000L, Constants.SERVER_RECV, zipkinQuery)).addAnnotation(Annotation.create(1442493420747000L, reallyLongAnnotation, zipkinQuery)).addAnnotation(Annotation.create(1442493422583586L, "Gc(9,0.PSScavenge,2015-09-17 12:37:02 +0000,304.milliseconds+762.microseconds)", zipkinQuery)).addAnnotation(Annotation.create(1442493422680000L, Constants.SERVER_SEND, zipkinQuery)).addBinaryAnnotation(BinaryAnnotation.create("srv/finagle.version", "6.28.0", zipkinQuery0)).addBinaryAnnotation(binaryAnnotation("srv/mux/enabled", true, zipkinQuery0)).addBinaryAnnotation(BinaryAnnotation.address(Constants.SERVER_ADDR, zipkinQuery)).addBinaryAnnotation(BinaryAnnotation.address(Constants.CLIENT_ADDR, zipkinQuery.toBuilder().port(63840).build())).addBinaryAnnotation(binaryAnnotation("numIds", 1, zipkinQuery)).debug(false).build());
}
Also used : Endpoint(zipkin.Endpoint) Test(org.junit.Test)

Example 12 with Endpoint

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

use of zipkin.Endpoint in project zipkin by openzipkin.

the class CorrectForClockSkew method getClockSkew.

/** Use client/server annotations to determine if there's clock skew. */
@Nullable
static ClockSkew getClockSkew(Span span) {
    Map<String, Annotation> annotations = asMap(span.annotations);
    Annotation clientSend = annotations.get(Constants.CLIENT_SEND);
    Annotation clientRecv = annotations.get(Constants.CLIENT_RECV);
    Annotation serverRecv = annotations.get(Constants.SERVER_RECV);
    Annotation serverSend = annotations.get(Constants.SERVER_SEND);
    if (clientSend == null || clientRecv == null || serverRecv == null || serverSend == null) {
        return null;
    }
    Endpoint server = serverRecv.endpoint != null ? serverRecv.endpoint : serverSend.endpoint;
    if (server == null)
        return null;
    Endpoint client = clientSend.endpoint != null ? clientSend.endpoint : clientRecv.endpoint;
    if (client == null)
        return null;
    // There's no skew if the RPC is going to itself
    if (ipsMatch(server, client))
        return null;
    long clientDuration = clientRecv.timestamp - clientSend.timestamp;
    long serverDuration = serverSend.timestamp - serverRecv.timestamp;
    // This breaks if client duration is smaller than server (due to async return for example).
    if (clientDuration < serverDuration)
        return null;
    long latency = (clientDuration - serverDuration) / 2;
    // We can't see skew when send happens before receive
    if (latency < 0)
        return null;
    long skew = serverRecv.timestamp - latency - clientSend.timestamp;
    if (skew != 0L) {
        return new ClockSkew(server, skew);
    }
    return null;
}
Also used : Endpoint(zipkin.Endpoint) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation)

Example 14 with Endpoint

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

Example 15 with Endpoint

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

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