Search in sources :

Example 36 with BACKEND

use of zipkin2.TestObjects.BACKEND in project zipkin by openzipkin.

the class SpanConverterTest method consumer_remote.

@Test
public void consumer_remote() {
    Span v2 = Span.newBuilder().traceId("1").parentId("2").id("3").name("next-message").kind(Kind.CONSUMER).localEndpoint(BACKEND).remoteEndpoint(kafka).timestamp(1472470996199000L).build();
    V1Span v1 = V1Span.newBuilder().traceId(1L).parentId(2L).id(3L).name("next-message").timestamp(1472470996199000L).addAnnotation(1472470996199000L, "mr", BACKEND).addBinaryAnnotation("ma", kafka).build();
    assertThat(v2SpanConverter.convert(v2)).usingRecursiveComparison().isEqualTo(v1);
    assertThat(v1SpanConverter.convert(v1)).containsExactly(v2);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 37 with BACKEND

use of zipkin2.TestObjects.BACKEND in project zipkin by openzipkin.

the class ITSpanConsumer method insertEntry_niceToString.

/**
 * It is easier to use a real Cassandra connection than mock a prepared statement.
 */
@Test
public void insertEntry_niceToString() {
    // This test can use fake data as it is never written to cassandra
    Span clientSpan = CLIENT_SPAN;
    AggregateCall<?, ?> acceptCall = (AggregateCall<?, ?>) storage.spanConsumer().accept(asList(clientSpan));
    List<Call<?>> insertEntryCalls = acceptCall.delegate().stream().filter(c -> c instanceof InsertEntry).collect(Collectors.toList());
    assertThat(insertEntryCalls.get(0)).hasToString("INSERT INTO span_by_service (service, span) VALUES (frontend,get)");
    assertThat(insertEntryCalls.get(1)).hasToString("INSERT INTO remote_service_by_service (service, remote_service) VALUES (frontend,backend)");
}
Also used : AggregateCall(zipkin2.internal.AggregateCall) IntStream(java.util.stream.IntStream) TestObjects.spanBuilder(zipkin2.TestObjects.spanBuilder) TestObjects.newClientSpan(zipkin2.TestObjects.newClientSpan) AggregateCall(zipkin2.internal.AggregateCall) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Span(zipkin2.Span) InsertEntry(zipkin2.storage.cassandra.internal.call.InsertEntry) CLIENT_SPAN(zipkin2.TestObjects.CLIENT_SPAN) Collectors(java.util.stream.Collectors) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) List(java.util.List) Arrays.asList(java.util.Arrays.asList) SERVER(zipkin2.Span.Kind.SERVER) StorageComponent(zipkin2.storage.StorageComponent) Call(zipkin2.Call) ITStorage(zipkin2.storage.ITStorage) AggregateCall(zipkin2.internal.AggregateCall) Call(zipkin2.Call) InsertEntry(zipkin2.storage.cassandra.internal.call.InsertEntry) TestObjects.newClientSpan(zipkin2.TestObjects.newClientSpan) Span(zipkin2.Span) Test(org.junit.jupiter.api.Test)

Example 38 with BACKEND

use of zipkin2.TestObjects.BACKEND in project zipkin by openzipkin.

the class CassandraSpanConsumerTest method serviceRemoteServiceKeys_skipsRemoteServiceNameWhenNoLocalService.

@Test
public void serviceRemoteServiceKeys_skipsRemoteServiceNameWhenNoLocalService() {
    Span span = spanWithoutAnnotationsOrTags.toBuilder().localEndpoint(null).remoteEndpoint(BACKEND).build();
    Call<Void> call = consumer.accept(singletonList(span));
    assertThat(call).isInstanceOf(InsertSpan.class);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 39 with BACKEND

use of zipkin2.TestObjects.BACKEND in project zipkin by openzipkin.

the class CassandraSpanConsumerTest method traceByServiceSpan_doesntIndexRemoteService.

@Test
public void traceByServiceSpan_doesntIndexRemoteService() {
    Span span = spanWithoutAnnotationsOrTags.toBuilder().remoteEndpoint(BACKEND).build();
    AggregateCall<?, Void> call = (AggregateCall<?, Void>) consumer.accept(singletonList(span));
    assertThat(call.delegate()).filteredOn(c -> c instanceof InsertTraceByServiceSpan).hasSize(2).extracting("input.service").doesNotContain(BACKEND.serviceName());
}
Also used : AggregateCall(zipkin2.internal.AggregateCall) TODAY(zipkin2.TestObjects.TODAY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) AggregateCall(zipkin2.internal.AggregateCall) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Span(zipkin2.Span) Test(org.junit.Test) InsertEntry(zipkin2.storage.cassandra.internal.call.InsertEntry) Assertions.entry(org.assertj.core.api.Assertions.entry) InternalForTests.mockSession(zipkin2.storage.cassandra.InternalForTests.mockSession) Collections.singletonList(java.util.Collections.singletonList) ResultSetFutureCall(zipkin2.storage.cassandra.internal.call.ResultSetFutureCall) FRONTEND(zipkin2.TestObjects.FRONTEND) BACKEND(zipkin2.TestObjects.BACKEND) Call(zipkin2.Call) Collections(java.util.Collections) Span(zipkin2.Span) Test(org.junit.Test)

Example 40 with BACKEND

use of zipkin2.TestObjects.BACKEND in project zipkin by openzipkin.

the class QueryRequest method test.

/**
 * Tests the supplied trace against the current request.
 *
 * <p>This is used when the backend cannot fully refine a trace query.
 */
public boolean test(List<Span> spans) {
    // v2 returns raw spans in any order, get the root's timestamp or the first timestamp
    long timestamp = 0L;
    for (Span span : spans) {
        if (span.timestampAsLong() == 0L)
            continue;
        if (span.parentId() == null) {
            timestamp = span.timestampAsLong();
            break;
        }
        if (timestamp == 0L || timestamp > span.timestampAsLong()) {
            timestamp = span.timestampAsLong();
        }
    }
    if (timestamp == 0L || timestamp < (endTs() - lookback()) * 1000 || timestamp > endTs() * 1000) {
        return false;
    }
    boolean testedDuration = minDuration() == null && maxDuration() == null;
    String serviceNameToMatch = serviceName();
    String remoteServiceNameToMatch = remoteServiceName();
    String spanNameToMatch = spanName();
    Map<String, String> annotationQueryRemaining = new LinkedHashMap<String, String>(annotationQuery());
    for (Span span : spans) {
        String localServiceName = span.localServiceName();
        // service name, when present, constrains other queries.
        if (serviceName() == null || serviceName().equals(localServiceName)) {
            serviceNameToMatch = null;
            for (Annotation a : span.annotations()) {
                if ("".equals(annotationQueryRemaining.get(a.value()))) {
                    annotationQueryRemaining.remove(a.value());
                }
            }
            for (Map.Entry<String, String> t : span.tags().entrySet()) {
                String value = annotationQueryRemaining.get(t.getKey());
                if (value == null)
                    continue;
                if (value.isEmpty() || value.equals(t.getValue())) {
                    annotationQueryRemaining.remove(t.getKey());
                }
            }
            if (remoteServiceNameToMatch != null && remoteServiceNameToMatch.equals(span.remoteServiceName())) {
                remoteServiceNameToMatch = null;
            }
            if (spanNameToMatch != null && spanNameToMatch.equals(span.name())) {
                spanNameToMatch = null;
            }
            if (!testedDuration) {
                if (minDuration() != null && maxDuration() != null) {
                    testedDuration = span.durationAsLong() >= minDuration() && span.durationAsLong() <= maxDuration();
                } else if (minDuration() != null) {
                    testedDuration = span.durationAsLong() >= minDuration();
                }
            }
        }
    }
    return (serviceName() == null || serviceNameToMatch == null) && remoteServiceNameToMatch == null && spanNameToMatch == null && annotationQueryRemaining.isEmpty() && testedDuration;
}
Also used : Span(zipkin2.Span) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Annotation(zipkin2.Annotation) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Span (zipkin2.Span)48 Test (org.junit.Test)31 Endpoint (zipkin2.Endpoint)17 Test (org.junit.jupiter.api.Test)16 V1Span (zipkin2.v1.V1Span)13 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)4 Call (zipkin2.Call)3 AggregateCall (zipkin2.internal.AggregateCall)3 InsertEntry (zipkin2.storage.cassandra.internal.call.InsertEntry)3 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)1 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)1 SpanSampler (com.wavefront.agent.sampler.SpanSampler)1 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)1