Skip to content

Commit ff429c9

Browse files
authored
feat: Added deadline to gRPC Java client (#4217)
Added deadline to gRPC Java Client Signed-off-by: Jose Acevedo <[email protected]>
1 parent 55566f0 commit ff429c9

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

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

Lines changed: 40 additions & 2 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;
@@ -63,7 +64,20 @@ public static FeastClient create(String host, int port) {
6364
}
6465

6566
/**
66-
* Create a authenticated client that can access Feast serving with authentication enabled.
67+
* Create a client to access Feast Serving.
68+
*
69+
* @param host hostname or ip address of Feast serving GRPC server
70+
* @param port port number of Feast serving GRPC server
71+
* @param deadline GRPC deadline of Feast serving GRPC server {@link Deadline}
72+
* @return {@link FeastClient}
73+
*/
74+
public static FeastClient create(String host, int port, Deadline deadline) {
75+
// configure client with no security config.
76+
return FeastClient.createSecure(host, port, SecurityConfig.newBuilder().build(), deadline);
77+
}
78+
79+
/**
80+
* Create an authenticated client that can access Feast serving with authentication enabled.
6781
*
6882
* @param host hostname or ip address of Feast serving GRPC server
6983
* @param port port number of Feast serving GRPC server
@@ -72,6 +86,21 @@ public static FeastClient create(String host, int port) {
7286
* @return {@link FeastClient}
7387
*/
7488
public static FeastClient createSecure(String host, int port, SecurityConfig securityConfig) {
89+
return createSecure(host, port, securityConfig, null);
90+
}
91+
92+
/**
93+
* Create an authenticated client that can access Feast serving with authentication enabled.
94+
*
95+
* @param host hostname or ip address of Feast serving GRPC server
96+
* @param port port number of Feast serving GRPC server
97+
* @param securityConfig security options to configure the Feast client. See {@link
98+
* SecurityConfig} for options.
99+
* @param deadline GRPC deadline of Feast serving GRPC server {@link Deadline}
100+
* @return {@link FeastClient}
101+
*/
102+
public static FeastClient createSecure(
103+
String host, int port, SecurityConfig securityConfig, Deadline deadline) {
75104
// Configure client TLS
76105
ManagedChannel channel = null;
77106
if (securityConfig.isTLSEnabled()) {
@@ -98,7 +127,7 @@ public static FeastClient createSecure(String host, int port, SecurityConfig sec
98127
channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build();
99128
}
100129

101-
return new FeastClient(channel, securityConfig.getCredentials());
130+
return new FeastClient(channel, securityConfig.getCredentials(), Optional.ofNullable(deadline));
102131
}
103132

104133
/**
@@ -202,6 +231,11 @@ public List<Row> getOnlineFeatures(List<String> featureRefs, List<Row> rows, Str
202231
}
203232

204233
protected FeastClient(ManagedChannel channel, Optional<CallCredentials> credentials) {
234+
this(channel, credentials, Optional.empty());
235+
}
236+
237+
protected FeastClient(
238+
ManagedChannel channel, Optional<CallCredentials> credentials, Optional<Deadline> deadline) {
205239
this.channel = channel;
206240
TracingClientInterceptor tracingInterceptor =
207241
TracingClientInterceptor.newBuilder().withTracer(GlobalTracer.get()).build();
@@ -213,6 +247,10 @@ protected FeastClient(ManagedChannel channel, Optional<CallCredentials> credenti
213247
servingStub = servingStub.withCallCredentials(credentials.get());
214248
}
215249

250+
if (deadline.isPresent()) {
251+
servingStub = servingStub.withDeadline(deadline.get());
252+
}
253+
216254
this.stub = servingStub;
217255
}
218256

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@
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;
4445
import org.junit.Test;
4546

4647
public class FeastClientTest {
4748
private final String AUTH_TOKEN = "test token";
49+
private final Deadline DEADLINE = Deadline.after(2, TimeUnit.SECONDS);
4850

4951
@Rule public GrpcCleanupRule grpcRule;
5052
private AtomicBoolean isAuthenticated;
@@ -86,7 +88,7 @@ public void setup() throws Exception {
8688
ManagedChannel channel =
8789
this.grpcRule.register(
8890
InProcessChannelBuilder.forName(serverName).directExecutor().build());
89-
this.client = new FeastClient(channel, Optional.empty());
91+
this.client = new FeastClient(channel, Optional.empty(), Optional.of(DEADLINE));
9092
}
9193

9294
@Test

0 commit comments

Comments
 (0)