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 b/hypertrace-core-graphql index 2b889a00..189b44f2 160000 --- a/hypertrace-core-graphql +++ b/hypertrace-core-graphql @@ -1 +1 @@ -Subproject commit 2b889a0071a28c481386eac7d6f506464c3bd2c4 +Subproject commit 189b44f21c042203cd41cfc4e3b3c850057d0918 diff --git a/hypertrace-graphql-service-config/src/main/java/org/hypertrace/graphql/config/HypertraceGraphQlServiceConfig.java b/hypertrace-graphql-service-config/src/main/java/org/hypertrace/graphql/config/HypertraceGraphQlServiceConfig.java index 119a8013..cda74c1b 100644 --- a/hypertrace-graphql-service-config/src/main/java/org/hypertrace/graphql/config/HypertraceGraphQlServiceConfig.java +++ b/hypertrace-graphql-service-config/src/main/java/org/hypertrace/graphql/config/HypertraceGraphQlServiceConfig.java @@ -1,5 +1,6 @@ package org.hypertrace.graphql.config; +import java.time.Duration; import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig; public interface HypertraceGraphQlServiceConfig extends GraphQlServiceConfig { @@ -7,7 +8,11 @@ public interface HypertraceGraphQlServiceConfig extends GraphQlServiceConfig { int getEntityServicePort(); + Duration getEntityServiceTimeout(); + String getConfigServiceHost(); int getConfigServicePort(); + + Duration getConfigServiceTimeout(); } diff --git a/hypertrace-graphql-service/src/main/java/org/hypertrace/graphql/service/DefaultGraphQlServiceConfig.java b/hypertrace-graphql-service/src/main/java/org/hypertrace/graphql/service/DefaultGraphQlServiceConfig.java index 23958887..0cb3fbbf 100644 --- a/hypertrace-graphql-service/src/main/java/org/hypertrace/graphql/service/DefaultGraphQlServiceConfig.java +++ b/hypertrace-graphql-service/src/main/java/org/hypertrace/graphql/service/DefaultGraphQlServiceConfig.java @@ -10,6 +10,8 @@ @Value class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig { + 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"; @@ -22,6 +24,7 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig { 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"; @@ -29,9 +32,11 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig { private static final String ENTITY_SERVICE_HOST_PROPERTY = "entity.service.host"; private static final String ENTITY_SERVICE_PORT_PROPERTY = "entity.service.port"; + private static final String ENTITY_SERVICE_CLIENT_TIMEOUT = "entity.service.timeout"; private static final String CONFIG_SERVICE_HOST_PROPERTY = "config.service.host"; private static final String CONFIG_SERVICE_PORT_PROPERTY = "config.service.port"; + private static final String CONFIG_SERVICE_CLIENT_TIMEOUT = "config.service.timeout"; String serviceName; int servicePort; @@ -41,13 +46,16 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig { int maxIoThreads; String attributeServiceHost; int attributeServicePort; + Duration attributeServiceTimeout; String gatewayServiceHost; int gatewayServicePort; Duration gatewayServiceTimeout; String entityServiceHost; int entityServicePort; + Duration entityServiceTimeout; String configServiceHost; int configServicePort; + Duration configServiceTimeout; DefaultGraphQlServiceConfig(Config untypedConfig) { this.serviceName = untypedConfig.getString(SERVICE_NAME_CONFIG); @@ -65,11 +73,24 @@ 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); + getSuppliedDurationOrFallback( + () -> untypedConfig.getDuration(GATEWAY_SERVICE_CLIENT_TIMEOUT)); + this.attributeServiceTimeout = + getSuppliedDurationOrFallback( + () -> untypedConfig.getDuration(ATTRIBUTE_SERVICE_CLIENT_TIMEOUT)); + this.configServiceTimeout = + getSuppliedDurationOrFallback( + () -> untypedConfig.getDuration(CONFIG_SERVICE_CLIENT_TIMEOUT)); + this.entityServiceTimeout = + getSuppliedDurationOrFallback( + () -> untypedConfig.getDuration(ENTITY_SERVICE_CLIENT_TIMEOUT)); + } + + private Duration getSuppliedDurationOrFallback(Supplier durationSupplier) { + return optionallyGet(durationSupplier) + .orElse(Duration.ofSeconds(DEFAULT_CLIENT_TIMEOUT_SECONDS)); } private Optional optionallyGet(Supplier valueSupplier) { diff --git a/hypertrace-graphql-spaces-schema/src/main/java/org/hypertrace/graphql/spaces/dao/ConfigServiceSpacesConfigDao.java b/hypertrace-graphql-spaces-schema/src/main/java/org/hypertrace/graphql/spaces/dao/ConfigServiceSpacesConfigDao.java index c676b394..11f28c33 100644 --- a/hypertrace-graphql-spaces-schema/src/main/java/org/hypertrace/graphql/spaces/dao/ConfigServiceSpacesConfigDao.java +++ b/hypertrace-graphql-spaces-schema/src/main/java/org/hypertrace/graphql/spaces/dao/ConfigServiceSpacesConfigDao.java @@ -1,9 +1,8 @@ package org.hypertrace.graphql.spaces.dao; -import static java.util.concurrent.TimeUnit.SECONDS; - import io.grpc.CallCredentials; import io.reactivex.rxjava3.core.Single; +import java.util.concurrent.TimeUnit; import javax.inject.Inject; import org.hypertrace.core.graphql.context.GraphQlRequestContext; import org.hypertrace.core.graphql.utils.grpc.GraphQlGrpcContextBuilder; @@ -19,11 +18,11 @@ class ConfigServiceSpacesConfigDao implements SpacesConfigDao { - private static final int DEFAULT_DEADLINE_SEC = 10; private final SpacesConfigServiceFutureStub spaceConfigServiceStub; private final GraphQlGrpcContextBuilder grpcContextBuilder; private final SpaceConfigRulesRequestConverter requestConverter; private final SpaceConfigRulesResponseConverter responseConverter; + private final HypertraceGraphQlServiceConfig serviceConfig; @Inject ConfigServiceSpacesConfigDao( @@ -36,6 +35,7 @@ class ConfigServiceSpacesConfigDao implements SpacesConfigDao { this.grpcContextBuilder = grpcContextBuilder; this.requestConverter = requestConverter; this.responseConverter = responseConverter; + this.serviceConfig = serviceConfig; this.spaceConfigServiceStub = SpacesConfigServiceGrpc.newFutureStub( @@ -52,7 +52,9 @@ public Single getAllRules(GraphQlRequestContext reques .callInContext( () -> this.spaceConfigServiceStub - .withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS) + .withDeadlineAfter( + serviceConfig.getConfigServiceTimeout().toMillis(), + TimeUnit.MILLISECONDS) .getRules(this.requestConverter.convertGetRequest()))) .flatMap(this.responseConverter::convertGetResponse); } @@ -65,7 +67,9 @@ public Single createRule(SpaceConfigRuleCreationRequest request .callInContext( () -> this.spaceConfigServiceStub - .withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS) + .withDeadlineAfter( + serviceConfig.getConfigServiceTimeout().toMillis(), + TimeUnit.MILLISECONDS) .createRule(this.requestConverter.convertCreationRequest(request)))) .flatMap(this.responseConverter::convertRule); } @@ -78,7 +82,9 @@ public Single updateRule(SpaceConfigRuleUpdateRequest request) .callInContext( () -> this.spaceConfigServiceStub - .withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS) + .withDeadlineAfter( + serviceConfig.getConfigServiceTimeout().toMillis(), + TimeUnit.MILLISECONDS) .updateRule(this.requestConverter.convertUpdateRequest(request)))) .flatMap(this.responseConverter::convertRule); } @@ -91,7 +97,9 @@ public Single deleteRule(SpaceConfigRuleDeleteRequest request) { .callInContext( () -> this.spaceConfigServiceStub - .withDeadlineAfter(DEFAULT_DEADLINE_SEC, SECONDS) + .withDeadlineAfter( + serviceConfig.getConfigServiceTimeout().toMillis(), + TimeUnit.MILLISECONDS) .deleteRule(this.requestConverter.convertDeleteRequest(request)))) .flatMap(unusedResponse -> this.responseConverter.buildDeleteResponse()); }