Search in sources :

Example 6 with UTF_8

use of zipkin2.TestObjects.UTF_8 in project zipkin by openzipkin.

the class SelectSpansAndAnnotations method toTraceIdQuery.

SelectOffsetStep<? extends Record> toTraceIdQuery(DSLContext context, QueryRequest request) {
    long endTs = request.endTs() * 1000;
    TableOnConditionStep<?> table = ZIPKIN_SPANS.join(ZIPKIN_ANNOTATIONS).on(schema.joinCondition(ZIPKIN_ANNOTATIONS));
    int i = 0;
    for (Map.Entry<String, String> kv : request.annotationQuery().entrySet()) {
        ZipkinAnnotations aTable = ZIPKIN_ANNOTATIONS.as("a" + i++);
        if (kv.getValue().isEmpty()) {
            table = maybeOnService(table.join(aTable).on(schema.joinCondition(aTable)).and(aTable.A_KEY.eq(kv.getKey())), aTable, request.serviceName());
        } else {
            table = maybeOnService(table.join(aTable).on(schema.joinCondition(aTable)).and(aTable.A_TYPE.eq(V1BinaryAnnotation.TYPE_STRING)).and(aTable.A_KEY.eq(kv.getKey())).and(aTable.A_VALUE.eq(kv.getValue().getBytes(UTF_8))), aTable, request.serviceName());
        }
    }
    List<SelectField<?>> distinctFields = new ArrayList<>(schema.spanIdFields);
    distinctFields.add(max(ZIPKIN_SPANS.START_TS));
    SelectConditionStep<Record> dsl = context.selectDistinct(distinctFields).from(table).where(ZIPKIN_SPANS.START_TS.between(endTs - request.lookback() * 1000, endTs));
    if (request.serviceName() != null) {
        dsl.and(localServiceNameCondition().and(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.eq(request.serviceName())));
    }
    if (request.remoteServiceName() != null) {
        dsl.and(ZIPKIN_SPANS.REMOTE_SERVICE_NAME.eq(request.remoteServiceName()));
    }
    if (request.spanName() != null) {
        dsl.and(ZIPKIN_SPANS.NAME.eq(request.spanName()));
    }
    if (request.minDuration() != null && request.maxDuration() != null) {
        dsl.and(ZIPKIN_SPANS.DURATION.between(request.minDuration(), request.maxDuration()));
    } else if (request.minDuration() != null) {
        dsl.and(ZIPKIN_SPANS.DURATION.greaterOrEqual(request.minDuration()));
    }
    return dsl.groupBy(schema.spanIdFields).orderBy(max(ZIPKIN_SPANS.START_TS).desc()).limit(request.limit());
}
Also used : ZipkinAnnotations(zipkin2.storage.mysql.v1.internal.generated.tables.ZipkinAnnotations) SelectField(org.jooq.SelectField) ArrayList(java.util.ArrayList) Record(org.jooq.Record) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Endpoint(zipkin2.Endpoint)

Example 7 with UTF_8

use of zipkin2.TestObjects.UTF_8 in project zipkin by openzipkin.

the class V1JsonSpanWriterTest method writesEmptySpanName.

@Test
public void writesEmptySpanName() {
    Span span = Span.newBuilder().traceId("7180c278b62e8f6a216a2aea45d08fc9").parentId("6b221d5bc9e6496c").id("5b4185666d50f68b").build();
    writer.write(span, buf);
    assertThat(new String(bytes, UTF_8)).contains("\"name\":\"\"");
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 8 with UTF_8

use of zipkin2.TestObjects.UTF_8 in project zipkin by openzipkin.

the class V2SpanWriterTest method omitsEmptyServiceName.

@Test
public void omitsEmptyServiceName() {
    Span span = CLIENT_SPAN.toBuilder().localEndpoint(Endpoint.newBuilder().ip("127.0.0.1").build()).build();
    writer.write(span, buf);
    assertThat(new String(bytes, UTF_8)).contains("\"localEndpoint\":{\"ipv4\":\"127.0.0.1\"}");
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 9 with UTF_8

use of zipkin2.TestObjects.UTF_8 in project zipkin by openzipkin.

the class TestObjects method newTraceId.

public static String newTraceId() {
    byte[] traceId = new byte[32];
    WriteBuffer buffer = WriteBuffer.wrap(traceId);
    buffer.writeLongHex(ThreadLocalRandom.current().nextLong());
    buffer.writeLongHex(ThreadLocalRandom.current().nextLong());
    return new String(traceId, UTF_8);
}
Also used : WriteBuffer(zipkin2.internal.WriteBuffer)

Example 10 with UTF_8

use of zipkin2.TestObjects.UTF_8 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

Test (org.junit.Test)8 Span (zipkin2.Span)7 DependencyLink (zipkin2.DependencyLink)2 Endpoint (zipkin2.Endpoint)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Record (org.jooq.Record)1 SelectField (org.jooq.SelectField)1 Test (org.junit.jupiter.api.Test)1 WriteBuffer (zipkin2.internal.WriteBuffer)1 ZipkinAnnotations (zipkin2.storage.mysql.v1.internal.generated.tables.ZipkinAnnotations)1