Search in sources :

Example 1 with V1SpanConverter

use of zipkin2.v1.V1SpanConverter in project zipkin by openzipkin.

the class V1JsonSpanReader method readList.

public boolean readList(ReadBuffer buffer, Collection<Span> out) {
    if (buffer.available() == 0)
        return false;
    V1SpanConverter converter = V1SpanConverter.create();
    JsonReader reader = new JsonReader(buffer);
    try {
        reader.beginArray();
        if (!reader.hasNext())
            return false;
        while (reader.hasNext()) {
            V1Span result = fromJson(reader);
            converter.convert(result, out);
        }
        reader.endArray();
        return true;
    } catch (Exception e) {
        throw exceptionReading("List<Span>", e);
    }
}
Also used : V1SpanConverter(zipkin2.v1.V1SpanConverter) JsonReader(zipkin2.internal.JsonCodec.JsonReader) IOException(java.io.IOException) V1Span(zipkin2.v1.V1Span)

Example 2 with V1SpanConverter

use of zipkin2.v1.V1SpanConverter in project zipkin by openzipkin.

the class ITDependencies method duplicateAddress.

/**
 * This test confirms that the span store can process trace with intermediate spans like the below
 * properly.
 * <p>
 * span1: SR SS span2: intermediate call span3: CS SR SS CR: Dependency 1
 */
@Test
protected void duplicateAddress(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    String traceId = newTraceId();
    Endpoint frontend = suffixServiceName(TestObjects.FRONTEND, testSuffix);
    Endpoint backend = suffixServiceName(TestObjects.BACKEND, testSuffix);
    V1SpanConverter converter = V1SpanConverter.create();
    List<Span> trace = new ArrayList<>();
    converter.convert(V1Span.newBuilder().traceId(traceId).id("20").name("get").timestamp(TODAY * 1000L).duration(350L * 1000L).addAnnotation(TODAY * 1000, "sr", frontend).addAnnotation((TODAY + 350) * 1000, "ss", frontend).addBinaryAnnotation("ca", frontend).addBinaryAnnotation("sa", frontend).build(), trace);
    converter.convert(V1Span.newBuilder().traceId(traceId).parentId("21").id("22").name("get").timestamp((TODAY + 50) * 1000L).duration(250L * 1000L).addAnnotation((TODAY + 50) * 1000, "cs", frontend).addAnnotation((TODAY + 300) * 1000, "cr", frontend).addBinaryAnnotation("ca", backend).addBinaryAnnotation("sa", backend).build(), trace);
    processDependencies(trace);
    assertThat(store().getDependencies(TODAY + 1000, 1000L).execute()).containsOnly(DependencyLink.newBuilder().parent(frontend.serviceName()).child(backend.serviceName()).callCount(1).build());
}
Also used : Endpoint(zipkin2.Endpoint) V1SpanConverter(zipkin2.v1.V1SpanConverter) ArrayList(java.util.ArrayList) Span(zipkin2.Span) V1Span(zipkin2.v1.V1Span) Test(org.junit.jupiter.api.Test)

Example 3 with V1SpanConverter

use of zipkin2.v1.V1SpanConverter in project zipkin by openzipkin.

the class SelectSpansAndAnnotations method apply.

@Override
public List<Span> apply(DSLContext context) {
    final Map<Pair, List<V1Span.Builder>> spansWithoutAnnotations;
    final Map<Row3<Long, Long, Long>, List<Record>> dbAnnotations;
    spansWithoutAnnotations = context.select(schema.spanFields).from(ZIPKIN_SPANS).where(traceIdCondition(context)).stream().map(r -> V1Span.newBuilder().traceIdHigh(maybeGet(r, ZIPKIN_SPANS.TRACE_ID_HIGH, 0L)).traceId(r.getValue(ZIPKIN_SPANS.TRACE_ID)).name(r.getValue(ZIPKIN_SPANS.NAME)).id(r.getValue(ZIPKIN_SPANS.ID)).parentId(maybeGet(r, ZIPKIN_SPANS.PARENT_ID, 0L)).timestamp(maybeGet(r, ZIPKIN_SPANS.START_TS, 0L)).duration(maybeGet(r, ZIPKIN_SPANS.DURATION, 0L)).debug(r.getValue(ZIPKIN_SPANS.DEBUG))).collect(groupingBy(s -> new Pair(s.traceIdHigh(), s.traceId()), LinkedHashMap::new, Collectors.toList()));
    dbAnnotations = context.select(schema.annotationFields).from(ZIPKIN_ANNOTATIONS).where(schema.annotationsTraceIdCondition(spansWithoutAnnotations.keySet())).orderBy(ZIPKIN_ANNOTATIONS.A_TIMESTAMP.asc(), ZIPKIN_ANNOTATIONS.A_KEY.asc()).stream().collect(groupingBy((Record a) -> row(maybeGet(a, ZIPKIN_ANNOTATIONS.TRACE_ID_HIGH, 0L), a.getValue(ZIPKIN_ANNOTATIONS.TRACE_ID), a.getValue(ZIPKIN_ANNOTATIONS.SPAN_ID)), LinkedHashMap::new, // LinkedHashMap preserves order while grouping
    Collectors.toList()));
    V1SpanConverter converter = V1SpanConverter.create();
    List<Span> allSpans = new ArrayList<>(spansWithoutAnnotations.size());
    for (List<V1Span.Builder> spans : spansWithoutAnnotations.values()) {
        for (V1Span.Builder span : spans) {
            Row3<Long, Long, Long> key = row(span.traceIdHigh(), span.traceId(), span.id());
            if (dbAnnotations.containsKey(key)) {
                for (Record a : dbAnnotations.get(key)) {
                    Endpoint endpoint = endpoint(a);
                    processAnnotationRecord(a, span, endpoint);
                }
            }
            converter.convert(span.build(), allSpans);
        }
    }
    return allSpans;
}
Also used : ArrayList(java.util.ArrayList) Span(zipkin2.Span) V1Span(zipkin2.v1.V1Span) LinkedHashMap(java.util.LinkedHashMap) Endpoint(zipkin2.Endpoint) V1SpanConverter(zipkin2.v1.V1SpanConverter) HexCodec.lowerHexToUnsignedLong(zipkin2.internal.HexCodec.lowerHexToUnsignedLong) ArrayList(java.util.ArrayList) List(java.util.List) Record(org.jooq.Record) V1Span(zipkin2.v1.V1Span) Row3(org.jooq.Row3)

Example 4 with V1SpanConverter

use of zipkin2.v1.V1SpanConverter in project zipkin by openzipkin.

the class ThriftCodec method readList.

public static boolean readList(ReadBuffer buffer, Collection<Span> out) {
    int length = buffer.available();
    if (length == 0)
        return false;
    try {
        int listLength = readListLength(buffer);
        if (listLength == 0)
            return false;
        V1ThriftSpanReader reader = new V1ThriftSpanReader();
        V1SpanConverter converter = V1SpanConverter.create();
        for (int i = 0; i < listLength; i++) {
            V1Span v1Span = reader.read(buffer);
            converter.convert(v1Span, out);
        }
    } catch (Exception e) {
        throw exceptionReading("List<Span>", e);
    }
    return true;
}
Also used : V1SpanConverter(zipkin2.v1.V1SpanConverter) EOFException(java.io.EOFException) BufferUnderflowException(java.nio.BufferUnderflowException) V1Span(zipkin2.v1.V1Span)

Aggregations

V1Span (zipkin2.v1.V1Span)4 V1SpanConverter (zipkin2.v1.V1SpanConverter)4 ArrayList (java.util.ArrayList)2 Endpoint (zipkin2.Endpoint)2 Span (zipkin2.Span)2 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 BufferUnderflowException (java.nio.BufferUnderflowException)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Record (org.jooq.Record)1 Row3 (org.jooq.Row3)1 Test (org.junit.jupiter.api.Test)1 HexCodec.lowerHexToUnsignedLong (zipkin2.internal.HexCodec.lowerHexToUnsignedLong)1 JsonReader (zipkin2.internal.JsonCodec.JsonReader)1