From 272ca0e938313235b54d919b83194c76fb09b43f Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Fri, 15 Sep 2017 16:45:00 +0200
Subject: [PATCH] Senders fix, do not use static thrift factory (#233)
---
.../main/java/com/uber/jaeger/senders/HttpSender.java | 9 ++++-----
.../main/java/com/uber/jaeger/senders/ThriftSender.java | 2 +-
.../src/main/java/com/uber/jaeger/senders/UdpSender.java | 6 ++----
3 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/jaeger-core/src/main/java/com/uber/jaeger/senders/HttpSender.java b/jaeger-core/src/main/java/com/uber/jaeger/senders/HttpSender.java
index 289ab80c2..d50868e86 100644
--- a/jaeger-core/src/main/java/com/uber/jaeger/senders/HttpSender.java
+++ b/jaeger-core/src/main/java/com/uber/jaeger/senders/HttpSender.java
@@ -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;
@@ -75,7 +73,7 @@ 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) {
@@ -83,12 +81,13 @@ private HttpSender(String endpoint, int maxPayloadBytes, OkHttpClient client) {
}
this.httpClient = client;
this.requestBuilder = new Request.Builder().url(collectorUrl);
+ this.serializer = new TSerializer(protocolFactory);
}
@Override
public void send(Process process, List 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();
diff --git a/jaeger-core/src/main/java/com/uber/jaeger/senders/ThriftSender.java b/jaeger-core/src/main/java/com/uber/jaeger/senders/ThriftSender.java
index 55c34b658..d20fa037c 100644
--- a/jaeger-core/src/main/java/com/uber/jaeger/senders/ThriftSender.java
+++ b/jaeger-core/src/main/java/com/uber/jaeger/senders/ThriftSender.java
@@ -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) {
diff --git a/jaeger-core/src/main/java/com/uber/jaeger/senders/UdpSender.java b/jaeger-core/src/main/java/com/uber/jaeger/senders/UdpSender.java
index 5fd22f10b..23da30b6f 100644
--- a/jaeger-core/src/main/java/com/uber/jaeger/senders/UdpSender.java
+++ b/jaeger-core/src/main/java/com/uber/jaeger/senders/UdpSender.java
@@ -31,11 +31,9 @@
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;
@@ -43,7 +41,7 @@ public class UdpSender extends ThriftSender {
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;
@@ -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