Skip to content

Commit 2cdb158

Browse files
authored
Gateway-Service Client Timeout Config (#91)
* Added config for gateway gRPC client deadline * Added config for gateway gRPC client deadline * Spotless apply * Changed gateway-service client timeout unit to java.time.Duration and added fallback configuration * Changed gateway-service client timeout unit to java.time.Duration and added fallback configuration * Update submodule ref: hypertrace-core-graphql
1 parent cef8ab9 commit 2cdb158

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayBaselineDao.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.hypertrace.graphql.entity.dao;
22

33
import static io.reactivex.rxjava3.core.Single.zip;
4-
import static java.util.concurrent.TimeUnit.SECONDS;
4+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
55
import static org.hypertrace.core.graphql.common.utils.CollectorUtils.flatten;
66

77
import io.grpc.CallCredentials;
@@ -40,6 +40,7 @@ class GatewayBaselineDao implements BaselineDao {
4040
private final Converter<Collection<MetricAggregationRequest>, Set<Expression>>
4141
aggregationConverter;
4242
private final Converter<Collection<MetricSeriesRequest>, Set<TimeAggregation>> seriesConverter;
43+
private final GraphQlServiceConfig serviceConfig;
4344

4445
@Inject
4546
GatewayBaselineDao(
@@ -57,6 +58,7 @@ class GatewayBaselineDao implements BaselineDao {
5758
.withCallCredentials(credentials);
5859
this.seriesConverter = seriesConverter;
5960
this.aggregationConverter = aggregationConverter;
61+
this.serviceConfig = serviceConfig;
6062
}
6163

6264
@Override
@@ -127,7 +129,8 @@ private Single<BaselineEntitiesResponse> makeRequest(
127129
.callInContext(
128130
() ->
129131
this.gatewayServiceStub
130-
.withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS)
132+
.withDeadlineAfter(
133+
serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS)
131134
.getBaselineForEntities(request)));
132135
}
133136
}

hypertrace-graphql-entity-schema/src/main/java/org/hypertrace/graphql/entity/dao/GatewayServiceEntityDao.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.hypertrace.graphql.entity.dao;
22

3-
import static java.util.concurrent.TimeUnit.SECONDS;
3+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
44

55
import io.grpc.CallCredentials;
66
import io.reactivex.rxjava3.core.Single;
@@ -20,12 +20,12 @@
2020

2121
@Singleton
2222
class GatewayServiceEntityDao implements EntityDao {
23-
private static final int DEFAULT_DEADLINE_SEC = 10;
2423
private final GatewayServiceFutureStub gatewayServiceStub;
2524
private final GraphQlGrpcContextBuilder grpcContextBuilder;
2625
private final GatewayServiceEntityRequestBuilder requestBuilder;
2726
private final GatewayServiceEntityConverter entityConverter;
2827
private final BaselineDao baselineDao;
28+
private final GraphQlServiceConfig serviceConfig;
2929

3030
@Inject
3131
GatewayServiceEntityDao(
@@ -40,6 +40,7 @@ class GatewayServiceEntityDao implements EntityDao {
4040
this.requestBuilder = requestBuilder;
4141
this.entityConverter = entityConverter;
4242
this.baselineDao = baselineDao;
43+
this.serviceConfig = serviceConfig;
4344

4445
this.gatewayServiceStub =
4546
GatewayServiceGrpc.newFutureStub(
@@ -77,7 +78,8 @@ private Single<EntitiesResponse> makeRequest(
7778
.callInContext(
7879
() ->
7980
this.gatewayServiceStub
80-
.withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS)
81+
.withDeadlineAfter(
82+
serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS)
8183
.getEntities(request)));
8284
}
8385
}

hypertrace-graphql-explorer-schema/src/main/java/org/hypertrace/graphql/explorer/dao/GatewayServiceExplorerDao.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.hypertrace.graphql.explorer.dao;
22

3-
import static java.util.concurrent.TimeUnit.SECONDS;
3+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
44

55
import io.grpc.CallCredentials;
66
import io.reactivex.rxjava3.core.Single;
@@ -18,11 +18,11 @@
1818

1919
@Singleton
2020
class GatewayServiceExplorerDao implements ExplorerDao {
21-
private static final int DEFAULT_DEADLINE_SEC = 10;
2221
private final GatewayServiceFutureStub gatewayServiceStub;
2322
private final GraphQlGrpcContextBuilder grpcContextBuilder;
2423
private final GatewayServiceExploreRequestBuilder requestBuilder;
2524
private final GatewayServiceExploreResponseConverter responseConverter;
25+
private final GraphQlServiceConfig serviceConfig;
2626

2727
@Inject
2828
GatewayServiceExplorerDao(
@@ -35,6 +35,7 @@ class GatewayServiceExplorerDao implements ExplorerDao {
3535
this.grpcContextBuilder = grpcContextBuilder;
3636
this.requestBuilder = requestBuilder;
3737
this.responseConverter = responseConverter;
38+
this.serviceConfig = serviceConfig;
3839

3940
this.gatewayServiceStub =
4041
GatewayServiceGrpc.newFutureStub(
@@ -60,7 +61,8 @@ private Single<ExploreResponse> makeRequest(
6061
.callInContext(
6162
() ->
6263
this.gatewayServiceStub
63-
.withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS)
64+
.withDeadlineAfter(
65+
serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS)
6466
.explore(request)));
6567
}
6668
}

hypertrace-graphql-service/src/main/java/org/hypertrace/graphql/service/DefaultGraphQlServiceConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hypertrace.graphql.service;
22

33
import com.typesafe.config.Config;
4+
import java.time.Duration;
45
import java.util.Optional;
56
import java.util.function.Supplier;
67
import lombok.Value;
@@ -24,6 +25,7 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig {
2425

2526
private static final String GATEWAY_SERVICE_HOST_PROPERTY = "gateway.service.host";
2627
private static final String GATEWAY_SERVICE_PORT_PROPERTY = "gateway.service.port";
28+
private static final String GATEWAY_SERVICE_CLIENT_TIMEOUT = "gateway.service.timeout";
2729

2830
private static final String ENTITY_SERVICE_HOST_PROPERTY = "entity.service.host";
2931
private static final String ENTITY_SERVICE_PORT_PROPERTY = "entity.service.port";
@@ -41,6 +43,7 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig {
4143
int attributeServicePort;
4244
String gatewayServiceHost;
4345
int gatewayServicePort;
46+
Duration gatewayServiceTimeout;
4447
String entityServiceHost;
4548
int entityServicePort;
4649
String configServiceHost;
@@ -62,6 +65,11 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig {
6265
this.entityServicePort = untypedConfig.getInt(ENTITY_SERVICE_PORT_PROPERTY);
6366
this.configServiceHost = untypedConfig.getString(CONFIG_SERVICE_HOST_PROPERTY);
6467
this.configServicePort = untypedConfig.getInt(CONFIG_SERVICE_PORT_PROPERTY);
68+
// fallback timeout: 10s
69+
this.gatewayServiceTimeout =
70+
untypedConfig.hasPath(GATEWAY_SERVICE_CLIENT_TIMEOUT)
71+
? untypedConfig.getDuration(GATEWAY_SERVICE_CLIENT_TIMEOUT)
72+
: Duration.ofSeconds(10);
6573
}
6674

6775
private <T> Optional<T> optionallyGet(Supplier<T> valueSupplier) {

0 commit comments

Comments
 (0)