Search in sources :

Example 1 with AutoExpandingBufferWriteTransport

use of org.apache.thrift.transport.AutoExpandingBufferWriteTransport in project jaeger-client-java by jaegertracing.

the class UdpSenderTest method testAppend.

@Test
public void testAppend() throws Exception {
    // find size of the initial span
    Span jaegerSpan = (Span) tracer.buildSpan("raza").startManual();
    com.uber.jaeger.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan(jaegerSpan);
    Process process = new Process(tracer.getServiceName()).setTags(JaegerThriftSpanConverter.buildTags(tracer.tags()));
    AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(maxPacketSize, 2);
    process.write(new TCompactProtocol(memoryTransport));
    int processSize = memoryTransport.getPos();
    memoryTransport.reset();
    span.write(new TCompactProtocol((memoryTransport)));
    int spanSize = memoryTransport.getPos();
    // create a sender thats a multiple of the span size (accounting for span overhead)
    // this allows us to test the boundary conditions of writing spans.
    int expectedNumSpans = 11;
    int maxPacketSize = (spanSize * expectedNumSpans) + sender.EMIT_BATCH_OVERHEAD + processSize;
    int maxPacketSizeLeft = maxPacketSize - sender.EMIT_BATCH_OVERHEAD - processSize;
    // add enough spans to be under buffer limit
    sender = new UdpSender(destHost, destPort, maxPacketSize);
    while (spanSize < maxPacketSizeLeft) {
        sender.append(jaegerSpan);
        maxPacketSizeLeft -= spanSize;
    }
    // add a span that overflows the limit to hit the last branch
    int result = sender.append(jaegerSpan);
    assertEquals(expectedNumSpans, result);
}
Also used : AutoExpandingBufferWriteTransport(org.apache.thrift.transport.AutoExpandingBufferWriteTransport) Process(com.uber.jaeger.thriftjava.Process) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Span(com.uber.jaeger.Span) Test(org.junit.Test)

Example 2 with AutoExpandingBufferWriteTransport

use of org.apache.thrift.transport.AutoExpandingBufferWriteTransport in project jaeger-client-java by jaegertracing.

the class ZipkinSenderTest method testAppend.

@Test
public void testAppend() throws Exception {
    // find size of the initial span
    AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(messageMaxBytes, 2);
    Span jaegerSpan = (Span) tracer.buildSpan("raza").startManual();
    com.twitter.zipkin.thriftjava.Span span = ThriftSpanConverter.convertSpan(jaegerSpan);
    int expectedNumSpans = 11;
    List<byte[]> spansToSend = new ArrayList<>(expectedNumSpans);
    for (int i = 0; i < expectedNumSpans; i++) {
        spansToSend.add(new ThriftSpanEncoder().encode(sender.backFillHostOnAnnotations(span)));
    }
    // create a sender thats a multiple of the span size (accounting for span overhead)
    // this allows us to test the boundary conditions of writing spans.
    int messageMaxBytes = sender.delegate.messageSizeInBytes(spansToSend);
    sender.close();
    sender = newSender(messageMaxBytes);
    // add enough spans to be under buffer limit
    for (int i = 0; i < expectedNumSpans - 1; i++) {
        assertEquals(0, sender.append(jaegerSpan));
    }
    // add a span that overflows the limit to hit the last branch
    int result = sender.append(jaegerSpan);
    assertEquals(expectedNumSpans, result);
}
Also used : AutoExpandingBufferWriteTransport(org.apache.thrift.transport.AutoExpandingBufferWriteTransport) ArrayList(java.util.ArrayList) Span(com.uber.jaeger.Span) Test(org.junit.Test)

Example 3 with AutoExpandingBufferWriteTransport

use of org.apache.thrift.transport.AutoExpandingBufferWriteTransport in project jaeger-client-java by jaegertracing.

the class UdpSenderTest method calculateBatchOverheadDifference.

private int calculateBatchOverheadDifference(int numberOfSpans) throws Exception {
    AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(maxPacketSize, 2);
    Agent.Client memoryClient = new Agent.Client(new TCompactProtocol((memoryTransport)));
    Span jaegerSpan = (Span) tracer.buildSpan("raza").startManual();
    com.uber.jaeger.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan(jaegerSpan);
    List<com.uber.jaeger.thriftjava.Span> spans = new ArrayList<>();
    for (int i = 0; i < numberOfSpans; i++) {
        spans.add(span);
    }
    memoryClient.emitBatch(new Batch(new Process(SERVICE_NAME), spans));
    int emitBatchOverheadMultipleSpans = memoryTransport.getPos();
    memoryTransport.reset();
    for (int j = 0; j < numberOfSpans; j++) {
        span.write(new TCompactProtocol(memoryTransport));
    }
    int writeBatchOverheadMultipleSpans = memoryTransport.getPos();
    return emitBatchOverheadMultipleSpans - writeBatchOverheadMultipleSpans;
}
Also used : AutoExpandingBufferWriteTransport(org.apache.thrift.transport.AutoExpandingBufferWriteTransport) Agent(com.uber.jaeger.agent.thrift.Agent) ArrayList(java.util.ArrayList) Process(com.uber.jaeger.thriftjava.Process) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Span(com.uber.jaeger.Span) Batch(com.uber.jaeger.thriftjava.Batch)

Aggregations

Span (com.uber.jaeger.Span)3 AutoExpandingBufferWriteTransport (org.apache.thrift.transport.AutoExpandingBufferWriteTransport)3 Process (com.uber.jaeger.thriftjava.Process)2 ArrayList (java.util.ArrayList)2 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)2 Test (org.junit.Test)2 Agent (com.uber.jaeger.agent.thrift.Agent)1 Batch (com.uber.jaeger.thriftjava.Batch)1