Search in sources :

Example 1 with SUCCESSFUL_2XX

use of io.servicetalk.http.api.HttpResponseStatus.StatusClass.SUCCESSFUL_2XX in project servicetalk by apple.

the class HttpReporter method encodedSpansReporter.

private static Function<Buffer, Completable> encodedSpansReporter(final HttpClient client, final Codec codec) {
    final String path;
    final CharSequence contentType;
    switch(codec) {
        case JSON_V1:
            path = V1_PATH;
            contentType = APPLICATION_JSON;
            break;
        case JSON_V2:
            path = V2_PATH;
            contentType = APPLICATION_JSON;
            break;
        case THRIFT:
            path = V2_PATH;
            contentType = THRIFT_CONTENT_TYPE;
            break;
        case PROTO3:
            path = V2_PATH;
            contentType = PROTO_CONTENT_TYPE;
            break;
        default:
            throw new IllegalArgumentException("Unknown codec: " + codec);
    }
    return encodedSpans -> client.request(client.post(path).setHeader(CONTENT_TYPE, contentType).payloadBody(encodedSpans)).beforeOnSuccess(response -> {
        HttpResponseStatus status = response.status();
        if (status.statusClass() != SUCCESSFUL_2XX) {
            LOGGER.info("Unexpected response from the collector. Response headers: {}", response.toString((__, headerValue) -> headerValue));
        }
    }).ignoreElement().onErrorComplete(cause -> {
        LOGGER.error("Failed to send a span, ignoring.", cause);
        return true;
    });
}
Also used : APPLICATION_JSON(io.servicetalk.http.api.HttpHeaderValues.APPLICATION_JSON) Publisher(io.servicetalk.concurrent.api.Publisher) LoggerFactory(org.slf4j.LoggerFactory) Span(zipkin2.Span) CONTENT_TYPE(io.servicetalk.http.api.HttpHeaderNames.CONTENT_TYPE) CharSequences.newAsciiString(io.servicetalk.buffer.api.CharSequences.newAsciiString) Duration.ofSeconds(java.time.Duration.ofSeconds) Function(java.util.function.Function) ArrayList(java.util.ArrayList) SourceAdapters.fromSource(io.servicetalk.concurrent.api.SourceAdapters.fromSource) Duration(java.time.Duration) Objects.requireNonNull(java.util.Objects.requireNonNull) Component(zipkin2.Component) SpanBytesEncoder(zipkin2.codec.SpanBytesEncoder) HttpClient(io.servicetalk.http.api.HttpClient) AsyncCloseable(io.servicetalk.concurrent.api.AsyncCloseable) Reporter(zipkin2.reporter.Reporter) Nonnull(javax.annotation.Nonnull) Processors.newCompletableProcessor(io.servicetalk.concurrent.api.Processors.newCompletableProcessor) Accumulator(io.servicetalk.concurrent.api.BufferStrategy.Accumulator) Processors.newPublisherProcessorDropHeadOnOverflow(io.servicetalk.concurrent.api.Processors.newPublisherProcessorDropHeadOnOverflow) Logger(org.slf4j.Logger) FutureUtils.awaitTermination(io.servicetalk.concurrent.internal.FutureUtils.awaitTermination) PublisherSource(io.servicetalk.concurrent.PublisherSource) OK(zipkin2.CheckResult.OK) Completable(io.servicetalk.concurrent.api.Completable) CompositeCloseable(io.servicetalk.concurrent.api.CompositeCloseable) CheckResult.failed(zipkin2.CheckResult.failed) BufferStrategies.forCountOrTime(io.servicetalk.concurrent.api.BufferStrategies.forCountOrTime) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) CheckResult(zipkin2.CheckResult) AsyncCloseables.toAsyncCloseable(io.servicetalk.concurrent.api.AsyncCloseables.toAsyncCloseable) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) CompletableSource(io.servicetalk.concurrent.CompletableSource) SUCCESSFUL_2XX(io.servicetalk.http.api.HttpResponseStatus.StatusClass.SUCCESSFUL_2XX) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) List(java.util.List) Buffer(io.servicetalk.buffer.api.Buffer) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) Collections(java.util.Collections) HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus) HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus) CharSequences.newAsciiString(io.servicetalk.buffer.api.CharSequences.newAsciiString)

Aggregations

Buffer (io.servicetalk.buffer.api.Buffer)1 BufferAllocator (io.servicetalk.buffer.api.BufferAllocator)1 CharSequences.newAsciiString (io.servicetalk.buffer.api.CharSequences.newAsciiString)1 CompletableSource (io.servicetalk.concurrent.CompletableSource)1 PublisherSource (io.servicetalk.concurrent.PublisherSource)1 AsyncCloseable (io.servicetalk.concurrent.api.AsyncCloseable)1 AsyncCloseables.newCompositeCloseable (io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable)1 AsyncCloseables.toAsyncCloseable (io.servicetalk.concurrent.api.AsyncCloseables.toAsyncCloseable)1 BufferStrategies.forCountOrTime (io.servicetalk.concurrent.api.BufferStrategies.forCountOrTime)1 Accumulator (io.servicetalk.concurrent.api.BufferStrategy.Accumulator)1 Completable (io.servicetalk.concurrent.api.Completable)1 Completable.completed (io.servicetalk.concurrent.api.Completable.completed)1 CompositeCloseable (io.servicetalk.concurrent.api.CompositeCloseable)1 Processors.newCompletableProcessor (io.servicetalk.concurrent.api.Processors.newCompletableProcessor)1 Processors.newPublisherProcessorDropHeadOnOverflow (io.servicetalk.concurrent.api.Processors.newPublisherProcessorDropHeadOnOverflow)1 Publisher (io.servicetalk.concurrent.api.Publisher)1 SourceAdapters.fromSource (io.servicetalk.concurrent.api.SourceAdapters.fromSource)1 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)1 FutureUtils.awaitTermination (io.servicetalk.concurrent.internal.FutureUtils.awaitTermination)1 HttpClient (io.servicetalk.http.api.HttpClient)1