use of zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class DependencyLinkV2SpanIteratorTest method whenServerLabelsAreMissing_kindIsUnknownAndLabelsAreCleared.
/**
* The linker is biased towards server spans, or client spans that know the peer localEndpoint().
*/
@Test
public void whenServerLabelsAreMissing_kindIsUnknownAndLabelsAreCleared() {
DependencyLinkV2SpanIterator iterator = iterator(newRecord().values(traceIdHigh, traceId, parentId, spanId, "ca", TYPE_BOOLEAN, "s1"));
Span span = iterator.next();
assertThat(span.kind()).isNull();
assertThat(span.localEndpoint()).isNull();
assertThat(span.remoteEndpoint()).isNull();
}
use of zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class ITDependencies method getDependenciesAllInstrumented.
/**
* When all servers are instrumented, they all record {@link Kind#SERVER} and the {@link
* Span#localEndpoint()} indicates the service.
*/
@Test
protected void getDependenciesAllInstrumented(TestInfo testInfo) throws Exception {
String testSuffix = testSuffix(testInfo);
String traceId = newTraceId();
String frontend = appendSuffix(TestObjects.FRONTEND.serviceName(), testSuffix);
String backend = appendSuffix(TestObjects.BACKEND.serviceName(), testSuffix);
String db = appendSuffix(TestObjects.DB.serviceName(), testSuffix);
Endpoint one = Endpoint.newBuilder().serviceName(frontend).ip("127.0.0.1").build();
Endpoint onePort3001 = one.toBuilder().port(3001).build();
Endpoint two = Endpoint.newBuilder().serviceName(backend).ip("127.0.0.2").build();
Endpoint twoPort3002 = two.toBuilder().port(3002).build();
Endpoint three = Endpoint.newBuilder().serviceName(db).ip("127.0.0.3").build();
List<Span> trace = asList(Span.newBuilder().traceId(traceId).id("10").name("get").kind(Kind.SERVER).timestamp(TODAY * 1000L).duration(350 * 1000L).localEndpoint(one).build(), Span.newBuilder().traceId(traceId).parentId("10").id("20").name("get").kind(Kind.CLIENT).timestamp((TODAY + 50) * 1000L).duration(250 * 1000L).localEndpoint(onePort3001).build(), Span.newBuilder().traceId(traceId).parentId("10").id("20").name("get").shared(true).kind(Kind.SERVER).timestamp((TODAY + 100) * 1000L).duration(150 * 1000L).localEndpoint(two).build(), Span.newBuilder().traceId(traceId).parentId("20").id("30").name("query").kind(Kind.CLIENT).timestamp((TODAY + 150) * 1000L).duration(50 * 1000L).localEndpoint(twoPort3002).build(), Span.newBuilder().traceId(traceId).parentId("20").id("30").name("query").shared(true).kind(Kind.SERVER).timestamp((TODAY + 160) * 1000L).duration(20 * 1000L).localEndpoint(three).build());
processDependencies(trace);
assertThat(store().getDependencies(endTs(trace), DAY).execute()).containsOnly(DependencyLink.newBuilder().parent(frontend).child(backend).callCount(1).build(), DependencyLink.newBuilder().parent(backend).child(db).callCount(1).build());
}
use of zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class DependencyLinkV2SpanIterator method next.
@Override
public Span next() {
if (!hasNext())
throw new NoSuchElementException();
Record row = delegate.peek();
long spanId = row.getValue(ZipkinSpans.ZIPKIN_SPANS.ID);
boolean error = false;
String lcService = null, srService = null, csService = null, caService = null, saService = null, maService = null, mrService = null, msService = null;
while (hasNext()) {
// there are more values for this trace
if (spanId != delegate.peek().getValue(ZipkinSpans.ZIPKIN_SPANS.ID)) {
// if we are in a new span
break;
}
// row for the same span
Record next = delegate.next();
String key = emptyToNull(next, ZIPKIN_ANNOTATIONS.A_KEY);
String value = emptyToNull(next, ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME);
// neither client nor server
if (key == null || value == null)
continue;
switch(key) {
case "lc":
lcService = value;
break;
case "ca":
caService = value;
break;
case "cs":
csService = value;
break;
case "ma":
maService = value;
break;
case "mr":
mrService = value;
break;
case "ms":
msService = value;
break;
case "sa":
saService = value;
break;
case "sr":
srService = value;
break;
case "error":
// a span is in error if it has a tag, not an annotation, of name "error"
error = V1BinaryAnnotation.TYPE_STRING == next.get(ZIPKIN_ANNOTATIONS.A_TYPE);
}
}
// The client address is more authoritative than the client send owner.
if (caService == null)
caService = csService;
// Skip the client side, so it isn't mistaken for a loopback request
if (saService != null && saService.equals(caService))
caService = null;
long parentId = maybeGet(row, ZipkinSpans.ZIPKIN_SPANS.PARENT_ID, 0L);
Span.Builder result = Span.newBuilder().traceId(traceIdHi, traceIdLo).parentId(parentId).id(spanId);
if (error) {
result.putTag("error", "");
}
if (srService != null) {
return result.kind(Span.Kind.SERVER).localEndpoint(ep(srService)).remoteEndpoint(ep(caService)).build();
} else if (saService != null) {
Endpoint localEndpoint = ep(caService);
// When span.kind is missing, the local endpoint is "lc" and the remote endpoint is "sa"
if (localEndpoint == null)
localEndpoint = ep(lcService);
return result.kind(csService != null ? Span.Kind.CLIENT : null).localEndpoint(localEndpoint).remoteEndpoint(ep(saService)).build();
} else if (csService != null) {
return result.kind(Span.Kind.SERVER).localEndpoint(ep(caService)).build();
} else if (mrService != null) {
return result.kind(Span.Kind.CONSUMER).localEndpoint(ep(mrService)).remoteEndpoint(ep(maService)).build();
} else if (msService != null) {
return result.kind(Span.Kind.PRODUCER).localEndpoint(ep(msService)).remoteEndpoint(ep(maService)).build();
}
return result.build();
}
use of zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class DependencyLinkV2SpanIteratorTest method whenSrServiceExists_kindIsServer.
/**
* "sr" is only applied when the local span is acting as a server
*/
@Test
public void whenSrServiceExists_kindIsServer() {
DependencyLinkV2SpanIterator iterator = iterator(newRecord().values(traceIdHigh, traceId, parentId, spanId, "sr", -1, "service"));
Span span = iterator.next();
assertThat(span.kind()).isEqualTo(Span.Kind.SERVER);
assertThat(span.localServiceName()).isEqualTo("service");
assertThat(span.remoteEndpoint()).isNull();
}
use of zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class V1SpanConverter method processBinaryAnnotations.
void processBinaryAnnotations(V1Span source) {
zipkin2.Endpoint ca = null, sa = null, ma = null;
for (int i = 0, length = source.binaryAnnotations.size(); i < length; i++) {
V1BinaryAnnotation b = source.binaryAnnotations.get(i);
// endpoint. Hence, we leniently parse.
if ("ca".equals(b.key)) {
ca = b.endpoint;
continue;
} else if ("sa".equals(b.key)) {
sa = b.endpoint;
continue;
} else if ("ma".equals(b.key)) {
ma = b.endpoint;
continue;
}
Span.Builder currentSpan = forEndpoint(source, b.endpoint);
// don't add marker "lc" tags
if ("lc".equals(b.key) && b.stringValue.isEmpty())
continue;
currentSpan.putTag(b.key, b.stringValue);
}
boolean noCoreAnnotations = cs == null && cr == null && ss == null && sr == null;
// special-case when we are missing core annotations, but we have both address annotations
if (noCoreAnnotations && (ca != null || sa != null)) {
if (ca != null && sa != null) {
forEndpoint(source, ca).remoteEndpoint(sa);
} else if (sa != null) {
// "sa" is a default for a remote address, don't make it a client span
forEndpoint(source, null).remoteEndpoint(sa);
} else {
// ca != null: treat it like a server
forEndpoint(source, null).kind(Kind.SERVER).remoteEndpoint(ca);
}
return;
}
V1Annotation server = sr != null ? sr : ss;
if (ca != null && server != null && !ca.equals(server.endpoint)) {
// the same service name as "sa". Removing the service name prevents creating loopback links.
if (hasSameServiceName(ca, server.endpoint)) {
ca = ca.toBuilder().serviceName(null).build();
}
forEndpoint(source, server.endpoint).remoteEndpoint(ca);
}
if (sa != null) {
// client span
if (cs != null) {
forEndpoint(source, cs.endpoint).remoteEndpoint(sa);
} else if (cr != null) {
forEndpoint(source, cr.endpoint).remoteEndpoint(sa);
}
}
if (ma != null) {
// a messaging span. This will ensure both sides have the address of the broker.
if (ms != null)
forEndpoint(source, ms.endpoint).remoteEndpoint(ma);
if (mr != null)
forEndpoint(source, mr.endpoint).remoteEndpoint(ma);
}
}
Aggregations