Search in sources :

Example 1 with BinaryAnnotation

use of zipkin.BinaryAnnotation in project zipkin by openzipkin.

the class CassandraUtil method annotationKeys.

/**
   * Returns keys that concatenate the serviceName associated with an annotation or a binary
   * annotation.
   *
   * <p>Note: in the case of binary annotations, only string types are returned, as that's the only
   * queryable type, per {@link QueryRequest#binaryAnnotations}.
   *
   * @see QueryRequest#annotations
   * @see QueryRequest#binaryAnnotations
   */
static Set<String> annotationKeys(Span span) {
    Set<String> annotationKeys = new LinkedHashSet<>();
    for (Annotation a : span.annotations) {
        // don't index core annotations as they aren't queryable
        if (Constants.CORE_ANNOTATIONS.contains(a.value))
            continue;
        if (a.endpoint != null && !a.endpoint.serviceName.isEmpty()) {
            annotationKeys.add(a.endpoint.serviceName + ":" + a.value);
        }
    }
    for (BinaryAnnotation b : span.binaryAnnotations) {
        if (b.type == BinaryAnnotation.Type.STRING && b.endpoint != null && !b.endpoint.serviceName.isEmpty() && b.value.length <= LONGEST_VALUE_TO_INDEX * 4) {
            // UTF_8 is up to 4bytes/char
            String value = new String(b.value, UTF_8);
            if (value.length() > LONGEST_VALUE_TO_INDEX)
                continue;
            annotationKeys.add(b.endpoint.serviceName + ":" + b.key + ":" + new String(b.value, UTF_8));
        }
    }
    return annotationKeys;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BinaryAnnotation(zipkin.BinaryAnnotation) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation)

Example 2 with BinaryAnnotation

use of zipkin.BinaryAnnotation in project zipkin by openzipkin.

the class CassandraSpanStoreTest method searchingByAnnotationShouldFilterBeforeLimiting.

@Test
public void searchingByAnnotationShouldFilterBeforeLimiting() {
    long now = System.currentTimeMillis();
    int queryLimit = 2;
    Endpoint endpoint = TestObjects.LOTS_OF_SPANS[0].annotations.get(0).endpoint;
    BinaryAnnotation ba = BinaryAnnotation.create("host.name", "host1", endpoint);
    int nbTraceFetched = queryLimit * storage.indexFetchMultiplier;
    IntStream.range(0, nbTraceFetched).forEach(i -> accept(TestObjects.LOTS_OF_SPANS[i++].toBuilder().timestamp(now - (i * 1000)).build()));
    // Add two traces with the binary annotation we're looking for
    IntStream.range(nbTraceFetched, nbTraceFetched + 2).forEach(i -> accept(TestObjects.LOTS_OF_SPANS[i++].toBuilder().timestamp(now - (i * 1000)).addBinaryAnnotation(ba).build()));
    QueryRequest queryRequest = QueryRequest.builder().addBinaryAnnotation(ba.key, new String(ba.value, Util.UTF_8)).serviceName(endpoint.serviceName).limit(queryLimit).build();
    assertThat(store().getTraces(queryRequest)).hasSize(queryLimit);
}
Also used : BinaryAnnotation(zipkin.BinaryAnnotation) Endpoint(zipkin.Endpoint) QueryRequest(zipkin.storage.QueryRequest) Endpoint(zipkin.Endpoint) Test(org.junit.Test) SpanStoreTest(zipkin.storage.SpanStoreTest)

Example 3 with BinaryAnnotation

use of zipkin.BinaryAnnotation in project zipkin by openzipkin.

the class CassandraSpanStoreTest method searchingByAnnotationShouldFilterBeforeLimiting.

@Test
public void searchingByAnnotationShouldFilterBeforeLimiting() {
    long now = System.currentTimeMillis();
    int queryLimit = 2;
    Endpoint endpoint = TestObjects.LOTS_OF_SPANS[0].annotations.get(0).endpoint;
    BinaryAnnotation ba = BinaryAnnotation.create("host.name", "host1", endpoint);
    int nbTraceFetched = queryLimit * storage.indexFetchMultiplier;
    IntStream.range(0, nbTraceFetched).forEach(i -> accept(TestObjects.LOTS_OF_SPANS[i++].toBuilder().timestamp(now - (i * 1000)).build()));
    // Add two traces with the binary annotation we're looking for
    IntStream.range(nbTraceFetched, nbTraceFetched + 2).forEach(i -> accept(TestObjects.LOTS_OF_SPANS[i++].toBuilder().timestamp(now - (i * 1000)).addBinaryAnnotation(ba).build()));
    QueryRequest queryRequest = QueryRequest.builder().addBinaryAnnotation(ba.key, new String(ba.value, Util.UTF_8)).serviceName(endpoint.serviceName).limit(queryLimit).build();
    assertThat(store().getTraces(queryRequest)).hasSize(queryLimit);
}
Also used : BinaryAnnotation(zipkin.BinaryAnnotation) Endpoint(zipkin.Endpoint) QueryRequest(zipkin.storage.QueryRequest) Endpoint(zipkin.Endpoint) Test(org.junit.Test) SpanStoreTest(zipkin.storage.SpanStoreTest)

Example 4 with BinaryAnnotation

use of zipkin.BinaryAnnotation in project zipkin by openzipkin.

the class SpanStoreTest method getTraces_duration.

/** Shows that duration queries go against the root span, not the child */
@Test
public void getTraces_duration() {
    Endpoint service1 = Endpoint.create("service1", 127 << 24 | 1);
    Endpoint service2 = Endpoint.create("service2", 127 << 24 | 2);
    Endpoint service3 = Endpoint.create("service3", 127 << 24 | 3);
    BinaryAnnotation.Builder component = BinaryAnnotation.builder().key(LOCAL_COMPONENT).value("archiver");
    BinaryAnnotation archiver1 = component.endpoint(service1).build();
    BinaryAnnotation archiver2 = component.endpoint(service2).build();
    BinaryAnnotation archiver3 = component.endpoint(service3).build();
    Span targz = Span.builder().traceId(1L).id(1L).name("targz").timestamp(today * 1000 + 100L).duration(200L).addBinaryAnnotation(archiver1).build();
    Span tar = Span.builder().traceId(1L).id(2L).parentId(1L).name("tar").timestamp(today * 1000 + 200L).duration(150L).addBinaryAnnotation(archiver2).build();
    Span gz = Span.builder().traceId(1L).id(3L).parentId(1L).name("gz").timestamp(today * 1000 + 250L).duration(50L).addBinaryAnnotation(archiver3).build();
    Span zip = Span.builder().traceId(3L).id(3L).name("zip").timestamp(today * 1000 + 130L).duration(50L).addBinaryAnnotation(archiver2).build();
    List<Span> trace1 = asList(targz, tar, gz);
    List<Span> trace2 = asList(targz.toBuilder().traceId(2L).timestamp(today * 1000 + 110L).binaryAnnotations(asList(archiver3)).build(), tar.toBuilder().traceId(2L).timestamp(today * 1000 + 210L).binaryAnnotations(asList(archiver2)).build(), gz.toBuilder().traceId(2L).timestamp(today * 1000 + 260L).binaryAnnotations(asList(archiver1)).build());
    List<Span> trace3 = asList(zip);
    accept(trace1.toArray(new Span[0]));
    accept(trace2.toArray(new Span[0]));
    accept(trace3.toArray(new Span[0]));
    // 12hrs, instead of 7days
    long lookback = 12L * 60 * 60 * 1000;
    // greater than all timestamps above
    long endTs = today + 1;
    QueryRequest.Builder q = QueryRequest.builder().serviceName("service1").lookback(lookback).endTs(endTs);
    // Min duration is inclusive and is applied by service.
    assertThat(store().getTraces(q.serviceName("service1").minDuration(targz.duration).build())).containsExactly(trace1);
    assertThat(store().getTraces(q.serviceName("service3").minDuration(targz.duration).build())).containsExactly(trace2);
    // Duration bounds aren't limited to root spans: they apply to all spans by service in a trace
    assertThat(store().getTraces(q.serviceName("service2").minDuration(zip.duration).maxDuration(tar.duration).build())).containsExactly(trace3, trace2, // service2 is in the middle of trace1 and 2, but root of trace3
    trace1);
    // Span name should apply to the duration filter
    assertThat(store().getTraces(q.serviceName("service2").spanName("zip").maxDuration(zip.duration).build())).containsExactly(trace3);
    // Max duration should filter our longer spans from the same service
    assertThat(store().getTraces(q.serviceName("service2").minDuration(gz.duration).maxDuration(zip.duration).build())).containsExactly(trace3);
}
Also used : BinaryAnnotation(zipkin.BinaryAnnotation) Endpoint(zipkin.Endpoint) Span(zipkin.Span) Test(org.junit.Test)

Example 5 with BinaryAnnotation

use of zipkin.BinaryAnnotation in project zipkin by openzipkin.

the class SpanStoreTest method getAllServiceNames__allReturned.

@Test
public void getAllServiceNames__allReturned() {
    // Assure a default spanstore limit isn't hit by assuming if 50 are returned, all are returned
    List<String> serviceNames = new ArrayList<>();
    serviceNames.add("service");
    for (int i = 0; i < 50; i++) {
        String suffix = i < 10 ? "0" + i : String.valueOf(i);
        BinaryAnnotation yak = BinaryAnnotation.address("sa", Endpoint.create("yak" + suffix, 127 << 24 | 1));
        accept(span1.toBuilder().id(i).addBinaryAnnotation(yak).build());
        serviceNames.add("yak" + suffix);
    }
    assertThat(store().getServiceNames()).containsOnlyElementsOf(serviceNames);
}
Also used : BinaryAnnotation(zipkin.BinaryAnnotation) ArrayList(java.util.ArrayList) Endpoint(zipkin.Endpoint) 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