Search in sources :

Example 1 with Nullable

use of zipkin2.internal.Nullable 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 2 with Nullable

use of zipkin2.internal.Nullable in project zipkin by openzipkin.

the class Endpoint method textToNumericFormatV6.

@Nullable
static byte[] textToNumericFormatV6(String ipString) {
    // An address can have [2..8] colons, and N colons make N+1 parts.
    String[] parts = ipString.split(":", IPV6_PART_COUNT + 2);
    if (parts.length < 3 || parts.length > IPV6_PART_COUNT + 1) {
        return null;
    }
    // Disregarding the endpoints, find "::" with nothing in between.
    // This indicates that a run of zeroes has been skipped.
    int skipIndex = -1;
    for (int i = 1; i < parts.length - 1; i++) {
        if (parts[i].length() == 0) {
            if (skipIndex >= 0) {
                // Can't have more than one ::
                return null;
            }
            skipIndex = i;
        }
    }
    // Number of parts to copy from above/before the "::"
    int partsHi;
    // Number of parts to copy from below/after the "::"
    int partsLo;
    if (skipIndex >= 0) {
        // If we found a "::", then check if it also covers the endpoints.
        partsHi = skipIndex;
        partsLo = parts.length - skipIndex - 1;
        if (parts[0].length() == 0 && --partsHi != 0) {
            // ^: requires ^::
            return null;
        }
        if (parts[parts.length - 1].length() == 0 && --partsLo != 0) {
            // :$ requires ::$
            return null;
        }
    } else {
        // Otherwise, allocate the entire address to partsHi. The endpoints
        // could still be empty, but parseHextet() will check for that.
        partsHi = parts.length;
        partsLo = 0;
    }
    // If we found a ::, then we must have skipped at least one part.
    // Otherwise, we must have exactly the right number of parts.
    int partsSkipped = IPV6_PART_COUNT - (partsHi + partsLo);
    if (!(skipIndex >= 0 ? partsSkipped >= 1 : partsSkipped == 0)) {
        return null;
    }
    // Now parse the hextets into a byte array.
    ByteBuffer rawBytes = ByteBuffer.allocate(2 * IPV6_PART_COUNT);
    try {
        for (int i = 0; i < partsHi; i++) {
            rawBytes.putShort(parseHextet(parts[i]));
        }
        for (int i = 0; i < partsSkipped; i++) {
            rawBytes.putShort((short) 0);
        }
        for (int i = partsLo; i > 0; i--) {
            rawBytes.putShort(parseHextet(parts[parts.length - i]));
        }
    } catch (NumberFormatException ex) {
        return null;
    }
    return rawBytes.array();
}
Also used : ByteBuffer(java.nio.ByteBuffer) Nullable(zipkin2.internal.Nullable)

Example 3 with Nullable

use of zipkin2.internal.Nullable in project zipkin by openzipkin.

the class EndpointCodec method outerToInner.

@Nullable
@Override
protected UdtValue outerToInner(@Nullable Endpoint endpoint) {
    if (endpoint == null)
        return null;
    UdtValue result = getCqlType().newValue();
    result.setString("service", endpoint.serviceName());
    result.setInetAddress("ipv4", inetAddressOrNull(endpoint.ipv4(), endpoint.ipv4Bytes()));
    result.setInetAddress("ipv6", inetAddressOrNull(endpoint.ipv6(), endpoint.ipv6Bytes()));
    result.setInt("port", endpoint.portAsInt());
    return result;
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) Nullable(zipkin2.internal.Nullable)

Example 4 with Nullable

use of zipkin2.internal.Nullable in project zipkin by openzipkin.

the class ThriftCodec method readOne.

@Nullable
public static Span readOne(ReadBuffer buffer) {
    if (buffer.available() == 0)
        return null;
    try {
        V1Span v1Span = new V1ThriftSpanReader().read(buffer);
        List<Span> out = new ArrayList<Span>(1);
        V1SpanConverter.create().convert(v1Span, out);
        return out.get(0);
    } catch (Exception e) {
        throw exceptionReading("Span", e);
    }
}
Also used : ArrayList(java.util.ArrayList) Span(zipkin2.Span) V1Span(zipkin2.v1.V1Span) EOFException(java.io.EOFException) BufferUnderflowException(java.nio.BufferUnderflowException) V1Span(zipkin2.v1.V1Span)

Example 5 with Nullable

use of zipkin2.internal.Nullable in project zipkin by openzipkin.

the class HttpCallTest method propagatesOnDispatcherThreadWhenFatal.

@Test
void propagatesOnDispatcherThreadWhenFatal() throws Exception {
    server.enqueue(SUCCESS_RESPONSE);
    final LinkedBlockingQueue<Object> q = new LinkedBlockingQueue<>();
    CountDownLatch latch = new CountDownLatch(1);
    http.newCall(REQUEST, (parser, contentString) -> {
        latch.countDown();
        throw new LinkageError();
    }, "test").enqueue(new Callback<Object>() {

        @Override
        public void onSuccess(@Nullable Object value) {
            q.add(value);
        }

        @Override
        public void onError(Throwable t) {
            q.add(t);
        }
    });
    // It can take some time for the HTTP response to process. Wait until we reach the parser
    latch.await();
    // Wait a little longer for a callback to fire (it should never do this)
    assertThat(q.poll(100, TimeUnit.MILLISECONDS)).as("expected callbacks to never signal").isNull();
}
Also used : Nullable(zipkin2.internal.Nullable) Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) RequestHeaders(com.linecorp.armeria.common.RequestHeaders) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequestLog(com.linecorp.armeria.common.logging.RequestLog) CompletableFuture(java.util.concurrent.CompletableFuture) EndpointGroupException(com.linecorp.armeria.client.endpoint.EndpointGroupException) AtomicReference(java.util.concurrent.atomic.AtomicReference) LinkedHashMap(java.util.LinkedHashMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) UTF_8(zipkin2.TestObjects.UTF_8) ByteBuf(io.netty.buffer.ByteBuf) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) HttpStatus(com.linecorp.armeria.common.HttpStatus) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) WebClient(com.linecorp.armeria.client.WebClient) PLAIN_TEXT_UTF_8(com.linecorp.armeria.common.MediaType.PLAIN_TEXT_UTF_8) Map(java.util.Map) AggregatedHttpResponse(com.linecorp.armeria.common.AggregatedHttpResponse) Callback(zipkin2.Callback) UnprocessedRequestException(com.linecorp.armeria.client.UnprocessedRequestException) HttpData(com.linecorp.armeria.common.HttpData) Awaitility.await(org.awaitility.Awaitility.await) MockWebServerExtension(com.linecorp.armeria.testing.junit5.server.mock.MockWebServerExtension) IOException(java.io.IOException) HttpMethod(com.linecorp.armeria.common.HttpMethod) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) FileNotFoundException(java.io.FileNotFoundException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) ResponseHeaders(com.linecorp.armeria.common.ResponseHeaders) Call(zipkin2.Call) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

Nullable (zipkin2.internal.Nullable)4 Map (java.util.Map)2 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)1 UnprocessedRequestException (com.linecorp.armeria.client.UnprocessedRequestException)1 WebClient (com.linecorp.armeria.client.WebClient)1 EndpointGroupException (com.linecorp.armeria.client.endpoint.EndpointGroupException)1 AggregatedHttpRequest (com.linecorp.armeria.common.AggregatedHttpRequest)1 AggregatedHttpResponse (com.linecorp.armeria.common.AggregatedHttpResponse)1 HttpData (com.linecorp.armeria.common.HttpData)1 HttpMethod (com.linecorp.armeria.common.HttpMethod)1 HttpStatus (com.linecorp.armeria.common.HttpStatus)1 PLAIN_TEXT_UTF_8 (com.linecorp.armeria.common.MediaType.PLAIN_TEXT_UTF_8)1 RequestHeaders (com.linecorp.armeria.common.RequestHeaders)1 ResponseHeaders (com.linecorp.armeria.common.ResponseHeaders)1 RequestLog (com.linecorp.armeria.common.logging.RequestLog)1 MockWebServerExtension (com.linecorp.armeria.testing.junit5.server.mock.MockWebServerExtension)1 ByteBuf (io.netty.buffer.ByteBuf)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 EOFException (java.io.EOFException)1 FileNotFoundException (java.io.FileNotFoundException)1