Skip to content

Commit 7c9dcde

Browse files
committed
feat: Added deadline to gRPC Java client
Signed-off-by: Jose Acevedo <sharp.acevedo@gmail.com>
1 parent 2b398dc commit 7c9dcde

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

java/serving-client/src/main/java/dev/feast/FeastClient.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import feast.proto.serving.ServingServiceGrpc.ServingServiceBlockingStub;
2727
import feast.proto.types.ValueProto;
2828
import io.grpc.CallCredentials;
29+
import io.grpc.Deadline;
2930
import io.grpc.ManagedChannel;
3031
import io.grpc.ManagedChannelBuilder;
3132
import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
@@ -57,9 +58,9 @@ public class FeastClient implements AutoCloseable {
5758
* @param port port number of Feast serving GRPC server
5859
* @return {@link FeastClient}
5960
*/
60-
public static FeastClient create(String host, int port) {
61+
public static FeastClient create(String host, int port, Deadline deadline) {
6162
// configure client with no security config.
62-
return FeastClient.createSecure(host, port, SecurityConfig.newBuilder().build());
63+
return FeastClient.createSecure(host, port, SecurityConfig.newBuilder().build(), deadline);
6364
}
6465

6566
/**
@@ -71,7 +72,7 @@ public static FeastClient create(String host, int port) {
7172
* SecurityConfig} for options.
7273
* @return {@link FeastClient}
7374
*/
74-
public static FeastClient createSecure(String host, int port, SecurityConfig securityConfig) {
75+
public static FeastClient createSecure(String host, int port, SecurityConfig securityConfig, Deadline deadline) {
7576
// Configure client TLS
7677
ManagedChannel channel = null;
7778
if (securityConfig.isTLSEnabled()) {
@@ -98,7 +99,7 @@ public static FeastClient createSecure(String host, int port, SecurityConfig sec
9899
channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build();
99100
}
100101

101-
return new FeastClient(channel, securityConfig.getCredentials());
102+
return new FeastClient(channel, securityConfig.getCredentials(), deadline);
102103
}
103104

104105
/**
@@ -201,7 +202,7 @@ public List<Row> getOnlineFeatures(List<String> featureRefs, List<Row> rows, Str
201202
return getOnlineFeatures(featureRefs, rows);
202203
}
203204

204-
protected FeastClient(ManagedChannel channel, Optional<CallCredentials> credentials) {
205+
protected FeastClient(ManagedChannel channel, Optional<CallCredentials> credentials, Deadline deadline) {
205206
this.channel = channel;
206207
TracingClientInterceptor tracingInterceptor =
207208
TracingClientInterceptor.newBuilder().withTracer(GlobalTracer.get()).build();
@@ -213,6 +214,8 @@ protected FeastClient(ManagedChannel channel, Optional<CallCredentials> credenti
213214
servingStub = servingStub.withCallCredentials(credentials.get());
214215
}
215216

217+
servingStub = servingStub.withDeadline(deadline);
218+
216219
this.stub = servingStub;
217220
}
218221

java/serving-client/src/test/java/dev/feast/FeastClientTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.HashMap;
3939
import java.util.List;
4040
import java.util.Optional;
41+
import java.util.concurrent.TimeUnit;
4142
import java.util.concurrent.atomic.AtomicBoolean;
4243
import org.junit.Before;
4344
import org.junit.Rule;
@@ -86,7 +87,7 @@ public void setup() throws Exception {
8687
ManagedChannel channel =
8788
this.grpcRule.register(
8889
InProcessChannelBuilder.forName(serverName).directExecutor().build());
89-
this.client = new FeastClient(channel, Optional.empty());
90+
this.client = new FeastClient(channel, Optional.empty(), Deadline.after(200, TimeUnit.MILLISECONDS));
9091
}
9192

9293
@Test

0 commit comments

Comments
 (0)