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: RPC mode does not honor timeout #1230

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[submodule "providers/flagd/test-harness"]
path = providers/flagd/test-harness
url = https://github.com/open-feature/test-harness.git
branch = v2.2.0
branch = v2.5.0
[submodule "providers/flagd/spec"]
path = providers/flagd/spec
url = https://github.com/open-feature/spec.git
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class GrpcConnector<T extends AbstractStub<T>, K extends AbstractBlocking
/**
* The blocking service stub for making blocking GRPC calls.
*/
private final K blockingStub;
private final Function<ManagedChannel, K> blockingStubFunction;

/**
* The GRPC managed channel for managing the underlying GRPC connection.
Expand All @@ -59,6 +59,8 @@ public class GrpcConnector<T extends AbstractStub<T>, K extends AbstractBlocking
*/
private final Consumer<T> streamObserver;

private final FlagdOptions options;

/**
* Indicates whether the connector is currently connected to the GRPC service.
*/
Expand All @@ -85,11 +87,12 @@ public GrpcConnector(

this.channel = channel;
this.serviceStub = stub.apply(channel).withWaitForReady();
this.blockingStub = blockingStub.apply(channel).withWaitForReady();
this.blockingStubFunction = blockingStub;
this.deadline = options.getDeadline();
this.streamDeadlineMs = options.getStreamDeadlineMs();
this.onConnectionEvent = onConnectionEvent;
this.streamObserver = eventStreamObserver;
this.options = options;
}

/**
Expand Down Expand Up @@ -126,7 +129,7 @@ public void initialize() throws Exception {
* @return the blocking service stub
*/
public K getResolver() {
return blockingStub;
return blockingStubFunction.apply(channel).withWaitForReady();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.grpc.Status.Code;
import io.grpc.StatusRuntimeException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;

Expand All @@ -50,6 +51,7 @@ public final class GrpcResolver implements Resolver {
private final GrpcConnector<ServiceGrpc.ServiceStub, ServiceGrpc.ServiceBlockingStub> connector;
private final Cache cache;
private final ResolveStrategy strategy;
private final FlagdOptions options;

/**
* Resolves flag values using https://buf.build/open-feature/flagd/docs/main:flagd.evaluation.v1.
Expand All @@ -63,6 +65,7 @@ public GrpcResolver(
final FlagdOptions options, final Cache cache, final Consumer<FlagdProviderEvent> onProviderEvent) {
this.cache = cache;
this.strategy = ResolveFactory.getStrategy(options);
this.options = options;
this.connector = new GrpcConnector<>(
options,
ServiceGrpc::newStub,
Expand Down Expand Up @@ -108,15 +111,15 @@ public void onError() {
public ProviderEvaluation<Boolean> booleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) {
ResolveBooleanRequest request = ResolveBooleanRequest.newBuilder().buildPartial();

return resolve(key, ctx, request, connector.getResolver()::resolveBoolean, null);
return resolve(key, ctx, request, getResolver()::resolveBoolean, null);
}

/**
* String evaluation from grpc resolver.
*/
public ProviderEvaluation<String> stringEvaluation(String key, String defaultValue, EvaluationContext ctx) {
ResolveStringRequest request = ResolveStringRequest.newBuilder().buildPartial();
return resolve(key, ctx, request, connector.getResolver()::resolveString, null);
return resolve(key, ctx, request, getResolver()::resolveString, null);
}

/**
Expand All @@ -125,7 +128,7 @@ public ProviderEvaluation<String> stringEvaluation(String key, String defaultVal
public ProviderEvaluation<Double> doubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) {
ResolveFloatRequest request = ResolveFloatRequest.newBuilder().buildPartial();

return resolve(key, ctx, request, connector.getResolver()::resolveFloat, null);
return resolve(key, ctx, request, getResolver()::resolveFloat, null);
}

/**
Expand All @@ -135,8 +138,11 @@ public ProviderEvaluation<Integer> integerEvaluation(String key, Integer default

ResolveIntRequest request = ResolveIntRequest.newBuilder().buildPartial();

return resolve(
key, ctx, request, connector.getResolver()::resolveInt, (Object value) -> ((Long) value).intValue());
return resolve(key, ctx, request, getResolver()::resolveInt, (Object value) -> ((Long) value).intValue());
}

private ServiceGrpc.ServiceBlockingStub getResolver() {
return connector.getResolver().withDeadlineAfter(options.getDeadline(), TimeUnit.MILLISECONDS);
}

/**
Expand All @@ -150,7 +156,7 @@ public ProviderEvaluation<Value> objectEvaluation(String key, Value defaultValue
key,
ctx,
request,
connector.getResolver()::resolveObject,
getResolver()::resolveObject,
(Object value) -> convertObjectResponse((Struct) value));
}

Expand Down
2 changes: 1 addition & 1 deletion providers/flagd/test-harness