Skip to content

Commit eb76fcf

Browse files
authored
ENG-55741: filtering support on the get all notification rule api (#272)
* ENG-55741: filtering support on the get all notification rule api * addressed comment
1 parent bb9aa98 commit eb76fcf

4 files changed

Lines changed: 55 additions & 12 deletions

File tree

notification-rule-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_rule_config_service.proto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ message UpdateNotificationRuleResponse {
3131
NotificationRule notification_rule = 1;
3232
}
3333

34-
message GetAllNotificationRulesRequest {}
34+
message GetAllNotificationRulesRequest {
35+
NotificationRuleFilter filter = 3;
36+
}
37+
38+
message NotificationRuleFilter {
39+
repeated string event_condition_type = 1;
40+
}
3541

3642
message GetAllNotificationRulesResponse {
3743
repeated NotificationRule notification_rules = 1;

notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
public class NotificationRuleConfigServiceImpl
2828
extends NotificationRuleConfigServiceGrpc.NotificationRuleConfigServiceImplBase {
2929

30-
private final NotificationRuleStore notificationRuleStore;
30+
private final NotificationRuleFilteredStore notificationRuleStore;
3131
private final NotificationRuleConfigServiceRequestValidator validator;
3232

3333
public NotificationRuleConfigServiceImpl(
3434
Channel channel, ConfigChangeEventGenerator configChangeEventGenerator) {
35-
this.notificationRuleStore = new NotificationRuleStore(channel, configChangeEventGenerator);
35+
this.notificationRuleStore =
36+
new NotificationRuleFilteredStore(channel, configChangeEventGenerator);
3637
this.validator = new NotificationRuleConfigServiceRequestValidator();
3738
}
3839

@@ -105,7 +106,7 @@ public void getAllNotificationRules(
105106
responseObserver.onNext(
106107
GetAllNotificationRulesResponse.newBuilder()
107108
.addAllNotificationRules(
108-
notificationRuleStore.getAllObjects(requestContext).stream()
109+
notificationRuleStore.getAllObjects(requestContext, request.getFilter()).stream()
109110
.map(ConfigObject::getData)
110111
.collect(Collectors.toUnmodifiableList()))
111112
.build());

notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleStore.java renamed to notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleFilteredStore.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66
import java.util.Optional;
77
import lombok.SneakyThrows;
88
import lombok.extern.slf4j.Slf4j;
9-
import org.hypertrace.config.objectstore.IdentifiedObjectStore;
9+
import org.hypertrace.config.objectstore.IdentifiedObjectStoreWithFilter;
1010
import org.hypertrace.config.proto.converter.ConfigProtoConverter;
1111
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
1212
import org.hypertrace.config.service.v1.ConfigServiceGrpc;
1313
import org.hypertrace.core.grpcutils.client.RequestContextClientCallCredsProviderFactory;
1414
import org.hypertrace.notification.config.service.v1.NotificationRule;
15+
import org.hypertrace.notification.config.service.v1.NotificationRuleFilter;
1516

1617
@Slf4j
17-
public class NotificationRuleStore extends IdentifiedObjectStore<NotificationRule> {
18+
public class NotificationRuleFilteredStore
19+
extends IdentifiedObjectStoreWithFilter<NotificationRule, NotificationRuleFilter> {
1820

1921
private static final String NOTIFICATION_CONFIG_NAMESPACE = "notification-v1";
2022
private static final String NOTIFICATION_RULE_CONFIG_RESOURCE_NAME = "notificationRuleConfig";
2123

22-
public NotificationRuleStore(
24+
public NotificationRuleFilteredStore(
2325
Channel channel, ConfigChangeEventGenerator configChangeEventGenerator) {
2426
super(
2527
ConfigServiceGrpc.newBlockingStub(channel)
@@ -52,4 +54,19 @@ protected Value buildValueFromData(NotificationRule object) {
5254
protected String getContextFromData(NotificationRule object) {
5355
return object.getId();
5456
}
57+
58+
@Override
59+
protected Optional<NotificationRule> filterConfigData(
60+
NotificationRule data, NotificationRuleFilter filter) {
61+
return Optional.of(data)
62+
.filter(
63+
notificationRule ->
64+
filter.getEventConditionTypeList().isEmpty()
65+
|| filter
66+
.getEventConditionTypeList()
67+
.contains(
68+
notificationRule
69+
.getNotificationRuleMutableData()
70+
.getEventConditionType()));
71+
}
5572
}

notification-rule-config-service-impl/src/test/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImplTest.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.hypertrace.notification.config.service.v1.GetNotificationRuleRequest;
1515
import org.hypertrace.notification.config.service.v1.NotificationRule;
1616
import org.hypertrace.notification.config.service.v1.NotificationRuleConfigServiceGrpc;
17+
import org.hypertrace.notification.config.service.v1.NotificationRuleFilter;
1718
import org.hypertrace.notification.config.service.v1.NotificationRuleMutableData;
1819
import org.hypertrace.notification.config.service.v1.UpdateNotificationRuleRequest;
1920
import org.junit.jupiter.api.BeforeEach;
@@ -23,13 +24,13 @@ class NotificationRuleConfigServiceImplTest {
2324

2425
MockGenericConfigService mockGenericConfigService;
2526
NotificationRuleConfigServiceGrpc.NotificationRuleConfigServiceBlockingStub notificationStub;
26-
NotificationRuleStore notificationRuleStore;
27+
NotificationRuleFilteredStore notificationRuleStore;
2728

2829
@BeforeEach
2930
void beforeEach() {
3031
mockGenericConfigService =
3132
new MockGenericConfigService().mockUpsert().mockGet().mockGetAll().mockDelete();
32-
notificationRuleStore = mock(NotificationRuleStore.class);
33+
notificationRuleStore = mock(NotificationRuleFilteredStore.class);
3334

3435
ConfigChangeEventGenerator configChangeEventGenerator = mock(ConfigChangeEventGenerator.class);
3536
mockGenericConfigService
@@ -88,7 +89,13 @@ void createReadUpdateDeleteNotificationRules() {
8889
assertEquals(
8990
List.of(notificationRule2, notificationRule1),
9091
notificationStub
91-
.getAllNotificationRules(GetAllNotificationRulesRequest.getDefaultInstance())
92+
.getAllNotificationRules(
93+
GetAllNotificationRulesRequest.newBuilder()
94+
.setFilter(
95+
NotificationRuleFilter.newBuilder()
96+
.addEventConditionType("metricAnomalyEventCondition")
97+
.build())
98+
.build())
9299
.getNotificationRulesList());
93100

94101
NotificationRule ruleToUpdate =
@@ -111,7 +118,13 @@ void createReadUpdateDeleteNotificationRules() {
111118
assertEquals(
112119
List.of(notificationRule2, updatedRule),
113120
notificationStub
114-
.getAllNotificationRules(GetAllNotificationRulesRequest.getDefaultInstance())
121+
.getAllNotificationRules(
122+
GetAllNotificationRulesRequest.newBuilder()
123+
.setFilter(
124+
NotificationRuleFilter.newBuilder()
125+
.addEventConditionType("metricAnomalyEventCondition")
126+
.build())
127+
.build())
115128
.getNotificationRulesList());
116129

117130
notificationStub.deleteNotificationRule(
@@ -121,7 +134,13 @@ void createReadUpdateDeleteNotificationRules() {
121134
assertEquals(
122135
List.of(updatedRule),
123136
notificationStub
124-
.getAllNotificationRules(GetAllNotificationRulesRequest.getDefaultInstance())
137+
.getAllNotificationRules(
138+
GetAllNotificationRulesRequest.newBuilder()
139+
.setFilter(
140+
NotificationRuleFilter.newBuilder()
141+
.addEventConditionType("metricAnomalyEventCondition")
142+
.build())
143+
.build())
125144
.getNotificationRulesList());
126145
}
127146

0 commit comments

Comments
 (0)