diff --git a/.snyk b/.snyk index fbd83903..1ca9ad72 100644 --- a/.snyk +++ b/.snyk @@ -5,6 +5,6 @@ ignore: SNYK-JAVA-IONETTY-1042268: - '*': reason: No replacement available - expires: 2021-06-30T00:00:00.000Z + expires: 2021-09-01T00:00:00.000Z patch: {} diff --git a/hypertrace-core-graphql-attribute-store/src/main/java/org/hypertrace/core/graphql/attributes/AttributeClient.java b/hypertrace-core-graphql-attribute-store/src/main/java/org/hypertrace/core/graphql/attributes/AttributeClient.java index 80e53a8f..38eb061a 100644 --- a/hypertrace-core-graphql-attribute-store/src/main/java/org/hypertrace/core/graphql/attributes/AttributeClient.java +++ b/hypertrace-core-graphql-attribute-store/src/main/java/org/hypertrace/core/graphql/attributes/AttributeClient.java @@ -18,10 +18,11 @@ @Singleton class AttributeClient { - private static final int DEFAULT_DEADLINE_SEC = 10; + private final AttributeServiceStub attributeServiceClient; private final GrpcContextBuilder grpcContextBuilder; private final AttributeModelTranslator translator; + private final GraphQlServiceConfig serviceConfig; @Inject AttributeClient( @@ -32,6 +33,7 @@ class AttributeClient { AttributeModelTranslator translator) { this.grpcContextBuilder = grpcContextBuilder; this.translator = translator; + this.serviceConfig = serviceConfig; this.attributeServiceClient = newStub( @@ -46,7 +48,9 @@ public Observable queryAll(GraphQlRequestContext requestContext) .stream( streamObserver -> this.attributeServiceClient - .withDeadlineAfter(DEFAULT_DEADLINE_SEC, TimeUnit.SECONDS) + .withDeadlineAfter( + serviceConfig.getAttributeServiceTimeout().toMillis(), + TimeUnit.MILLISECONDS) .findAll(Empty.getDefaultInstance(), streamObserver)) .mapOptional(this.translator::translate); } 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 e3171a03..538bd4f5 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 @@ -8,6 +8,8 @@ class DefaultGraphQlServiceConfig implements GraphQlServiceConfig { + private static final Long DEFAULT_CLIENT_TIMEOUT_SECONDS = 10L; + private static final String SERVICE_NAME_CONFIG = "service.name"; private static final String SERVICE_PORT_CONFIG = "service.port"; @@ -20,6 +22,7 @@ class DefaultGraphQlServiceConfig implements GraphQlServiceConfig { private static final String ATTRIBUTE_SERVICE_HOST_PROPERTY = "attribute.service.host"; private static final String ATTRIBUTE_SERVICE_PORT_PROPERTY = "attribute.service.port"; + private static final String ATTRIBUTE_SERVICE_CLIENT_TIMEOUT = "attribute.service.timeout"; private static final String GATEWAY_SERVICE_HOST_PROPERTY = "gateway.service.host"; private static final String GATEWAY_SERVICE_PORT_PROPERTY = "gateway.service.port"; @@ -33,6 +36,7 @@ class DefaultGraphQlServiceConfig implements GraphQlServiceConfig { private final int maxIoThreads; private final String attributeServiceHost; private final int attributeServicePort; + private final Duration attributeServiceTimeout; private final String gatewayServiceHost; private final int gatewayServicePort; private final Duration gatewayServiceTimeout; @@ -47,13 +51,13 @@ class DefaultGraphQlServiceConfig implements GraphQlServiceConfig { this.attributeServiceHost = untypedConfig.getString(ATTRIBUTE_SERVICE_HOST_PROPERTY); this.attributeServicePort = untypedConfig.getInt(ATTRIBUTE_SERVICE_PORT_PROPERTY); + this.attributeServiceTimeout = + getTimeoutOrFallback(() -> untypedConfig.getDuration(ATTRIBUTE_SERVICE_CLIENT_TIMEOUT)); + 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); + getTimeoutOrFallback(() -> untypedConfig.getDuration(GATEWAY_SERVICE_CLIENT_TIMEOUT)); } @Override @@ -96,6 +100,11 @@ public int getAttributeServicePort() { return this.attributeServicePort; } + @Override + public Duration getAttributeServiceTimeout() { + return attributeServiceTimeout; + } + @Override public String getGatewayServiceHost() { return this.gatewayServiceHost; @@ -111,6 +120,11 @@ public Duration getGatewayServiceTimeout() { return gatewayServiceTimeout; } + private Duration getTimeoutOrFallback(Supplier durationSupplier) { + return optionallyGet(durationSupplier) + .orElse(Duration.ofSeconds(DEFAULT_CLIENT_TIMEOUT_SECONDS)); + } + private Optional optionallyGet(Supplier valueSupplier) { try { return Optional.ofNullable(valueSupplier.get()); 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 310666f7..f38a7aa3 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 @@ -21,6 +21,8 @@ public interface GraphQlServiceConfig { int getAttributeServicePort(); + Duration getAttributeServiceTimeout(); + String getGatewayServiceHost(); int getGatewayServicePort();