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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NotificationRule> {
public class NotificationRuleFilteredStore
extends IdentifiedObjectStoreWithFilter<NotificationRule, NotificationRuleFilter> {

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)
Expand Down Expand Up @@ -52,4 +54,19 @@ protected Value buildValueFromData(NotificationRule object) {
protected String getContextFromData(NotificationRule object) {
return object.getId();
}

@Override
protected Optional<NotificationRule> filterConfigData(
NotificationRule data, NotificationRuleFilter filter) {
return Optional.of(data)
.filter(
notificationRule ->
filter.getEventConditionTypeList().isEmpty()
|| filter
.getEventConditionTypeList()
.contains(
notificationRule
.getNotificationRuleMutableData()
.getEventConditionType()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand All @@ -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(
Expand All @@ -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());
}

Expand Down
Loading