Search in sources :

Example 6 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class CassandraSpanConsumerTest method dontLogTimestampMissingOnMidTierServerSpan.

@Test
public void dontLogTimestampMissingOnMidTierServerSpan() {
    Span span = TestObjects.TRACE.get(0);
    accept(span);
    verify(mockAppender, never()).doAppend(considerSwitchStrategyLog());
}
Also used : Span(zipkin.Span) Test(org.junit.Test)

Example 7 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class CassandraSpanConsumerTest method doesntIndexCoreOrNonStringAnnotations.

/**
   * Core/Boundary annotations like "sr" aren't queryable, and don't add value to users. Address
   * annotations, like "sa", don't have string values, so are similarly not queryable. Skipping
   * indexing of such annotations dramatically reduces the load on cassandra and size of indexes.
   */
@Test
public void doesntIndexCoreOrNonStringAnnotations() {
    Span span = TestObjects.TRACE.get(1);
    assertThat(span.annotations).extracting(a -> a.value).matches(Constants.CORE_ANNOTATIONS::containsAll);
    assertThat(span.binaryAnnotations).extracting(b -> b.key).containsOnly(Constants.SERVER_ADDR, Constants.CLIENT_ADDR);
    accept(span);
    assertThat(rowCount(Tables.ANNOTATIONS_INDEX)).isZero();
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) Annotation(zipkin.Annotation) CLIENT_SEND(zipkin.Constants.CLIENT_SEND) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) ArgumentMatcher(org.mockito.ArgumentMatcher) ImmutableList(com.google.common.collect.ImmutableList) Span(zipkin.Span) Appender(ch.qos.logback.core.Appender) After(org.junit.After) TestObjects(zipkin.TestObjects) Before(org.junit.Before) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) CLIENT_RECV(zipkin.Constants.CLIENT_RECV) Mockito.verify(org.mockito.Mockito.verify) Futures(com.google.common.util.concurrent.Futures) Collectors.toList(java.util.stream.Collectors.toList) Mockito.never(org.mockito.Mockito.never) APP_ENDPOINT(zipkin.TestObjects.APP_ENDPOINT) Logger(ch.qos.logback.classic.Logger) Matchers.argThat(org.mockito.Matchers.argThat) Constants(zipkin.Constants) Mockito.mock(org.mockito.Mockito.mock) Span(zipkin.Span) Test(org.junit.Test)

Example 8 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class ZipkinRuleTest method readSpans_gzippedResponse.

@Test
public void readSpans_gzippedResponse() throws Exception {
    char[] annotation2K = new char[2048];
    Arrays.fill(annotation2K, 'a');
    List<Span> trace = asList(TRACE.get(0).toBuilder().addAnnotation(Annotation.create(System.currentTimeMillis(), new String(annotation2K), null)).build());
    zipkin.storeSpans(trace);
    Response response = client.newCall(new Request.Builder().url(format("%s/api/v1/trace/%016x", zipkin.httpUrl(), traceId)).addHeader("Accept-Encoding", "gzip").build()).execute();
    assertThat(response.code()).isEqualTo(200);
    assertThat(response.body().contentLength()).isLessThan(annotation2K.length);
    Buffer result = new Buffer();
    GzipSource source = new GzipSource(response.body().source());
    while (source.read(result, Integer.MAX_VALUE) != -1) ;
    byte[] unzipped = result.readByteArray();
    assertThat(Codec.JSON.readSpans(unzipped)).isEqualTo(trace);
}
Also used : Response(okhttp3.Response) Buffer(okio.Buffer) GzipSource(okio.GzipSource) Request(okhttp3.Request) ByteString(okio.ByteString) Span(zipkin.Span) Test(org.junit.Test)

Example 9 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class CassandraSpanStoreTest method overFetchesToCompensateForDuplicateIndexData.

@Test
public void overFetchesToCompensateForDuplicateIndexData() {
    int traceCount = 100;
    List<Span> spans = new ArrayList<>();
    for (int i = 0; i < traceCount; i++) {
        // all timestamps happen a millisecond later
        final long delta = i * 1000;
        for (Span s : TestObjects.TRACE) {
            spans.add(TestObjects.TRACE.get(0).toBuilder().traceId(s.traceId + i * 10).id(s.id + i * 10).timestamp(s.timestamp + delta).annotations(s.annotations.stream().map(a -> Annotation.create(a.timestamp + delta, a.value, a.endpoint)).collect(toList())).build());
        }
    }
    accept(spans.toArray(new Span[0]));
    // Index ends up containing more rows than services * trace count, and cannot be de-duped
    // in a server-side query.
    assertThat(rowCount(Tables.SERVICE_NAME_INDEX)).isGreaterThan(traceCount * store().getServiceNames().size());
    // Implementation over-fetches on the index to allow the user to receive unsurprising results.
    assertThat(store().getTraces(QueryRequest.builder().limit(traceCount).build())).hasSize(traceCount);
}
Also used : ArrayList(java.util.ArrayList) Span(zipkin.Span) Endpoint(zipkin.Endpoint) Test(org.junit.Test) SpanStoreTest(zipkin.storage.SpanStoreTest)

Example 10 with Span

use of zipkin.Span in project zipkin by openzipkin.

the class CassandraSpanStoreTest method rawTraceStoredWithoutAdjustments.

/** Cassandra indexing is performed separately, allowing the raw span to be stored unaltered. */
@Test
public void rawTraceStoredWithoutAdjustments() {
    Span rawSpan = TestObjects.TRACE.get(0).toBuilder().timestamp(null).duration(null).build();
    accept(rawSpan);
    // At query time, timestamp and duration are added.
    assertThat(store().getTrace(rawSpan.traceIdHigh, rawSpan.traceId)).containsExactly(ApplyTimestampAndDuration.apply(rawSpan));
    // Unlike other stores, Cassandra can show that timestamp and duration weren't reported
    assertThat(store().getRawTrace(rawSpan.traceIdHigh, rawSpan.traceId)).containsExactly(rawSpan);
}
Also used : Span(zipkin.Span) Test(org.junit.Test) SpanStoreTest(zipkin.storage.SpanStoreTest)

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