Search in sources :

Example 1 with Annotation

use of org.exquery.xquery3.Annotation in project brave by openzipkin.

the class MutableSpanMapTest method reportOrphanedSpans_afterGC.

/**
 * This is the key feature. Spans orphaned via GC are reported to zipkin on the next action.
 *
 * <p>This is a customized version of https://github.com/raphw/weak-lock-free/blob/master/src/test/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMapTest.java
 */
@Test
public void reportOrphanedSpans_afterGC() {
    TraceContext context1 = context.toBuilder().spanId(1).build();
    map.getOrCreate(context1);
    TraceContext context2 = context.toBuilder().spanId(2).build();
    map.getOrCreate(context2);
    TraceContext context3 = context.toBuilder().spanId(3).build();
    map.getOrCreate(context3);
    TraceContext context4 = context.toBuilder().spanId(4).build();
    map.getOrCreate(context4);
    // By clearing strong references in this test, we are left with the weak ones in the map
    context1 = context2 = null;
    blockOnGC();
    // After GC, we expect that the weak references of context1 and context2 to be cleared
    assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(null, null, context3, context4);
    map.reportOrphanedSpans();
    // After reporting, we expect no the weak references of null
    assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(context3, context4);
    // We also expect the spans to have been reported
    assertThat(spans).flatExtracting(Span::annotations).extracting(Annotation::value).containsExactly("brave.flush", "brave.flush");
}
Also used : Tracing(brave.Tracing) PowerMockito.mockStatic(org.powermock.api.mockito.PowerMockito.mockStatic) PowerMockito.when(org.powermock.api.mockito.PowerMockito.when) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Span(zipkin2.Span) Test(org.junit.Test) TraceContext(brave.propagation.TraceContext) ArrayList(java.util.ArrayList) Reference(java.lang.ref.Reference) List(java.util.List) Annotation(zipkin2.Annotation) Platform(brave.internal.Platform) Endpoint(zipkin2.Endpoint) After(org.junit.After) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Reference(java.lang.ref.Reference) TraceContext(brave.propagation.TraceContext) Span(zipkin2.Span) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with Annotation

use of org.exquery.xquery3.Annotation in project spring-cloud-gcp by spring-cloud.

the class LabelExtractor method extract.

/**
 * Extracts the Stackdriver span labels that are equivalent to the Zipkin Span
 * annotations.
 *
 * @param zipkinSpan The Zipkin Span
 * @return A map of the Stackdriver span labels equivalent to the Zipkin annotations.
 */
public Map<String, String> extract(Span zipkinSpan) {
    Map<String, String> result = new LinkedHashMap<>();
    for (Map.Entry<String, String> tag : zipkinSpan.tags().entrySet()) {
        result.put(label(tag.getKey()), tag.getValue());
    }
    // trace might not show the final destination.
    if (zipkinSpan.localEndpoint() != null && zipkinSpan.kind() == Span.Kind.SERVER) {
        if (zipkinSpan.localEndpoint().ipv4() != null) {
            result.put(label("endpoint.ipv4"), zipkinSpan.localEndpoint().ipv4());
        }
        if (zipkinSpan.localEndpoint().ipv6() != null) {
            result.put(label("endpoint.ipv6"), zipkinSpan.localEndpoint().ipv6());
        }
    }
    for (Annotation annotation : zipkinSpan.annotations()) {
        result.put(label(annotation.value()), formatTimestamp(annotation.timestamp()));
    }
    if (zipkinSpan.localEndpoint() != null && !zipkinSpan.localEndpoint().serviceName().isEmpty()) {
        result.put("/component", zipkinSpan.localEndpoint().serviceName());
    }
    if (zipkinSpan.parentId() == null) {
        String agentName = System.getProperty("stackdriver.trace.zipkin.agent", "spring-cloud-gcp-trace");
        result.put("/agent", agentName);
    }
    return result;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) Annotation(zipkin2.Annotation) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with Annotation

use of org.exquery.xquery3.Annotation in project zipkin by openzipkin.

the class BulkIndexWriter method addSearchFields.

static void addSearchFields(Span span, JsonGenerator writer) throws IOException {
    long timestampMillis = span.timestampAsLong() / 1000L;
    if (timestampMillis != 0L)
        writer.writeNumberField("timestamp_millis", timestampMillis);
    if (!span.tags().isEmpty() || !span.annotations().isEmpty()) {
        writer.writeArrayFieldStart("_q");
        for (Annotation a : span.annotations()) {
            if (a.value().length() > SHORT_STRING_LENGTH)
                continue;
            writer.writeString(a.value());
        }
        for (Map.Entry<String, String> tag : span.tags().entrySet()) {
            int length = tag.getKey().length() + tag.getValue().length() + 1;
            if (length > SHORT_STRING_LENGTH)
                continue;
            // search is possible by key alone
            writer.writeString(tag.getKey());
            writer.writeString(tag.getKey() + "=" + tag.getValue());
        }
        writer.writeEndArray();
    }
}
Also used : Map(java.util.Map) Annotation(zipkin2.Annotation) Endpoint(zipkin2.Endpoint)

Example 4 with Annotation

use of org.exquery.xquery3.Annotation in project zipkin by openzipkin.

the class CassandraUtil method annotationQuery.

/**
 * Returns a set of annotation getValues and tags joined on equals, delimited by ░
 *
 * <p>Values over {@link RecyclableBuffers#SHORT_STRING_LENGTH} are not considered. Zipkin's
 * {@link QueryRequest#annotationQuery()} are equals match. Not all values are lookup values. For
 * example, {@code sql.query} isn't something that is likely to be looked up by value and indexing
 * that could add a potentially kilobyte partition key on {@link Schema#TABLE_SPAN}
 *
 * @see QueryRequest#annotationQuery()
 */
@Nullable
static String annotationQuery(Span span) {
    if (span.annotations().isEmpty() && span.tags().isEmpty())
        return null;
    // as very unlikely to be in the query
    char delimiter = '░';
    StringBuilder result = new StringBuilder().append(delimiter);
    for (Annotation a : span.annotations()) {
        if (a.value().length() > SHORT_STRING_LENGTH)
            continue;
        result.append(a.value()).append(delimiter);
    }
    for (Map.Entry<String, String> tag : span.tags().entrySet()) {
        if (tag.getValue().length() > SHORT_STRING_LENGTH)
            continue;
        // search is possible by key alone
        result.append(tag.getKey()).append(delimiter);
        result.append(tag.getKey()).append('=').append(tag.getValue()).append(delimiter);
    }
    return result.length() == 1 ? null : result.toString();
}
Also used : TreeMap(java.util.TreeMap) Map(java.util.Map) Annotation(zipkin2.Annotation) Nullable(zipkin2.internal.Nullable)

Example 5 with Annotation

use of org.exquery.xquery3.Annotation in project zipkin by openzipkin.

the class V2SpanWriter method sizeInBytes.

@Override
public int sizeInBytes(Span value) {
    // {"traceId":""
    int sizeInBytes = 13;
    sizeInBytes += value.traceId().length();
    if (value.parentId() != null) {
        // ,"parentId":"0123456789abcdef"
        sizeInBytes += 30;
    }
    // ,"id":"0123456789abcdef"
    sizeInBytes += 24;
    if (value.kind() != null) {
        // ,"kind":""
        sizeInBytes += 10;
        sizeInBytes += value.kind().name().length();
    }
    if (value.name() != null) {
        // ,"name":""
        sizeInBytes += 10;
        sizeInBytes += jsonEscapedSizeInBytes(value.name());
    }
    if (value.timestampAsLong() != 0L) {
        // ,"timestamp":
        sizeInBytes += 13;
        sizeInBytes += asciiSizeInBytes(value.timestampAsLong());
    }
    if (value.durationAsLong() != 0L) {
        // ,"duration":
        sizeInBytes += 12;
        sizeInBytes += asciiSizeInBytes(value.durationAsLong());
    }
    if (value.localEndpoint() != null) {
        // ,"localEndpoint":
        sizeInBytes += 17;
        sizeInBytes += endpointSizeInBytes(value.localEndpoint(), false);
    }
    if (value.remoteEndpoint() != null) {
        // ,"remoteEndpoint":
        sizeInBytes += 18;
        sizeInBytes += endpointSizeInBytes(value.remoteEndpoint(), false);
    }
    if (!value.annotations().isEmpty()) {
        // ,"annotations":[]
        sizeInBytes += 17;
        int length = value.annotations().size();
        // comma to join elements
        if (length > 1)
            sizeInBytes += length - 1;
        for (int i = 0; i < length; i++) {
            Annotation a = value.annotations().get(i);
            sizeInBytes += annotationSizeInBytes(a.timestamp(), a.value(), 0);
        }
    }
    if (!value.tags().isEmpty()) {
        // ,"tags":{}
        sizeInBytes += 10;
        int tagCount = value.tags().size();
        // comma to join elements
        if (tagCount > 1)
            sizeInBytes += tagCount - 1;
        for (Map.Entry<String, String> entry : value.tags().entrySet()) {
            // "":""
            sizeInBytes += 5;
            sizeInBytes += jsonEscapedSizeInBytes(entry.getKey());
            sizeInBytes += jsonEscapedSizeInBytes(entry.getValue());
        }
    }
    if (Boolean.TRUE.equals(value.debug())) {
        // ,"debug":true
        sizeInBytes += 13;
    }
    if (Boolean.TRUE.equals(value.shared())) {
        // ,"shared":true
        sizeInBytes += 14;
    }
    // }
    return ++sizeInBytes;
}
Also used : Map(java.util.Map) Endpoint(zipkin2.Endpoint) Annotation(zipkin2.Annotation)

Aggregations

Annotation (zipkin2.Annotation)14 Map (java.util.Map)8 Test (org.junit.Test)5 Endpoint (zipkin2.Endpoint)5 ArrayList (java.util.ArrayList)4 Span (zipkin2.Span)4 LinkedHashMap (java.util.LinkedHashMap)3 TreeMap (java.util.TreeMap)3 QName (javax.xml.namespace.QName)3 Annotation (org.sbolstandard.core2.Annotation)3 JsonToken (com.fasterxml.jackson.core.JsonToken)2 JaegerSpan (io.jaegertracing.internal.JaegerSpan)2 IOException (java.io.IOException)2 URI (java.net.URI)2 List (java.util.List)2 Tracing (brave.Tracing)1 Platform (brave.internal.Platform)1 TraceContext (brave.propagation.TraceContext)1 TimeEvents (com.google.devtools.cloudtrace.v2.Span.TimeEvents)1 Timestamp (com.google.protobuf.Timestamp)1