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

codifying peer forwarder local client #626

Merged
merged 1 commit into from
Nov 18, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class PeerForwarder extends AbstractPrepper<Record<ExportTraceServiceRequ
public static final String ERRORS = "errors";
public static final String DESTINATION = "destination";

private static final TraceServiceGrpc.TraceServiceBlockingStub LOCAL_CLIENT = null;

public static final int ASYNC_REQUEST_THREAD_COUNT = 200;

private static final Logger LOG = LoggerFactory.getLogger(PeerForwarder.class);
Expand Down Expand Up @@ -110,12 +112,7 @@ public List<Record<ExportTraceServiceRequest>> doExecute(final Collection<Record
final List<CompletableFuture<Record>> forwardedRequestFutures = new ArrayList<>();

for (final Map.Entry<String, List<ResourceSpans>> entry : groupedRS.entrySet()) {
final TraceServiceGrpc.TraceServiceBlockingStub client;
if (isAddressDefinedLocally(entry.getKey())) {
client = null;
} else {
client = peerClientPool.getClient(entry.getKey());
}
final TraceServiceGrpc.TraceServiceBlockingStub client = getClient(entry.getKey());

// Create ExportTraceRequest for storing single batch of spans
ExportTraceServiceRequest.Builder currRequestBuilder = ExportTraceServiceRequest.newBuilder();
Expand All @@ -124,7 +121,7 @@ public List<Record<ExportTraceServiceRequest>> doExecute(final Collection<Record
final int rsSize = PeerForwarderUtils.getResourceSpansSize(rs);
if (currSpansCount >= maxNumSpansPerRequest) {
final ExportTraceServiceRequest currRequest = currRequestBuilder.build();
if (client == null) {
if (isLocalClient(client)) {
recordsToProcessLocally.add(new Record<>(currRequest));
} else {
forwardedRequestFutures.add(processRequest(client, currRequest));
Expand Down Expand Up @@ -191,6 +188,14 @@ private CompletableFuture<Record> processRequest(final TraceServiceGrpc.TraceSer
return callFuture;
}

private TraceServiceGrpc.TraceServiceBlockingStub getClient(final String address) {
return isAddressDefinedLocally(address) ? LOCAL_CLIENT : peerClientPool.getClient(address);
}

private boolean isLocalClient(final TraceServiceGrpc.TraceServiceBlockingStub client) {
return client == LOCAL_CLIENT;
}

private boolean isAddressDefinedLocally(final String address) {
final InetAddress inetAddress;
try {
Expand Down