Skip to content

Gateway-Service Client Timeout Config #91

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

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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.hypertrace.graphql.entity.dao;

import static io.reactivex.rxjava3.core.Single.zip;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.hypertrace.core.graphql.common.utils.CollectorUtils.flatten;

import io.grpc.CallCredentials;
Expand Down Expand Up @@ -40,6 +40,7 @@ class GatewayBaselineDao implements BaselineDao {
private final Converter<Collection<MetricAggregationRequest>, Set<Expression>>
aggregationConverter;
private final Converter<Collection<MetricSeriesRequest>, Set<TimeAggregation>> seriesConverter;
private final GraphQlServiceConfig serviceConfig;

@Inject
GatewayBaselineDao(
Expand All @@ -57,6 +58,7 @@ class GatewayBaselineDao implements BaselineDao {
.withCallCredentials(credentials);
this.seriesConverter = seriesConverter;
this.aggregationConverter = aggregationConverter;
this.serviceConfig = serviceConfig;
}

@Override
Expand Down Expand Up @@ -127,7 +129,8 @@ private Single<BaselineEntitiesResponse> makeRequest(
.callInContext(
() ->
this.gatewayServiceStub
.withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS)
.withDeadlineAfter(
serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS)
.getBaselineForEntities(request)));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.hypertrace.graphql.entity.dao;

import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import io.grpc.CallCredentials;
import io.reactivex.rxjava3.core.Single;
Expand All @@ -20,12 +20,12 @@

@Singleton
class GatewayServiceEntityDao implements EntityDao {
private static final int DEFAULT_DEADLINE_SEC = 10;
private final GatewayServiceFutureStub gatewayServiceStub;
private final GraphQlGrpcContextBuilder grpcContextBuilder;
private final GatewayServiceEntityRequestBuilder requestBuilder;
private final GatewayServiceEntityConverter entityConverter;
private final BaselineDao baselineDao;
private final GraphQlServiceConfig serviceConfig;

@Inject
GatewayServiceEntityDao(
Expand All @@ -40,6 +40,7 @@ class GatewayServiceEntityDao implements EntityDao {
this.requestBuilder = requestBuilder;
this.entityConverter = entityConverter;
this.baselineDao = baselineDao;
this.serviceConfig = serviceConfig;

this.gatewayServiceStub =
GatewayServiceGrpc.newFutureStub(
Expand Down Expand Up @@ -77,7 +78,8 @@ private Single<EntitiesResponse> makeRequest(
.callInContext(
() ->
this.gatewayServiceStub
.withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS)
.withDeadlineAfter(
serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS)
.getEntities(request)));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.hypertrace.graphql.explorer.dao;

import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import io.grpc.CallCredentials;
import io.reactivex.rxjava3.core.Single;
Expand All @@ -18,11 +18,11 @@

@Singleton
class GatewayServiceExplorerDao implements ExplorerDao {
private static final int DEFAULT_DEADLINE_SEC = 10;
private final GatewayServiceFutureStub gatewayServiceStub;
private final GraphQlGrpcContextBuilder grpcContextBuilder;
private final GatewayServiceExploreRequestBuilder requestBuilder;
private final GatewayServiceExploreResponseConverter responseConverter;
private final GraphQlServiceConfig serviceConfig;

@Inject
GatewayServiceExplorerDao(
Expand All @@ -35,6 +35,7 @@ class GatewayServiceExplorerDao implements ExplorerDao {
this.grpcContextBuilder = grpcContextBuilder;
this.requestBuilder = requestBuilder;
this.responseConverter = responseConverter;
this.serviceConfig = serviceConfig;

this.gatewayServiceStub =
GatewayServiceGrpc.newFutureStub(
Expand All @@ -60,7 +61,8 @@ private Single<ExploreResponse> makeRequest(
.callInContext(
() ->
this.gatewayServiceStub
.withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS)
.withDeadlineAfter(
serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS)
.explore(request)));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hypertrace.graphql.service;

import com.typesafe.config.Config;
import java.time.Duration;
import java.util.Optional;
import java.util.function.Supplier;
import lombok.Value;
Expand All @@ -24,6 +25,7 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig {

private static final String GATEWAY_SERVICE_HOST_PROPERTY = "gateway.service.host";
private static final String GATEWAY_SERVICE_PORT_PROPERTY = "gateway.service.port";
private static final String GATEWAY_SERVICE_CLIENT_TIMEOUT = "gateway.service.timeout";

private static final String ENTITY_SERVICE_HOST_PROPERTY = "entity.service.host";
private static final String ENTITY_SERVICE_PORT_PROPERTY = "entity.service.port";
Expand All @@ -41,6 +43,7 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig {
int attributeServicePort;
String gatewayServiceHost;
int gatewayServicePort;
Duration gatewayServiceTimeout;
String entityServiceHost;
int entityServicePort;
String configServiceHost;
Expand All @@ -62,6 +65,11 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig {
this.entityServicePort = untypedConfig.getInt(ENTITY_SERVICE_PORT_PROPERTY);
this.configServiceHost = untypedConfig.getString(CONFIG_SERVICE_HOST_PROPERTY);
this.configServicePort = untypedConfig.getInt(CONFIG_SERVICE_PORT_PROPERTY);
// fallback timeout: 10s
this.gatewayServiceTimeout =
untypedConfig.hasPath(GATEWAY_SERVICE_CLIENT_TIMEOUT)
? untypedConfig.getDuration(GATEWAY_SERVICE_CLIENT_TIMEOUT)
: Duration.ofSeconds(10);
}

private <T> Optional<T> optionallyGet(Supplier<T> valueSupplier) {
Expand Down