Search in sources :

Example 21 with Endpoint

use of org.pjsip.pjsua2.Endpoint in project zipkin by openzipkin.

the class ITDependenciesHeavy method manyLinks.

/**
 * Ensure there's no query limit problem around links
 */
@Test
protected void manyLinks() throws Exception {
    // Larger than 10, which is the default ES search limit that tripped this
    int count = 1000;
    List<Span> spans = new ArrayList<>(count);
    for (int i = 1; i <= count; i++) {
        String traceId = newTraceId();
        Endpoint web = FRONTEND.toBuilder().serviceName("web-" + i).build();
        Endpoint app = BACKEND.toBuilder().serviceName("app-" + i).build();
        Endpoint db = DB.toBuilder().serviceName("db-" + i).build();
        spans.add(Span.newBuilder().traceId(traceId).id("10").name("get").timestamp((TODAY + 50L) * 1000L).duration(250L * 1000L).kind(Kind.CLIENT).localEndpoint(web).build());
        spans.add(Span.newBuilder().traceId(traceId).id("10").name("get").shared(true).timestamp((TODAY + 100) * 1000L).duration(150 * 1000L).kind(Kind.SERVER).localEndpoint(app).build());
        spans.add(Span.newBuilder().traceId(traceId).parentId("10").id("11").name("get").timestamp((TODAY + 150L) * 1000L).duration(50L * 1000L).kind(Kind.CLIENT).localEndpoint(app).remoteEndpoint(db).build());
    }
    processDependencies(spans);
    List<DependencyLink> links = store().getDependencies(endTs(spans), DAY).execute();
    // web-? -> app-?, app-? -> db-?
    assertThat(links).hasSize(count * 2);
    assertThat(links).extracting(DependencyLink::callCount).allSatisfy(callCount -> assertThat(callCount).isEqualTo(1));
}
Also used : Endpoint(zipkin2.Endpoint) ArrayList(java.util.ArrayList) DependencyLink(zipkin2.DependencyLink) Span(zipkin2.Span) Endpoint(zipkin2.Endpoint) Test(org.junit.jupiter.api.Test)

Example 22 with Endpoint

use of org.pjsip.pjsua2.Endpoint 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();
}
Also used : Endpoint(zipkin2.Endpoint) Record(org.jooq.Record) Span(zipkin2.Span) NoSuchElementException(java.util.NoSuchElementException)

Example 23 with Endpoint

use of org.pjsip.pjsua2.Endpoint in project zipkin by openzipkin.

the class ITSpanStore method setupDurationData.

List<List<Span>> setupDurationData(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    Endpoint frontend = suffixServiceName(TestObjects.FRONTEND, testSuffix);
    Endpoint backend = suffixServiceName(TestObjects.BACKEND, testSuffix);
    Endpoint db = suffixServiceName(TestObjects.DB, testSuffix);
    String traceId1 = newTraceId(), traceId2 = newTraceId(), traceId3 = newTraceId();
    // to make sure queries look back properly
    long offsetMicros = (TODAY - 3) * 1000L;
    Span targz = Span.newBuilder().traceId(traceId1).id(1L).name("targz").timestamp(offsetMicros + 100L).duration(200_000L).localEndpoint(frontend).remoteEndpoint(db).putTag("lc", "archiver").build();
    Span tar = Span.newBuilder().traceId(traceId1).id(2L).parentId(1L).name("tar").timestamp(offsetMicros + 200L).duration(150_000L).localEndpoint(backend).remoteEndpoint(backend).putTag("lc", "archiver").build();
    Span gz = Span.newBuilder().traceId(traceId1).id(3L).parentId(1L).name("gz").timestamp(offsetMicros + 250L).duration(50_000L).localEndpoint(db).remoteEndpoint(frontend).putTag("lc", "archiver").build();
    Span zip = Span.newBuilder().traceId(traceId3).id(3L).name("zip").timestamp(offsetMicros + 130L).duration(50_000L).addAnnotation(offsetMicros + 130L, "zip").localEndpoint(backend).remoteEndpoint(backend).putTag("lc", "archiver").build();
    List<Span> trace1 = asList(targz, tar, gz);
    List<Span> trace2 = asList(targz.toBuilder().traceId(traceId2).timestamp(offsetMicros + 110L).localEndpoint(db).remoteEndpoint(frontend).putTag("lc", "archiver-v2").build(), tar.toBuilder().traceId(traceId2).timestamp(offsetMicros + 210L).localEndpoint(backend).remoteEndpoint(backend).putTag("lc", "archiver").build(), gz.toBuilder().traceId(traceId2).timestamp(offsetMicros + 260L).localEndpoint(frontend).remoteEndpoint(backend).putTag("lc", "archiver").build());
    List<Span> trace3 = asList(zip);
    accept(trace1);
    accept(trace2);
    accept(trace3);
    return asList(trace1, trace2, trace3);
}
Also used : Endpoint(zipkin2.Endpoint) TestObjects.newClientSpan(zipkin2.TestObjects.newClientSpan) Span(zipkin2.Span)

Example 24 with Endpoint

use of org.pjsip.pjsua2.Endpoint 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 25 with Endpoint

use of org.pjsip.pjsua2.Endpoint in project zipkin by openzipkin.

the class V2SpanWriter method writeEndpoint.

static void writeEndpoint(Endpoint value, WriteBuffer b, boolean writeEmptyServiceName) {
    b.writeByte('{');
    boolean wroteField = false;
    String serviceName = value.serviceName();
    if (serviceName == null && writeEmptyServiceName)
        serviceName = "";
    if (serviceName != null) {
        b.writeAscii("\"serviceName\":\"");
        b.writeUtf8(jsonEscape(serviceName));
        b.writeByte('"');
        wroteField = true;
    }
    if (value.ipv4() != null) {
        if (wroteField)
            b.writeByte(',');
        b.writeAscii("\"ipv4\":\"");
        b.writeAscii(value.ipv4());
        b.writeByte('"');
        wroteField = true;
    }
    if (value.ipv6() != null) {
        if (wroteField)
            b.writeByte(',');
        b.writeAscii("\"ipv6\":\"");
        b.writeAscii(value.ipv6());
        b.writeByte('"');
        wroteField = true;
    }
    int port = value.portAsInt();
    if (port != 0) {
        if (wroteField)
            b.writeByte(',');
        b.writeAscii("\"port\":");
        b.writeAscii(port);
    }
    b.writeByte('}');
}
Also used : Endpoint(zipkin2.Endpoint)

Aggregations

Endpoint (zipkin2.Endpoint)55 Span (zipkin2.Span)27 Test (org.junit.jupiter.api.Test)18 V1Span (zipkin2.v1.V1Span)16 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)5 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)5 List (java.util.List)3 JsonToken (com.fasterxml.jackson.core.JsonToken)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 NetworkInterface (java.net.NetworkInterface)2 Arrays.asList (java.util.Arrays.asList)2 Endpoint (org.jboss.remoting3.Endpoint)2 Record (org.jooq.Record)2 Access (org.openstack4j.model.identity.v2.Access)2 V1SpanConverter (zipkin2.v1.V1SpanConverter)2 Tracing (brave.Tracing)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CrnkClient (io.crnk.client.CrnkClient)1