Search in sources :

Example 6 with DependencyLink

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();
}
Also used : DependencyLinker(zipkin2.internal.DependencyLinker) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Record(org.jooq.Record) Span(zipkin2.Span) Record1(org.jooq.Record1)

Example 7 with DependencyLink

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);
}
Also used : DependencyLink(zipkin2.DependencyLink) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 8 with DependencyLink

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);
}
Also used : DependencyLink(zipkin2.DependencyLink) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with DependencyLink

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;
}
Also used : DependencyLinker(zipkin2.internal.DependencyLinker) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Span(zipkin2.Span) V1Span(zipkin2.v1.V1Span) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with DependencyLink

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);
}
Also used : DependencyLink(zipkin2.DependencyLink) Test(org.junit.Test)

Aggregations

DependencyLink (zipkin2.DependencyLink)9 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Span (zipkin2.Span)3 LocalDate (java.time.LocalDate)2 LinkedHashMap (java.util.LinkedHashMap)2 DependencyLinker (zipkin2.internal.DependencyLinker)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)1 Kryo (com.esotericsoftware.kryo.Kryo)1 Input (com.esotericsoftware.kryo.io.Input)1 Output (com.esotericsoftware.kryo.io.Output)1 JavaSerializer (com.esotericsoftware.kryo.serializers.JavaSerializer)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ByteBuffer (java.nio.ByteBuffer)1 Connection (java.sql.Connection)1 Arrays.asList (java.util.Arrays.asList)1 Iterator (java.util.Iterator)1 List (java.util.List)1