Search in sources :

Example 11 with BinaryAnnotation

use of zipkin.BinaryAnnotation in project zipkin by openzipkin.

the class QueryRequest method test.

/** Tests the supplied trace against the current request */
public boolean test(List<Span> spans) {
    Long timestamp = ApplyTimestampAndDuration.guessTimestamp(spans.get(0));
    if (timestamp == null || timestamp < (endTs - lookback) * 1000 || timestamp > endTs * 1000) {
        return false;
    }
    Set<String> serviceNames = new LinkedHashSet<>();
    boolean testedDuration = minDuration == null && maxDuration == null;
    String spanNameToMatch = spanName;
    Set<String> annotationsToMatch = new LinkedHashSet<>(annotations);
    Map<String, String> binaryAnnotationsToMatch = new LinkedHashMap<>(binaryAnnotations);
    Set<String> currentServiceNames = new LinkedHashSet<>();
    for (Span span : spans) {
        currentServiceNames.clear();
        for (Annotation a : span.annotations) {
            if (appliesToServiceName(a.endpoint, serviceName)) {
                annotationsToMatch.remove(a.value);
            }
            if (a.endpoint != null) {
                serviceNames.add(a.endpoint.serviceName);
                currentServiceNames.add(a.endpoint.serviceName);
            }
        }
        for (BinaryAnnotation b : span.binaryAnnotations) {
            if (appliesToServiceName(b.endpoint, serviceName) && b.type == BinaryAnnotation.Type.STRING && new String(b.value, UTF_8).equals(binaryAnnotationsToMatch.get(b.key))) {
                binaryAnnotationsToMatch.remove(b.key);
            }
            if (b.endpoint != null) {
                serviceNames.add(b.endpoint.serviceName);
                currentServiceNames.add(b.endpoint.serviceName);
            }
        }
        if ((serviceName == null || currentServiceNames.contains(serviceName)) && !testedDuration) {
            if (minDuration != null && maxDuration != null) {
                testedDuration = span.duration >= minDuration && span.duration <= maxDuration;
            } else if (minDuration != null) {
                testedDuration = span.duration >= minDuration;
            }
        }
        if (span.name.equals(spanNameToMatch)) {
            spanNameToMatch = null;
        }
    }
    return (serviceName == null || serviceNames.contains(serviceName)) && spanNameToMatch == null && annotationsToMatch.isEmpty() && binaryAnnotationsToMatch.isEmpty() && testedDuration;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BinaryAnnotation(zipkin.BinaryAnnotation) Span(zipkin.Span) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with BinaryAnnotation

use of zipkin.BinaryAnnotation in project zipkin by openzipkin.

the class DependencyLinkSpan method from.

public static DependencyLinkSpan from(Span s) {
    TraceId traceId = new TraceId(s.traceIdHigh, s.traceId);
    DependencyLinkSpan.Builder linkSpan = new DependencyLinkSpan.Builder(traceId, s.parentId, s.id);
    for (BinaryAnnotation a : s.binaryAnnotations) {
        if (a.key.equals(Constants.CLIENT_ADDR) && a.endpoint != null) {
            linkSpan.caService(a.endpoint.serviceName);
        } else if (a.key.equals(Constants.SERVER_ADDR) && a.endpoint != null) {
            linkSpan.saService(a.endpoint.serviceName);
        }
    }
    for (Annotation a : s.annotations) {
        if (a.value.equals(Constants.SERVER_RECV) && a.endpoint != null) {
            linkSpan.srService(a.endpoint.serviceName);
        } else if (a.value.equals(Constants.CLIENT_SEND) && a.endpoint != null) {
            linkSpan.csService(a.endpoint.serviceName);
        }
    }
    return linkSpan.build();
}
Also used : BinaryAnnotation(zipkin.BinaryAnnotation) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation)

Example 13 with BinaryAnnotation

use of zipkin.BinaryAnnotation in project zipkin by openzipkin.

the class SpanStoreTest method getAllServiceNames_mergesAnnotation_andBinaryAnnotation.

@Test
public void getAllServiceNames_mergesAnnotation_andBinaryAnnotation() {
    // creates a span with mutual exclusive endpoints in binary annotations and annotations
    BinaryAnnotation yak = BinaryAnnotation.address("sa", Endpoint.create("yak", 127 << 24 | 1));
    accept(span1.toBuilder().binaryAnnotations(asList(yak)).build());
    // should be in order
    assertThat(store().getServiceNames()).containsExactly("service", "yak");
}
Also used : BinaryAnnotation(zipkin.BinaryAnnotation) Test(org.junit.Test)

Aggregations

BinaryAnnotation (zipkin.BinaryAnnotation)13 Annotation (zipkin.Annotation)7 Test (org.junit.Test)6 Endpoint (zipkin.Endpoint)6 Span (zipkin.Span)5 ArrayList (java.util.ArrayList)4 LinkedHashSet (java.util.LinkedHashSet)3 LinkedHashMap (java.util.LinkedHashMap)2 QueryRequest (zipkin.storage.QueryRequest)2 SpanStoreTest (zipkin.storage.SpanStoreTest)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 UUID (java.util.UUID)1 DSLContext (org.jooq.DSLContext)1 Query (org.jooq.Query)1 Record (org.jooq.Record)1 TableField (org.jooq.TableField)1 AnnotationUDT (zipkin.storage.cassandra3.Schema.AnnotationUDT)1 BinaryAnnotationUDT (zipkin.storage.cassandra3.Schema.BinaryAnnotationUDT)1