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);
}
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)");
}
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);
}
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());
}
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;
}
Aggregations