From 502e8c7c045ec7e494a5a11a168af7c760ce0c38 Mon Sep 17 00:00:00 2001 From: Prashant Pandey Date: Sun, 11 Jul 2021 11:58:10 +0530 Subject: [PATCH 1/5] Entity service and config service configurable timeouts --- .../HypertraceGraphQlServiceConfig.java | 5 +++ .../service/DefaultGraphQlServiceConfig.java | 32 ++++++++++++++++--- .../dao/ConfigServiceSpacesConfigDao.java | 22 +++++++++---- 3 files changed, 48 insertions(+), 11 deletions(-) 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..df90da7d 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_PORT_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,27 @@ 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_PORT_TIMEOUT)); + this.configServiceTimeout = + getSuppliedDurationOrFallback( + () -> untypedConfig.getDuration(CONFIG_SERVICE_CLIENT_TIMEOUT)); + this.entityServiceTimeout = + getSuppliedDurationOrFallback( + () -> untypedConfig.getDuration(ENTITY_SERVICE_CLIENT_TIMEOUT)); + } + + private Duration getSuppliedDurationOrFallback(Supplier durationSupplier) { + try { + return durationSupplier.get(); + } catch (Throwable unused) { + return 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()); } From f39ddd9086527b76b7f5704497cec155f9b8af47 Mon Sep 17 00:00:00 2001 From: Prashant Pandey Date: Mon, 12 Jul 2021 13:08:57 +0530 Subject: [PATCH 2/5] .synk update expiry date --- .snyk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: {} From 22284e6bd4e2d05755896caf0d353c73feb39392 Mon Sep 17 00:00:00 2001 From: Prashant Pandey Date: Mon, 12 Jul 2021 13:38:49 +0530 Subject: [PATCH 3/5] Fix typo --- .../graphql/service/DefaultGraphQlServiceConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 df90da7d..e4b71194 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 @@ -24,7 +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_PORT_TIMEOUT = "attribute.service.timeout"; + 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"; @@ -79,7 +79,7 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig { () -> untypedConfig.getDuration(GATEWAY_SERVICE_CLIENT_TIMEOUT)); this.attributeServiceTimeout = getSuppliedDurationOrFallback( - () -> untypedConfig.getDuration(ATTRIBUTE_SERVICE_PORT_TIMEOUT)); + () -> untypedConfig.getDuration(ATTRIBUTE_SERVICE_CLIENT_TIMEOUT)); this.configServiceTimeout = getSuppliedDurationOrFallback( () -> untypedConfig.getDuration(CONFIG_SERVICE_CLIENT_TIMEOUT)); From 86bbfe52d899cae0edd0a494c3e728dc09804182 Mon Sep 17 00:00:00 2001 From: Prashant Pandey Date: Mon, 12 Jul 2021 17:20:02 +0530 Subject: [PATCH 4/5] Reuse optionallyGet in the implementation of getTimeoutOrFallback --- .../graphql/service/DefaultGraphQlServiceConfig.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 e4b71194..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 @@ -89,11 +89,8 @@ class DefaultGraphQlServiceConfig implements HypertraceGraphQlServiceConfig { } private Duration getSuppliedDurationOrFallback(Supplier durationSupplier) { - try { - return durationSupplier.get(); - } catch (Throwable unused) { - return Duration.ofSeconds(DEFAULT_CLIENT_TIMEOUT_SECONDS); - } + return optionallyGet(durationSupplier) + .orElse(Duration.ofSeconds(DEFAULT_CLIENT_TIMEOUT_SECONDS)); } private Optional optionallyGet(Supplier valueSupplier) { From d009bf9ebf6a017b7179988961345cfc8ff6fae3 Mon Sep 17 00:00:00 2001 From: Prashant Pandey Date: Mon, 12 Jul 2021 19:31:28 +0530 Subject: [PATCH 5/5] chore: submodule ref update --- hypertrace-core-graphql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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