Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Senders fix, do not use static thrift factory (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavolloffay authored and vprithvi committed Sep 15, 2017
1 parent 912bfdb commit 272ca0e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@
import org.apache.thrift.TException;
import org.apache.thrift.TSerializer;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocolFactory;

public class HttpSender extends ThriftSender {

private static final String HTTP_COLLECTOR_JAEGER_THRIFT_FORMAT_PARAM = "format=jaeger.thrift";
private static final TProtocolFactory PROTOCOL_FACTORY = new TBinaryProtocol.Factory();
private static final TSerializer SERIALIZER = new TSerializer(PROTOCOL_FACTORY);
private static final int ONE_MB_IN_BYTES = 1048576;
private static final MediaType MEDIA_TYPE_THRIFT = MediaType.parse("application/x-thrift");
private final TSerializer serializer;
private final OkHttpClient httpClient;
private final Request.Builder requestBuilder;

Expand Down Expand Up @@ -75,20 +73,21 @@ public HttpSender(String endpoint, int maxPayloadBytes) {
* @param client a client used to make http requests
*/
private HttpSender(String endpoint, int maxPayloadBytes, OkHttpClient client) {
super(PROTOCOL_FACTORY, maxPayloadBytes);
super(new TBinaryProtocol.Factory(), maxPayloadBytes);
HttpUrl collectorUrl = HttpUrl
.parse(String.format("%s?%s", endpoint, HTTP_COLLECTOR_JAEGER_THRIFT_FORMAT_PARAM));
if (collectorUrl == null) {
throw new IllegalArgumentException("Could not parse url.");
}
this.httpClient = client;
this.requestBuilder = new Request.Builder().url(collectorUrl);
this.serializer = new TSerializer(protocolFactory);
}

@Override
public void send(Process process, List<Span> spans) throws TException {
Batch batch = new Batch(process, spans);
byte[] bytes = SERIALIZER.serialize(batch);
byte[] bytes = serializer.serialize(batch);

RequestBody body = RequestBody.create(MEDIA_TYPE_THRIFT, bytes);
Request request = requestBuilder.post(body).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public abstract class ThriftSender implements Sender {
private int byteBufferSize;
private AutoExpandingBufferWriteTransport memoryTransport;

private final TProtocolFactory protocolFactory;
protected final TProtocolFactory protocolFactory;
private final int maxSpanBytes;

public ThriftSender(TProtocolFactory protocolFactory, int maxPacketSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@
import lombok.ToString;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocolFactory;

@ToString(exclude = {"agentClient"})
public class UdpSender extends ThriftSender {
private static final TProtocolFactory PROTOCOL_FACTORY = new TCompactProtocol.Factory();
public static final String DEFAULT_AGENT_UDP_HOST = "localhost";
public static final int DEFAULT_AGENT_UDP_COMPACT_PORT = 6831;

private Agent.Client agentClient;
private ThriftUdpTransport udpTransport;

public UdpSender(String host, int port, int maxPacketSize) {
super(PROTOCOL_FACTORY, maxPacketSize);
super(new TCompactProtocol.Factory(), maxPacketSize);

if (host == null || host.length() == 0) {
host = DEFAULT_AGENT_UDP_HOST;
Expand All @@ -54,7 +52,7 @@ public UdpSender(String host, int port, int maxPacketSize) {
}

udpTransport = ThriftUdpTransport.newThriftUdpClient(host, port);
agentClient = new Agent.Client(PROTOCOL_FACTORY.getProtocol(udpTransport));
agentClient = new Agent.Client(protocolFactory.getProtocol(udpTransport));
}

@Override
Expand Down

0 comments on commit 272ca0e

Please sign in to comment.