diff --git a/hypertrace-core-graphql-log-event-schema/src/main/java/org/hypertrace/core/graphql/log/event/dao/GatewayServiceLogEventDao.java b/hypertrace-core-graphql-log-event-schema/src/main/java/org/hypertrace/core/graphql/log/event/dao/GatewayServiceLogEventDao.java index 6d43f005..68bd5642 100644 --- a/hypertrace-core-graphql-log-event-schema/src/main/java/org/hypertrace/core/graphql/log/event/dao/GatewayServiceLogEventDao.java +++ b/hypertrace-core-graphql-log-event-schema/src/main/java/org/hypertrace/core/graphql/log/event/dao/GatewayServiceLogEventDao.java @@ -1,6 +1,6 @@ package org.hypertrace.core.graphql.log.event.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; @@ -19,11 +19,11 @@ @Singleton class GatewayServiceLogEventDao implements LogEventDao { - private static final int DEFAULT_DEADLINE_SEC = 10; private final GatewayServiceFutureStub gatewayServiceStub; private final GrpcContextBuilder grpcContextBuilder; private final GatewayServiceLogEventsRequestBuilder requestBuilder; private final GatewayServiceLogEventsResponseConverter logEventConverter; + private final GraphQlServiceConfig serviceConfig; @Inject GatewayServiceLogEventDao( @@ -36,6 +36,7 @@ class GatewayServiceLogEventDao implements LogEventDao { this.grpcContextBuilder = grpcContextBuilder; this.requestBuilder = requestBuilder; this.logEventConverter = logEventConverter; + this.serviceConfig = serviceConfig; this.gatewayServiceStub = GatewayServiceGrpc.newFutureStub( @@ -60,7 +61,8 @@ private Single makeRequest( .call( () -> this.gatewayServiceStub - .withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS) + .withDeadlineAfter( + serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS) .getLogEvents(request))); } } diff --git a/hypertrace-core-graphql-service/src/main/java/org/hypertrace/core/graphql/service/DefaultGraphQlServiceConfig.java b/hypertrace-core-graphql-service/src/main/java/org/hypertrace/core/graphql/service/DefaultGraphQlServiceConfig.java index dcdbc398..e3171a03 100644 --- a/hypertrace-core-graphql-service/src/main/java/org/hypertrace/core/graphql/service/DefaultGraphQlServiceConfig.java +++ b/hypertrace-core-graphql-service/src/main/java/org/hypertrace/core/graphql/service/DefaultGraphQlServiceConfig.java @@ -1,6 +1,7 @@ package org.hypertrace.core.graphql.service; import com.typesafe.config.Config; +import java.time.Duration; import java.util.Optional; import java.util.function.Supplier; import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig; @@ -22,6 +23,7 @@ class DefaultGraphQlServiceConfig implements GraphQlServiceConfig { 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 final String serviceName; private final int servicePort; @@ -33,6 +35,7 @@ class DefaultGraphQlServiceConfig implements GraphQlServiceConfig { private final int attributeServicePort; private final String gatewayServiceHost; private final int gatewayServicePort; + private final Duration gatewayServiceTimeout; DefaultGraphQlServiceConfig(Config untypedConfig) { this.serviceName = untypedConfig.getString(SERVICE_NAME_CONFIG); @@ -46,6 +49,11 @@ class DefaultGraphQlServiceConfig implements GraphQlServiceConfig { this.attributeServicePort = untypedConfig.getInt(ATTRIBUTE_SERVICE_PORT_PROPERTY); this.gatewayServiceHost = untypedConfig.getString(GATEWAY_SERVICE_HOST_PROPERTY); this.gatewayServicePort = untypedConfig.getInt(GATEWAY_SERVICE_PORT_PROPERTY); + // fallback timeout: 10s + this.gatewayServiceTimeout = + untypedConfig.hasPath(GATEWAY_SERVICE_CLIENT_TIMEOUT) + ? untypedConfig.getDuration(GATEWAY_SERVICE_CLIENT_TIMEOUT) + : Duration.ofSeconds(10); } @Override @@ -98,6 +106,11 @@ public int getGatewayServicePort() { return this.gatewayServicePort; } + @Override + public Duration getGatewayServiceTimeout() { + return gatewayServiceTimeout; + } + private Optional optionallyGet(Supplier valueSupplier) { try { return Optional.ofNullable(valueSupplier.get()); diff --git a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/GatewayServiceSpanDao.java b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/GatewayServiceSpanDao.java index ca9d4444..67a5f9d9 100644 --- a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/GatewayServiceSpanDao.java +++ b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/GatewayServiceSpanDao.java @@ -1,6 +1,6 @@ package org.hypertrace.core.graphql.span.dao; -import static java.util.concurrent.TimeUnit.SECONDS; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import io.reactivex.rxjava3.core.Single; import javax.inject.Inject; @@ -8,6 +8,7 @@ import org.hypertrace.core.graphql.context.GraphQlRequestContext; import org.hypertrace.core.graphql.span.request.SpanRequest; import org.hypertrace.core.graphql.span.schema.SpanResultSet; +import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig; import org.hypertrace.core.graphql.utils.grpc.GrpcContextBuilder; import org.hypertrace.gateway.service.GatewayServiceGrpc.GatewayServiceFutureStub; import org.hypertrace.gateway.service.v1.span.SpansRequest; @@ -15,15 +16,17 @@ @Singleton class GatewayServiceSpanDao implements SpanDao { - private static final int DEFAULT_DEADLINE_SEC = 10; + private final GatewayServiceFutureStub gatewayServiceStub; private final GrpcContextBuilder grpcContextBuilder; private final GatewayServiceSpanRequestBuilder requestBuilder; private final GatewayServiceSpanConverter spanConverter; private final SpanLogEventDao spanLogEventDao; + private final GraphQlServiceConfig serviceConfig; @Inject GatewayServiceSpanDao( + GraphQlServiceConfig serviceConfig, GatewayServiceFutureStub gatewayServiceFutureStub, GrpcContextBuilder grpcContextBuilder, GatewayServiceSpanRequestBuilder requestBuilder, @@ -34,6 +37,7 @@ class GatewayServiceSpanDao implements SpanDao { this.spanConverter = spanConverter; this.spanLogEventDao = spanLogEventDao; this.gatewayServiceStub = gatewayServiceFutureStub; + this.serviceConfig = serviceConfig; } @Override @@ -54,7 +58,8 @@ private Single makeRequest(GraphQlRequestContext context, SpansRe .call( () -> this.gatewayServiceStub - .withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS) + .withDeadlineAfter( + serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS) .getSpans(request))); } } diff --git a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/SpanDaoModule.java b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/SpanDaoModule.java index 77b03d12..36aff948 100644 --- a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/SpanDaoModule.java +++ b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/SpanDaoModule.java @@ -32,6 +32,7 @@ public class SpanDaoModule extends AbstractModule { protected void configure() { bind(SpanDao.class).to(GatewayServiceSpanDao.class); requireBinding(GatewayServiceFutureStub.class); + requireBinding(GraphQlServiceConfig.class); requireBinding(CallCredentials.class); requireBinding(GraphQlServiceConfig.class); requireBinding(GrpcContextBuilder.class); diff --git a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/SpanLogEventDao.java b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/SpanLogEventDao.java index 88ecac95..f714ddec 100644 --- a/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/SpanLogEventDao.java +++ b/hypertrace-core-graphql-span-schema/src/main/java/org/hypertrace/core/graphql/span/dao/SpanLogEventDao.java @@ -1,12 +1,13 @@ package org.hypertrace.core.graphql.span.dao; -import static java.util.concurrent.TimeUnit.SECONDS; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import io.reactivex.rxjava3.core.Single; import java.util.Map; import javax.inject.Inject; import org.hypertrace.core.graphql.context.GraphQlRequestContext; import org.hypertrace.core.graphql.span.request.SpanRequest; +import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig; import org.hypertrace.core.graphql.utils.grpc.GrpcContextBuilder; import org.hypertrace.gateway.service.GatewayServiceGrpc.GatewayServiceFutureStub; import org.hypertrace.gateway.service.v1.log.events.LogEventsRequest; @@ -15,15 +16,15 @@ class SpanLogEventDao { - private static final int DEFAULT_DEADLINE_SEC = 10; - private final GatewayServiceFutureStub gatewayServiceStub; private final GrpcContextBuilder grpcContextBuilder; private final SpanLogEventRequestBuilder spanLogEventRequestBuilder; private final SpanLogEventResponseConverter spanLogEventResponseConverter; + private final GraphQlServiceConfig serviceConfig; @Inject SpanLogEventDao( + GraphQlServiceConfig serviceConfig, GatewayServiceFutureStub gatewayServiceFutureStub, GrpcContextBuilder grpcContextBuilder, SpanLogEventRequestBuilder spanLogEventRequestBuilder, @@ -32,6 +33,7 @@ class SpanLogEventDao { this.grpcContextBuilder = grpcContextBuilder; this.spanLogEventRequestBuilder = spanLogEventRequestBuilder; this.spanLogEventResponseConverter = spanLogEventResponseConverter; + this.serviceConfig = serviceConfig; } /** @@ -73,7 +75,8 @@ private Single makeRequest( .call( () -> this.gatewayServiceStub - .withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS) + .withDeadlineAfter( + serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS) .getLogEvents(request))); } } diff --git a/hypertrace-core-graphql-spi/src/main/java/org/hypertrace/core/graphql/spi/config/GraphQlServiceConfig.java b/hypertrace-core-graphql-spi/src/main/java/org/hypertrace/core/graphql/spi/config/GraphQlServiceConfig.java index 26bace29..310666f7 100644 --- a/hypertrace-core-graphql-spi/src/main/java/org/hypertrace/core/graphql/spi/config/GraphQlServiceConfig.java +++ b/hypertrace-core-graphql-spi/src/main/java/org/hypertrace/core/graphql/spi/config/GraphQlServiceConfig.java @@ -1,5 +1,6 @@ package org.hypertrace.core.graphql.spi.config; +import java.time.Duration; import java.util.Optional; public interface GraphQlServiceConfig { @@ -23,4 +24,6 @@ public interface GraphQlServiceConfig { String getGatewayServiceHost(); int getGatewayServicePort(); + + Duration getGatewayServiceTimeout(); } diff --git a/hypertrace-core-graphql-trace-schema/src/main/java/org/hypertrace/core/graphql/trace/dao/GatewayServiceTraceDao.java b/hypertrace-core-graphql-trace-schema/src/main/java/org/hypertrace/core/graphql/trace/dao/GatewayServiceTraceDao.java index e28031e5..e1f55c62 100644 --- a/hypertrace-core-graphql-trace-schema/src/main/java/org/hypertrace/core/graphql/trace/dao/GatewayServiceTraceDao.java +++ b/hypertrace-core-graphql-trace-schema/src/main/java/org/hypertrace/core/graphql/trace/dao/GatewayServiceTraceDao.java @@ -1,6 +1,6 @@ package org.hypertrace.core.graphql.trace.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; @@ -19,11 +19,12 @@ @Singleton class GatewayServiceTraceDao implements TraceDao { - private static final int DEFAULT_DEADLINE_SEC = 10; + private final GatewayServiceFutureStub gatewayServiceStub; private final GrpcContextBuilder grpcContextBuilder; private final GatewayServiceTraceRequestBuilder requestBuilder; private final GatewayServiceTraceConverter traceConverter; + private final GraphQlServiceConfig serviceConfig; @Inject GatewayServiceTraceDao( @@ -36,6 +37,7 @@ class GatewayServiceTraceDao implements TraceDao { this.grpcContextBuilder = grpcContextBuilder; this.requestBuilder = requestBuilder; this.traceConverter = traceConverter; + this.serviceConfig = serviceConfig; this.gatewayServiceStub = GatewayServiceGrpc.newFutureStub( @@ -61,7 +63,8 @@ private Single makeRequest(GraphQlRequestContext context, Traces .call( () -> this.gatewayServiceStub - .withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS) + .withDeadlineAfter( + serviceConfig.getGatewayServiceTimeout().toMillis(), MILLISECONDS) .getTraces(request))); } }