diff --git a/helm/templates/config-service-config.yaml b/helm/templates/config-service-config.yaml index 1f7d8d2f..ba76b5eb 100644 --- a/helm/templates/config-service-config.yaml +++ b/helm/templates/config-service-config.yaml @@ -22,7 +22,6 @@ data: } } publish.change.events = {{ .Values.configServiceConfig.publishChangeEvents }} - max.dynamic.label.application.rules.per.tenant = {{ .Values.configServiceConfig.maxDynamicLabelApplicationRulesPerTenant }} } event.store { type = kafka diff --git a/helm/values.yaml b/helm/values.yaml index 7d309646..fd41d39d 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -83,7 +83,6 @@ configServiceConfig: mongo: host: mongo url: "" - maxDynamicLabelApplicationRulesPerTenant: 100 logConfig: name: config-service-log-config diff --git a/label-application-rule-config-service-impl/src/main/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleConfigServiceImpl.java b/label-application-rule-config-service-impl/src/main/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleConfigServiceImpl.java index f2290790..321bf4b3 100644 --- a/label-application-rule-config-service-impl/src/main/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleConfigServiceImpl.java +++ b/label-application-rule-config-service-impl/src/main/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleConfigServiceImpl.java @@ -27,19 +27,28 @@ public class LabelApplicationRuleConfigServiceImpl extends LabelApplicationRuleConfigServiceGrpc.LabelApplicationRuleConfigServiceImplBase { - private static final String MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT = + static final String LABEL_APPLICATION_RULE_CONFIG_SERVICE_CONFIG = + "label.application.rule.config.service"; + static final String MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT = "max.dynamic.label.application.rules.per.tenant"; - private static final int MAX_DYNAMIC_LABEL_APPLICATION_RULE_CONSTANT = 100; + static final int DEFAULT_MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT = 100; private final IdentifiedObjectStore labelApplicationRuleStore; private final LabelApplicationRuleValidator requestValidator; private final int maxDynamicLabelApplicationRulesAllowed; public LabelApplicationRuleConfigServiceImpl( Channel configChannel, Config config, ConfigChangeEventGenerator configChangeEventGenerator) { - this.maxDynamicLabelApplicationRulesAllowed = - config.hasPath(MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT) - ? config.getInt(MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT) - : MAX_DYNAMIC_LABEL_APPLICATION_RULE_CONSTANT; + int maxDynamicRules = DEFAULT_MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT; + if (config.hasPath(LABEL_APPLICATION_RULE_CONFIG_SERVICE_CONFIG)) { + Config labelApplicationRuleConfig = + config.getConfig(LABEL_APPLICATION_RULE_CONFIG_SERVICE_CONFIG); + if (labelApplicationRuleConfig.hasPath(MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT)) { + maxDynamicRules = + labelApplicationRuleConfig.getInt(MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT); + } + } + this.maxDynamicLabelApplicationRulesAllowed = maxDynamicRules; + ConfigServiceBlockingStub configServiceBlockingStub = ConfigServiceGrpc.newBlockingStub(configChannel) .withCallCredentials( diff --git a/label-application-rule-config-service-impl/src/test/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleConfigServiceImplTest.java b/label-application-rule-config-service-impl/src/test/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleConfigServiceImplTest.java index a2972bf8..d3e8dac7 100644 --- a/label-application-rule-config-service-impl/src/test/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleConfigServiceImplTest.java +++ b/label-application-rule-config-service-impl/src/test/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleConfigServiceImplTest.java @@ -1,12 +1,14 @@ package org.hypertrace.label.application.rule.config.service; +import static org.hypertrace.label.application.rule.config.service.LabelApplicationRuleConfigServiceImpl.LABEL_APPLICATION_RULE_CONFIG_SERVICE_CONFIG; +import static org.hypertrace.label.application.rule.config.service.LabelApplicationRuleConfigServiceImpl.MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; import io.grpc.Channel; import io.grpc.Status; import io.grpc.StatusRuntimeException; @@ -42,8 +44,6 @@ import org.junit.jupiter.api.Test; public class LabelApplicationRuleConfigServiceImplTest { - private static final String MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT = - "max.dynamic.label.application.rules.per.tenant"; MockGenericConfigService mockGenericConfigService; LabelApplicationRuleConfigServiceBlockingStub labelApplicationRuleConfigServiceBlockingStub; @@ -53,13 +53,14 @@ void setUp() { new MockGenericConfigService().mockUpsert().mockGet().mockGetAll().mockDelete(); Channel channel = mockGenericConfigService.channel(); ConfigChangeEventGenerator configChangeEventGenerator = mock(ConfigChangeEventGenerator.class); - Config mockConfig = mock(Config.class); - when(mockConfig.hasPath(MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT)).thenReturn(true); - when(mockConfig.getInt(MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT)).thenReturn(2); + Config config = + ConfigFactory.parseMap( + Map.of( + LABEL_APPLICATION_RULE_CONFIG_SERVICE_CONFIG, + Map.of(MAX_DYNAMIC_LABEL_APPLICATION_RULES_PER_TENANT, 2))); mockGenericConfigService .addService( - new LabelApplicationRuleConfigServiceImpl( - channel, mockConfig, configChangeEventGenerator)) + new LabelApplicationRuleConfigServiceImpl(channel, config, configChangeEventGenerator)) .start(); labelApplicationRuleConfigServiceBlockingStub = LabelApplicationRuleConfigServiceGrpc.newBlockingStub(channel); @@ -99,11 +100,9 @@ void createLabelApplicationRuleWithDynamicLabelApplicationRulesLimitReached() { assertEquals(simpleRuleData2, response2.getLabelApplicationRule().getData()); CreateLabelApplicationRuleRequest request3 = CreateLabelApplicationRuleRequest.newBuilder().setData(simpleRuleData3).build(); - Exception exception = - assertThrows( - RuntimeException.class, - () -> - labelApplicationRuleConfigServiceBlockingStub.createLabelApplicationRule(request3)); + assertThrows( + RuntimeException.class, + () -> labelApplicationRuleConfigServiceBlockingStub.createLabelApplicationRule(request3)); } @Test