Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion helm/templates/config-service-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ configServiceConfig:
mongo:
host: mongo
url: ""
maxDynamicLabelApplicationRulesPerTenant: 100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now where is this defined in configmap then ?


logConfig:
name: config-service-log-config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LabelApplicationRule> 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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down