use of zipkin.BinaryAnnotation 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;
}
use of zipkin.BinaryAnnotation in project zipkin by openzipkin.
the class DependencyLinkSpan method from.
public static DependencyLinkSpan from(Span s) {
TraceId traceId = new TraceId(s.traceIdHigh, s.traceId);
DependencyLinkSpan.Builder linkSpan = new DependencyLinkSpan.Builder(traceId, s.parentId, s.id);
for (BinaryAnnotation a : s.binaryAnnotations) {
if (a.key.equals(Constants.CLIENT_ADDR) && a.endpoint != null) {
linkSpan.caService(a.endpoint.serviceName);
} else if (a.key.equals(Constants.SERVER_ADDR) && a.endpoint != null) {
linkSpan.saService(a.endpoint.serviceName);
}
}
for (Annotation a : s.annotations) {
if (a.value.equals(Constants.SERVER_RECV) && a.endpoint != null) {
linkSpan.srService(a.endpoint.serviceName);
} else if (a.value.equals(Constants.CLIENT_SEND) && a.endpoint != null) {
linkSpan.csService(a.endpoint.serviceName);
}
}
return linkSpan.build();
}
use of zipkin.BinaryAnnotation in project zipkin by openzipkin.
the class SpanStoreTest method getAllServiceNames_mergesAnnotation_andBinaryAnnotation.
@Test
public void getAllServiceNames_mergesAnnotation_andBinaryAnnotation() {
// creates a span with mutual exclusive endpoints in binary annotations and annotations
BinaryAnnotation yak = BinaryAnnotation.address("sa", Endpoint.create("yak", 127 << 24 | 1));
accept(span1.toBuilder().binaryAnnotations(asList(yak)).build());
// should be in order
assertThat(store().getServiceNames()).containsExactly("service", "yak");
}
Aggregations