use of zipkin2.DependencyLink in project zipkin by openzipkin.
the class AggregateDependencies method apply.
@Override
public List<DependencyLink> apply(DSLContext context) {
// Subquery on trace IDs to prevent only matching the part of the trace that exists within
// the interval: we want all of the trace.
SelectConditionStep<Record1<Long>> traceIDs = context.selectDistinct(ZIPKIN_SPANS.TRACE_ID).from(ZIPKIN_SPANS).where(startTsBegin == startTsEnd ? ZIPKIN_SPANS.START_TS.lessOrEqual(startTsEnd) : ZIPKIN_SPANS.START_TS.between(startTsBegin, startTsEnd));
// Lazy fetching the cursor prevents us from buffering the whole dataset in memory.
Cursor<Record> cursor = context.selectDistinct(schema.dependencyLinkerFields).from(ZIPKIN_SPANS.leftJoin(ZIPKIN_ANNOTATIONS).on(ZIPKIN_SPANS.TRACE_ID.eq(ZIPKIN_ANNOTATIONS.TRACE_ID).and(ZIPKIN_SPANS.ID.eq(ZIPKIN_ANNOTATIONS.SPAN_ID))).and(ZIPKIN_ANNOTATIONS.A_KEY.in("lc", "cs", "ca", "sr", "sa", "ma", "mr", "ms", "error"))).where(ZIPKIN_SPANS.TRACE_ID.in(traceIDs)).groupBy(schema.dependencyLinkerGroupByFields).fetchLazy();
Iterator<Iterator<Span>> traces = new DependencyLinkV2SpanIterator.ByTraceId(cursor.iterator(), schema.hasTraceIdHigh);
if (!traces.hasNext())
return Collections.emptyList();
DependencyLinker linker = new DependencyLinker();
List<Span> nextTrace = new ArrayList<>();
while (traces.hasNext()) {
Iterator<Span> i = traces.next();
while (i.hasNext()) nextTrace.add(i.next());
linker.putTrace(nextTrace);
nextTrace.clear();
}
return linker.link();
}
use of zipkin2.DependencyLink in project zipkin by openzipkin.
the class DependenciesTest method dependenciesRoundTrip.
@Test
public void dependenciesRoundTrip() {
DependencyLink ab = DependencyLink.newBuilder().parent("a").child("b").callCount(2L).build();
DependencyLink cd = DependencyLink.newBuilder().parent("c").child("d").errorCount(2L).build();
Dependencies dependencies = Dependencies.create(1L, 2L, asList(ab, cd));
ByteBuffer bytes = dependencies.toThrift();
assertThat(Dependencies.fromThrift(bytes)).isEqualTo(dependencies);
}
use of zipkin2.DependencyLink in project zipkin by openzipkin.
the class DependencyLinker method merge.
/**
* links are merged by mapping to parent/child and summing corresponding links
*/
public static List<DependencyLink> merge(Iterable<DependencyLink> in) {
Map<Pair, Long> callCounts = new LinkedHashMap<Pair, Long>();
Map<Pair, Long> errorCounts = new LinkedHashMap<Pair, Long>();
for (DependencyLink link : in) {
Pair parentChild = new Pair(link.parent(), link.child());
long callCount = callCounts.containsKey(parentChild) ? callCounts.get(parentChild) : 0L;
callCount += link.callCount();
callCounts.put(parentChild, callCount);
long errorCount = errorCounts.containsKey(parentChild) ? errorCounts.get(parentChild) : 0L;
errorCount += link.errorCount();
errorCounts.put(parentChild, errorCount);
}
return link(callCounts, errorCounts);
}
use of zipkin2.DependencyLink in project zipkin by openzipkin.
the class ITDependencies method aggregateLinks.
/**
* Returns links aggregated by midnight
*/
public static Map<Long, List<DependencyLink>> aggregateLinks(List<Span> spans) {
Map<Long, DependencyLinker> midnightToLinker = new LinkedHashMap<>();
for (List<Span> trace : GroupByTraceId.create(false).map(spans)) {
long midnightOfTrace = flooredTraceTimestamp(trace);
DependencyLinker linker = midnightToLinker.get(midnightOfTrace);
if (linker == null)
midnightToLinker.put(midnightOfTrace, (linker = new DependencyLinker()));
linker.putTrace(trace);
}
Map<Long, List<DependencyLink>> result = new LinkedHashMap<>();
midnightToLinker.forEach((midnight, linker) -> result.put(midnight, linker.link()));
return result;
}
use of zipkin2.DependencyLink in project zipkin by openzipkin.
the class JsonSerializersTest method dependencyLinkRoundTrip_withError.
@Test
public void dependencyLinkRoundTrip_withError() {
DependencyLink link = DependencyLink.newBuilder().parent("foo").child("bar").callCount(2).errorCount(1).build();
assertThat(parse(JsonSerializers.DEPENDENCY_LINK_PARSER, new String(DependencyLinkBytesEncoder.JSON_V1.encode(link), UTF_8))).isEqualTo(link);
}
Aggregations