Search in sources :

Example 6 with LogEntry

use of zipkin2.collector.scribe.generated.LogEntry in project zipkin by openzipkin.

the class ScribeSpanConsumerTest method entriesWithSpansAreConsumed.

@Test
void entriesWithSpansAreConsumed() throws Exception {
    ScribeSpanConsumer scribe = newScribeSpanConsumer("zipkin", consumer);
    LogEntry entry = new LogEntry();
    entry.category = "zipkin";
    entry.message = encodedSpan;
    expectSuccess(scribe, entry);
    // Storage finishes after callback so wait for it.
    await().untilAsserted(() -> assertThat(storage.getTraces()).containsExactly(asList(v2)));
    assertThat(scribeMetrics.messages()).isEqualTo(1);
    assertThat(scribeMetrics.messagesDropped()).isZero();
    assertThat(scribeMetrics.bytes()).isEqualTo(bytes.length);
    assertThat(scribeMetrics.spans()).isEqualTo(1);
    assertThat(scribeMetrics.spansDropped()).isZero();
}
Also used : LogEntry(zipkin2.collector.scribe.generated.LogEntry) Test(org.junit.jupiter.api.Test)

Example 7 with LogEntry

use of zipkin2.collector.scribe.generated.LogEntry in project zipkin by openzipkin.

the class ScribeSpanConsumer method Log.

@Override
public void Log(List<LogEntry> messages, AsyncMethodCallback<ResultCode> resultHandler) {
    metrics.incrementMessages();
    List<Span> spans = new ArrayList<>();
    int byteCount = 0;
    try {
        for (LogEntry logEntry : messages) {
            if (!category.equals(logEntry.category))
                continue;
            byte[] bytes = logEntry.message.getBytes(StandardCharsets.ISO_8859_1);
            // finagle-zipkin uses mime encoding
            bytes = Base64.getMimeDecoder().decode(bytes);
            byteCount += bytes.length;
            spans.add(SpanBytesDecoder.THRIFT.decodeOne(bytes));
        }
    } catch (RuntimeException e) {
        metrics.incrementMessagesDropped();
        resultHandler.onError(e);
        return;
    } finally {
        metrics.incrementBytes(byteCount);
    }
    collector.accept(spans, new Callback<Void>() {

        @Override
        public void onSuccess(Void value) {
            resultHandler.onComplete(ResultCode.OK);
        }

        @Override
        public void onError(Throwable t) {
            Exception error = t instanceof Exception ? (Exception) t : new RuntimeException(t);
            resultHandler.onError(error);
        }
    }, CommonPools.blockingTaskExecutor());
}
Also used : ArrayList(java.util.ArrayList) Span(zipkin2.Span) LogEntry(zipkin2.collector.scribe.generated.LogEntry)

Example 8 with LogEntry

use of zipkin2.collector.scribe.generated.LogEntry in project zipkin by openzipkin.

the class ITScribeCollector method normal.

@Test
void normal() throws Exception {
    // Java version of this sample code
    // https://github.com/facebookarchive/scribe/wiki/Logging-Messages
    TTransport transport = new TFramedTransport(new TSocket("localhost", server.port()));
    TProtocol protocol = new TBinaryProtocol(transport, false, false);
    Scribe.Iface client = new Scribe.Client(protocol);
    List<LogEntry> entries = TestObjects.TRACE.stream().map(ITScribeCollector::logEntry).collect(Collectors.toList());
    transport.open();
    try {
        ResultCode code = client.Log(entries);
        assertThat(code).isEqualTo(ResultCode.OK);
        code = client.Log(entries);
        assertThat(code).isEqualTo(ResultCode.OK);
    } finally {
        transport.close();
    }
    verify(collector, times(2)).accept(eq(TestObjects.TRACE), any(), eq(CommonPools.blockingTaskExecutor()));
    verify(metrics, times(2)).incrementMessages();
}
Also used : Scribe(zipkin2.collector.scribe.generated.Scribe) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.layered.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) LogEntry(zipkin2.collector.scribe.generated.LogEntry) ResultCode(zipkin2.collector.scribe.generated.ResultCode) TSocket(org.apache.thrift.transport.TSocket) Test(org.junit.jupiter.api.Test)

Aggregations

LogEntry (zipkin2.collector.scribe.generated.LogEntry)8 Test (org.junit.jupiter.api.Test)7 Call (zipkin2.Call)2 Span (zipkin2.Span)2 ResultCode (zipkin2.collector.scribe.generated.ResultCode)2 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Base64 (java.util.Base64)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 AsyncMethodCallback (org.apache.thrift.async.AsyncMethodCallback)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TSocket (org.apache.thrift.transport.TSocket)1 TTransport (org.apache.thrift.transport.TTransport)1 TFramedTransport (org.apache.thrift.transport.layered.TFramedTransport)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Awaitility.await (org.awaitility.Awaitility.await)1