use of zipkin.Span in project zipkin by openzipkin.
the class DependenciesTest method oneway_noClient.
/** Async span starts from an uninstrumented source. */
@Test
public void oneway_noClient() {
Endpoint kafka = Endpoint.create("kafka", 172 << 24 | 17 << 16 | 4);
List<Span> trace = asList(Span.builder().traceId(10L).id(10L).name("receive").addAnnotation(Annotation.create((TODAY) * 1000, SERVER_RECV, APP_ENDPOINT)).addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, kafka)).build(), Span.builder().traceId(10L).parentId(10L).id(11L).name("process").timestamp((TODAY + 25) * 1000).duration(325L * 1000).addBinaryAnnotation(BinaryAnnotation.create(LOCAL_COMPONENT, "", APP_ENDPOINT)).build());
processDependencies(trace);
assertThat(store().getDependencies(TODAY + 1000L, null)).containsOnly(DependencyLink.create("kafka", "app", 1));
}
use of zipkin.Span in project zipkin by openzipkin.
the class DependenciesTest method noCoreAnnotations.
/** This test confirms that core ("sr", "cs", "cr", "ss") annotations are not required. */
@Test
public void noCoreAnnotations() {
Endpoint someClient = Endpoint.create("some-client", 172 << 24 | 17 << 16 | 4);
List<Span> trace = asList(Span.builder().traceId(20L).id(20L).name("get").timestamp(TODAY * 1000).duration(350L * 1000).addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, someClient)).addBinaryAnnotation(BinaryAnnotation.address(SERVER_ADDR, WEB_ENDPOINT)).build(), Span.builder().traceId(20L).parentId(20L).id(21L).name("get").timestamp((TODAY + 50) * 1000).duration(250L * 1000).addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, WEB_ENDPOINT)).addBinaryAnnotation(BinaryAnnotation.address(SERVER_ADDR, APP_ENDPOINT)).build(), Span.builder().traceId(20L).parentId(21L).id(22L).name("get").timestamp((TODAY + 150) * 1000).duration(50L * 1000).addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, APP_ENDPOINT)).addBinaryAnnotation(BinaryAnnotation.address(SERVER_ADDR, DB_ENDPOINT)).build());
processDependencies(trace);
assertThat(store().getDependencies(TODAY + 1000, null)).containsOnly(DependencyLink.create("some-client", "web", 1), DependencyLink.create("web", "app", 1), DependencyLink.create("app", "db", 1));
}
use of zipkin.Span in project zipkin by openzipkin.
the class DependenciesTest method getDependencies_noTimestamps.
/**
* Legacy instrumentation don't set Span.timestamp or duration. Make sure dependencies still work.
*/
@Test
public void getDependencies_noTimestamps() {
Endpoint one = Endpoint.create("trace-producer-one", 127 << 24 | 1);
Endpoint onePort3001 = one.toBuilder().port((short) 3001).build();
Endpoint two = Endpoint.create("trace-producer-two", 127 << 24 | 2);
Endpoint twoPort3002 = two.toBuilder().port((short) 3002).build();
Endpoint three = Endpoint.create("trace-producer-three", 127 << 24 | 3);
List<Span> trace = asList(Span.builder().traceId(10L).id(10L).name("get").addAnnotation(Annotation.create(1445136539256150L, SERVER_RECV, one)).addAnnotation(Annotation.create(1445136540408729L, SERVER_SEND, one)).build(), Span.builder().traceId(10L).parentId(10L).id(20L).name("get").addAnnotation(Annotation.create(1445136539764798L, CLIENT_SEND, onePort3001)).addAnnotation(Annotation.create(1445136539816432L, SERVER_RECV, two)).addAnnotation(Annotation.create(1445136540401414L, SERVER_SEND, two)).addAnnotation(Annotation.create(1445136540404135L, CLIENT_RECV, onePort3001)).build(), Span.builder().traceId(10L).parentId(20L).id(30L).name("get").addAnnotation(Annotation.create(1445136540025751L, CLIENT_SEND, twoPort3002)).addAnnotation(Annotation.create(1445136540072846L, SERVER_RECV, three)).addAnnotation(Annotation.create(1445136540394644L, SERVER_SEND, three)).addAnnotation(Annotation.create(1445136540397049L, CLIENT_RECV, twoPort3002)).build());
processDependencies(trace);
long traceDuration = ApplyTimestampAndDuration.apply(trace.get(0)).duration;
assertThat(store().getDependencies((trace.get(0).annotations.get(0).timestamp + traceDuration) / 1000, traceDuration / 1000)).containsOnly(DependencyLink.create("trace-producer-one", "trace-producer-two", 1), DependencyLink.create("trace-producer-two", "trace-producer-three", 1));
}
use of zipkin.Span in project zipkin by openzipkin.
the class DependenciesTest method notInstrumentedClientAndServer.
/**
* This test confirms that the span store can detect dependency indicated by SERVER_ADDR and
* CLIENT_ADDR. In some cases an RPC call is made where one of the two services is not
* instrumented. However, if the other service is able to emit "sa" or "ca" annotation with a
* service name, the link can still be constructed.
*
* span1: CA SR SS: Dependency 1 by a not-instrumented client span2: intermediate call span3: CS
* CR SA: Dependency 2 to a not-instrumented server
*/
@Test
public void notInstrumentedClientAndServer() {
Endpoint someClient = Endpoint.create("some-client", 172 << 24 | 17 << 16 | 4);
List<Span> trace = asList(Span.builder().traceId(20L).id(20L).name("get").timestamp(TODAY * 1000).duration(350L * 1000).addAnnotation(Annotation.create(TODAY * 1000, SERVER_RECV, WEB_ENDPOINT)).addAnnotation(Annotation.create((TODAY + 350) * 1000, SERVER_SEND, WEB_ENDPOINT)).addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, someClient)).build(), Span.builder().traceId(20L).parentId(20L).id(21L).name("get").timestamp((TODAY + 50L) * 1000).duration(250L * 1000).addAnnotation(Annotation.create((TODAY + 50) * 1000, CLIENT_SEND, WEB_ENDPOINT)).addAnnotation(Annotation.create((TODAY + 100) * 1000, SERVER_RECV, APP_ENDPOINT)).addAnnotation(Annotation.create((TODAY + 250) * 1000, SERVER_SEND, APP_ENDPOINT)).addAnnotation(Annotation.create((TODAY + 300) * 1000, CLIENT_RECV, WEB_ENDPOINT)).build(), Span.builder().traceId(20L).parentId(21L).id(22L).name("get").timestamp((TODAY + 150L) * 1000).duration(50L * 1000).addAnnotation(Annotation.create((TODAY + 150) * 1000, CLIENT_SEND, APP_ENDPOINT)).addAnnotation(Annotation.create((TODAY + 200) * 1000, CLIENT_RECV, APP_ENDPOINT)).addBinaryAnnotation(BinaryAnnotation.address(CLIENT_ADDR, APP_ENDPOINT)).addBinaryAnnotation(BinaryAnnotation.address(SERVER_ADDR, DB_ENDPOINT)).build());
processDependencies(trace);
assertThat(store().getDependencies(TODAY + 1000L, null)).containsOnly(DependencyLink.create("some-client", "web", 1), DependencyLink.create("web", "app", 1), DependencyLink.create("app", "db", 1));
}
use of zipkin.Span 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;
}
Aggregations