Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky rector netty test #9081

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix flaky rector netty test
  • Loading branch information
laurit committed Jul 31, 2023
commit eecfd1bd2dc97628ad416f6198eaa9688198b2c6
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientResend;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.concurrent.LinkedBlockingQueue;
import javax.annotation.Nullable;
import reactor.netty.http.client.HttpClientRequest;
import reactor.netty.http.client.HttpClientResponse;

final class InstrumentationContexts {

private static final Logger logger = Logger.getLogger(InstrumentationContexts.class.getName());

private volatile Context parentContext;
// on retries, reactor-netty starts the next resend attempt before it ends the previous one (i.e.
// it calls the callback functions in that order); thus for a short moment there can be 2
// it calls the callback functions in that order); thus for a short moment there can be multiple
// coexisting HTTP client spans
private final Queue<RequestAndContext> clientContexts = new ArrayBlockingQueue<>(2, true);
private final Queue<RequestAndContext> clientContexts = new LinkedBlockingQueue<>();

void initialize(Context parentContext) {
this.parentContext = HttpClientResend.initialize(parentContext);
Expand All @@ -47,13 +43,7 @@ Context startClientSpan(HttpClientRequest request) {
Context context = null;
if (instrumenter().shouldStart(parentContext, request)) {
context = instrumenter().start(parentContext, request);
if (!clientContexts.offer(new RequestAndContext(request, context))) {
// should not ever happen in reality
String message =
"Could not instrument HTTP client request; not enough space in the request queue";
logger.log(Level.FINE, message);
instrumenter().end(context, request, null, new IllegalStateException(message));
}
clientContexts.offer(new RequestAndContext(request, context));
}
return context;
}
Expand Down
Loading