Skip to content

Commit 0eaf51c

Browse files
committed
Implement fail-open when config has failure_mode_allow set to true.
1 parent 56ab7ce commit 0eaf51c

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
112112
Channel next) {
113113

114114
ExternalProcessorGrpc.ExternalProcessorStub stub = getExternalProcessorStub(filterConfig.externalProcessor.getGrpcService());
115-
115+
ExternalProcessor config = filterConfig.externalProcessor;
116116
// Wrap the outgoing call to intercept client events
117-
return new ExtProcClientCall<>(next.newCall(method, callOptions), stub, method);
117+
return new ExtProcClientCall<>(next.newCall(method, callOptions), stub, method, config);
118118
}
119119

120120
// --- SHARED UTILITY METHODS ---
@@ -196,6 +196,7 @@ private static void applyHeaderMutations(Metadata headers, io.envoyproxy.envoy.s
196196
private static class ExtProcClientCall<ReqT, RespT> extends SimpleForwardingClientCall<ReqT, RespT> {
197197
private final ExternalProcessorGrpc.ExternalProcessorStub stub;
198198
private final MethodDescriptor<ReqT, RespT> method;
199+
private final ExternalProcessor config;
199200
private io.grpc.stub.StreamObserver<io.envoyproxy.envoy.service.ext_proc.v3.ProcessingRequest> requestObserver;
200201

201202
private boolean headersSent = false;
@@ -206,10 +207,12 @@ private static class ExtProcClientCall<ReqT, RespT> extends SimpleForwardingClie
206207

207208
protected ExtProcClientCall(ClientCall<ReqT, RespT> delegate,
208209
ExternalProcessorGrpc.ExternalProcessorStub stub,
209-
MethodDescriptor<ReqT, RespT> method) {
210+
MethodDescriptor<ReqT, RespT> method,
211+
ExternalProcessor config) {
210212
super(delegate);
211213
this.stub = stub;
212214
this.method = method;
215+
this.config = config;
213216
}
214217

215218
@Override
@@ -268,23 +271,18 @@ else if (response.hasResponseBody()) {
268271

269272
@Override
270273
public void onError(Throwable t) {
271-
if (extProcStreamFailed.compareAndSet(false, true)) {
272-
delegate().cancel("External processor stream failed", t);
274+
if (config.getFailureModeAllow()) {
275+
handleFailOpen(wrappedListener);
276+
} else {
277+
if (extProcStreamFailed.compareAndSet(false, true)) {
278+
delegate().cancel("External processor stream failed", t);
279+
}
273280
}
274281
}
275282

276283
@Override
277284
public void onCompleted() {
278-
if (extProcStreamCompleted.compareAndSet(false, true)) {
279-
// The ext_proc server has gracefully closed the stream.
280-
// Unblock any part of the interceptor that is currently waiting.
281-
if (!headersSent) {
282-
headersSent = true;
283-
delegate().start(wrappedListener, requestHeaders);
284-
drainQueue();
285-
}
286-
wrappedListener.unblockAfterStreamComplete();
287-
}
285+
handleFailOpen(wrappedListener);
288286
}
289287
});
290288

@@ -382,6 +380,19 @@ private void handleImmediateResponse(io.envoyproxy.envoy.service.ext_proc.v3.Imm
382380
listener.onClose(status, new Metadata());
383381
requestObserver.onCompleted();
384382
}
383+
384+
private void handleFailOpen(ExtProcListener<ReqT, RespT> listener) {
385+
if (extProcStreamCompleted.compareAndSet(false, true)) {
386+
// The ext_proc stream is gone. "Fail open" means we proceed with the RPC
387+
// without any more processing.
388+
if (!headersSent) {
389+
headersSent = true;
390+
delegate().start(listener, requestHeaders);
391+
drainQueue();
392+
}
393+
listener.unblockAfterStreamComplete();
394+
}
395+
}
385396
}
386397

387398
private static class ExtProcListener<ReqT, RespT> extends ForwardingClientCallListener.SimpleForwardingClientCallListener<RespT> {

0 commit comments

Comments
 (0)