diff --git a/notification-rule-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_rule_config_service.proto b/notification-rule-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_rule_config_service.proto index ec01c9b4..df2e54ea 100644 --- a/notification-rule-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_rule_config_service.proto +++ b/notification-rule-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_rule_config_service.proto @@ -31,7 +31,13 @@ message UpdateNotificationRuleResponse { NotificationRule notification_rule = 1; } -message GetAllNotificationRulesRequest {} +message GetAllNotificationRulesRequest { + NotificationRuleFilter filter = 3; +} + +message NotificationRuleFilter { + repeated string event_condition_type = 1; +} message GetAllNotificationRulesResponse { repeated NotificationRule notification_rules = 1; diff --git a/notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImpl.java b/notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImpl.java index abcd6001..ff55d6c3 100644 --- a/notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImpl.java +++ b/notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImpl.java @@ -27,12 +27,13 @@ public class NotificationRuleConfigServiceImpl extends NotificationRuleConfigServiceGrpc.NotificationRuleConfigServiceImplBase { - private final NotificationRuleStore notificationRuleStore; + private final NotificationRuleFilteredStore notificationRuleStore; private final NotificationRuleConfigServiceRequestValidator validator; public NotificationRuleConfigServiceImpl( Channel channel, ConfigChangeEventGenerator configChangeEventGenerator) { - this.notificationRuleStore = new NotificationRuleStore(channel, configChangeEventGenerator); + this.notificationRuleStore = + new NotificationRuleFilteredStore(channel, configChangeEventGenerator); this.validator = new NotificationRuleConfigServiceRequestValidator(); } @@ -105,7 +106,7 @@ public void getAllNotificationRules( responseObserver.onNext( GetAllNotificationRulesResponse.newBuilder() .addAllNotificationRules( - notificationRuleStore.getAllObjects(requestContext).stream() + notificationRuleStore.getAllObjects(requestContext, request.getFilter()).stream() .map(ConfigObject::getData) .collect(Collectors.toUnmodifiableList())) .build()); diff --git a/notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleStore.java b/notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleFilteredStore.java similarity index 68% rename from notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleStore.java rename to notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleFilteredStore.java index 566eae12..d7c87067 100644 --- a/notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleStore.java +++ b/notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleFilteredStore.java @@ -6,20 +6,22 @@ import java.util.Optional; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.hypertrace.config.objectstore.IdentifiedObjectStore; +import org.hypertrace.config.objectstore.IdentifiedObjectStoreWithFilter; import org.hypertrace.config.proto.converter.ConfigProtoConverter; import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator; import org.hypertrace.config.service.v1.ConfigServiceGrpc; import org.hypertrace.core.grpcutils.client.RequestContextClientCallCredsProviderFactory; import org.hypertrace.notification.config.service.v1.NotificationRule; +import org.hypertrace.notification.config.service.v1.NotificationRuleFilter; @Slf4j -public class NotificationRuleStore extends IdentifiedObjectStore { +public class NotificationRuleFilteredStore + extends IdentifiedObjectStoreWithFilter { private static final String NOTIFICATION_CONFIG_NAMESPACE = "notification-v1"; private static final String NOTIFICATION_RULE_CONFIG_RESOURCE_NAME = "notificationRuleConfig"; - public NotificationRuleStore( + public NotificationRuleFilteredStore( Channel channel, ConfigChangeEventGenerator configChangeEventGenerator) { super( ConfigServiceGrpc.newBlockingStub(channel) @@ -52,4 +54,19 @@ protected Value buildValueFromData(NotificationRule object) { protected String getContextFromData(NotificationRule object) { return object.getId(); } + + @Override + protected Optional filterConfigData( + NotificationRule data, NotificationRuleFilter filter) { + return Optional.of(data) + .filter( + notificationRule -> + filter.getEventConditionTypeList().isEmpty() + || filter + .getEventConditionTypeList() + .contains( + notificationRule + .getNotificationRuleMutableData() + .getEventConditionType())); + } } diff --git a/notification-rule-config-service-impl/src/test/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImplTest.java b/notification-rule-config-service-impl/src/test/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImplTest.java index 7302d778..c6d8352c 100644 --- a/notification-rule-config-service-impl/src/test/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImplTest.java +++ b/notification-rule-config-service-impl/src/test/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImplTest.java @@ -14,6 +14,7 @@ import org.hypertrace.notification.config.service.v1.GetNotificationRuleRequest; import org.hypertrace.notification.config.service.v1.NotificationRule; import org.hypertrace.notification.config.service.v1.NotificationRuleConfigServiceGrpc; +import org.hypertrace.notification.config.service.v1.NotificationRuleFilter; import org.hypertrace.notification.config.service.v1.NotificationRuleMutableData; import org.hypertrace.notification.config.service.v1.UpdateNotificationRuleRequest; import org.junit.jupiter.api.BeforeEach; @@ -23,13 +24,13 @@ class NotificationRuleConfigServiceImplTest { MockGenericConfigService mockGenericConfigService; NotificationRuleConfigServiceGrpc.NotificationRuleConfigServiceBlockingStub notificationStub; - NotificationRuleStore notificationRuleStore; + NotificationRuleFilteredStore notificationRuleStore; @BeforeEach void beforeEach() { mockGenericConfigService = new MockGenericConfigService().mockUpsert().mockGet().mockGetAll().mockDelete(); - notificationRuleStore = mock(NotificationRuleStore.class); + notificationRuleStore = mock(NotificationRuleFilteredStore.class); ConfigChangeEventGenerator configChangeEventGenerator = mock(ConfigChangeEventGenerator.class); mockGenericConfigService @@ -88,7 +89,13 @@ void createReadUpdateDeleteNotificationRules() { assertEquals( List.of(notificationRule2, notificationRule1), notificationStub - .getAllNotificationRules(GetAllNotificationRulesRequest.getDefaultInstance()) + .getAllNotificationRules( + GetAllNotificationRulesRequest.newBuilder() + .setFilter( + NotificationRuleFilter.newBuilder() + .addEventConditionType("metricAnomalyEventCondition") + .build()) + .build()) .getNotificationRulesList()); NotificationRule ruleToUpdate = @@ -111,7 +118,13 @@ void createReadUpdateDeleteNotificationRules() { assertEquals( List.of(notificationRule2, updatedRule), notificationStub - .getAllNotificationRules(GetAllNotificationRulesRequest.getDefaultInstance()) + .getAllNotificationRules( + GetAllNotificationRulesRequest.newBuilder() + .setFilter( + NotificationRuleFilter.newBuilder() + .addEventConditionType("metricAnomalyEventCondition") + .build()) + .build()) .getNotificationRulesList()); notificationStub.deleteNotificationRule( @@ -121,7 +134,13 @@ void createReadUpdateDeleteNotificationRules() { assertEquals( List.of(updatedRule), notificationStub - .getAllNotificationRules(GetAllNotificationRulesRequest.getDefaultInstance()) + .getAllNotificationRules( + GetAllNotificationRulesRequest.newBuilder() + .setFilter( + NotificationRuleFilter.newBuilder() + .addEventConditionType("metricAnomalyEventCondition") + .build()) + .build()) .getNotificationRulesList()); }