Skip to content

Commit 66a57e3

Browse files
committed
Implement request_drain for already sent data plane requests for graceful termination of the ext-proc stream.
1 parent 0eaf51c commit 66a57e3

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

‎xds/src/main/java/io/grpc/xds/ExternalProcessorFilter.java‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.envoyproxy.envoy.extensions.filters.http.ext_proc.v3.ExternalProcessor;
1313
import io.envoyproxy.envoy.service.ext_proc.v3.ExternalProcessorGrpc;
1414
import io.envoyproxy.envoy.service.ext_proc.v3.ProcessingRequest;
15+
import io.envoyproxy.envoy.service.ext_proc.v3.ProcessingResponse;
1516
import io.grpc.CallOptions;
1617
import io.grpc.Channel;
1718
import io.grpc.ClientCall;
@@ -220,14 +221,20 @@ public void start(Listener<RespT> responseListener, Metadata headers) {
220221
this.requestHeaders = headers;
221222
ExternalProcessorInterceptor.ExtProcListener<ReqT, RespT> wrappedListener = new ExternalProcessorInterceptor.ExtProcListener<>(responseListener, delegate(), method, this);
222223

223-
requestObserver = stub.process(new io.grpc.stub.StreamObserver<io.envoyproxy.envoy.service.ext_proc.v3.ProcessingResponse>() {
224+
requestObserver = stub.process(new io.grpc.stub.StreamObserver<ProcessingResponse>() {
224225
@Override
225226
public void onNext(io.envoyproxy.envoy.service.ext_proc.v3.ProcessingResponse response) {
226227
if (response.hasImmediateResponse()) {
227228
handleImmediateResponse(response.getImmediateResponse(), responseListener);
228229
return;
229230
}
230231

232+
if (response.getRequestDrain()) {
233+
handleFailOpen(wrappedListener);
234+
requestObserver.onCompleted();
235+
return;
236+
}
237+
231238
// --- Handlers for 6 Event types ---
232239

233240
// 1. Client Headers
@@ -535,7 +542,21 @@ void unblockAfterStreamComplete() {
535542

536543
@VisibleForTesting
537544
ExternalProcessorGrpc.ExternalProcessorStub getExternalProcessorStub(GrpcService service) {
538-
return null; // Implementation needed
545+
// TODO: Implement actual stub creation based on the GrpcService configuration.
546+
// This will likely involve creating a ManagedChannel and then a stub from it.
547+
// For now, returning null as a placeholder.
548+
//
549+
// This method needs to create a ManagedChannel based on the GrpcService configuration.
550+
// The GrpcService contains information like target URI, timeout, and optionally
551+
// a Google gRPC service config.
552+
// For a full implementation, you would typically use a ManagedChannelBuilder
553+
// to construct the channel and then create a stub from it.
554+
// Example (simplified, actual implementation would need more details from GrpcService):
555+
// ManagedChannel channel = ManagedChannelBuilder.forTarget(service.getEnvoyGrpc().getClusterName())
556+
// .usePlaintext() // Or use TLS based on configuration
557+
// .build();
558+
// return ExternalProcessorGrpc.newStub(channel);
559+
return null;
539560
}
540561
}
541562
}

0 commit comments

Comments
 (0)