Skip to content

Commit

Permalink
Creating a new sender when a sender has been closed.
Browse files Browse the repository at this point in the history
Resolves jaegertracing#684

* Adding a closed attribute on sender
* Sender configuration is resolving again is sender is closed.

Issue: jaegertracing#684
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
  • Loading branch information
ehsavoie committed Feb 12, 2020
1 parent 3e20f62 commit 870d8d7
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ public SenderConfiguration withAuthPassword(String password) {
* @return the sender passed via the constructor or a properly configured sender
*/
public Sender getSender() {
if (sender == null) {
if (sender == null || sender.isClosed()) {
sender = SenderResolver.resolve(this);
}
return sender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
@ToString
public class NoopSender implements Sender {
private boolean closed = false;

@Override
public int append(JaegerSpan span) {
return 1;
Expand All @@ -36,6 +38,13 @@ public int flush() {

@Override
public int close() {
this.closed = true;
return 0;
}

@Override
public boolean isClosed() {
return closed;
}

}
2 changes: 2 additions & 0 deletions jaeger-core/src/main/java/io/jaegertracing/spi/Sender.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface Sender {
int flush() throws SenderException;

int close() throws SenderException;

boolean isClosed();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class InMemorySender implements Sender {
private List<JaegerSpan> flushed;
private List<JaegerSpan> received;
private Semaphore semaphore = new Semaphore(Integer.MAX_VALUE);
private boolean closed = false;

public InMemorySender() {
appended = new ArrayList<>();
Expand Down Expand Up @@ -75,9 +76,15 @@ public int flush() throws SenderException {

@Override
public int close() throws SenderException {
this.closed = true;
return flush();
}

@Override
public boolean isClosed() {
return closed;
}

/**
* Removes previously granted "append" permits and grants
* a new number of permits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private Sender getSenderForServiceFileContents(String contents, boolean append)
}

static class CustomSender implements Sender {
private boolean closed = false;

@Override
public int append(JaegerSpan span) {
Expand All @@ -137,9 +138,15 @@ public int flush() {

@Override
public int close() {
this.closed = true;
return 0;
}

@Override
public boolean isClosed() {
return closed;
}

@Override
public String toString() {
return "CustomSender{}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public abstract class ThriftSender extends ThriftSenderBase implements Sender {
private Process process;
private int processBytesSize;
private int byteBufferSize;
private boolean closed = false;

@ToString.Exclude private List<io.jaegertracing.thriftjava.Span> spanBuffer;

Expand Down Expand Up @@ -119,7 +120,13 @@ public int flush() throws SenderException {

@Override
public int close() throws SenderException {
this.closed = true;
return flush();
}

@Override
public boolean isClosed() {
return closed;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public final class ZipkinSender implements Sender {

@ToString.Exclude final ThriftSpanEncoder encoder = new ThriftSpanEncoder();
@ToString.Exclude final List<byte[]> spanBuffer;
private boolean closed = false;

/**
* @param endpoint The POST URL for zipkin's <a href="http://zipkin.io/zipkin-api/#/">v1 api</a>,
Expand Down Expand Up @@ -178,9 +179,15 @@ public int close() throws SenderException {
} catch (IOException e) {
throw new SenderException("Failed to close " + delegate, e, n);
}
this.closed = true;
return n;
}

@Override
public boolean isClosed() {
return closed;
}

// serviceName/host is needed on annotations so zipkin can query
// see https://github.com/jaegertracing/jaeger-client-java/pull/75 for more info
static Span backFillHostOnAnnotations(Span span) {
Expand Down

0 comments on commit 870d8d7

Please # to comment.