Skip to content

Commit e8186d0

Browse files
support to enable/disable a notif rule (#281)
* ENG-58592 - support to enable/disable a notif rule * addressed comments * Update gradle locks * Revert "Update gradle locks" This reverts commit 5dff600. * addressed comments * addressed comment * addressed comment & fixed test --------- Co-authored-by: Kshitiz Saxena <[email protected]>
1 parent 9fa718b commit e8186d0

File tree

4 files changed

+84
-13
lines changed

4 files changed

+84
-13
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ message NotificationRuleMutableData {
2020
string rate_limit_interval_duration = 6;
2121

2222
NotificationIntegrationTarget integration_target = 7;
23+
bool disabled = 8;
2324
}
2425

2526
message NotificationIntegrationTarget {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ message GetAllNotificationRulesRequest {
3737

3838
message NotificationRuleFilter {
3939
repeated string event_condition_type = 1;
40+
optional bool enabled = 2;
4041
}
4142

4243
message GetAllNotificationRulesResponse {

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,21 @@ protected String getContextFromData(NotificationRule object) {
5959
protected Optional<NotificationRule> filterConfigData(
6060
NotificationRule data, NotificationRuleFilter filter) {
6161
return Optional.of(data)
62-
.filter(
63-
notificationRule ->
64-
filter.getEventConditionTypeList().isEmpty()
65-
|| filter
66-
.getEventConditionTypeList()
67-
.contains(
68-
notificationRule
69-
.getNotificationRuleMutableData()
70-
.getEventConditionType()));
62+
.filter(rule -> satisfiesEnabledPredicate(rule, filter))
63+
.filter(rule -> satisfiesConditionTypePredicate(rule, filter));
64+
}
65+
66+
private boolean satisfiesEnabledPredicate(
67+
NotificationRule notificationRule, NotificationRuleFilter filter) {
68+
return !filter.hasEnabled()
69+
|| filter.getEnabled() != notificationRule.getNotificationRuleMutableData().getDisabled();
70+
}
71+
72+
private boolean satisfiesConditionTypePredicate(
73+
NotificationRule notificationRule, NotificationRuleFilter filter) {
74+
return filter.getEventConditionTypeList().isEmpty()
75+
|| filter
76+
.getEventConditionTypeList()
77+
.contains(notificationRule.getNotificationRuleMutableData().getEventConditionType());
7178
}
7279
}

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

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ void beforeEach() {
4646
@Test
4747
void createReadUpdateDeleteNotificationRules() {
4848
NotificationRuleMutableData notificationRuleMutableData1 =
49-
getNotificationRuleMutableData("rule1", "channel1");
49+
getNotificationRuleMutableData("rule1", "channel1", false);
5050
NotificationRuleMutableData notificationRuleMutableData2 =
51-
getNotificationRuleMutableData("rule2", "channel1");
51+
getNotificationRuleMutableData("rule2", "channel1", false);
52+
NotificationRuleMutableData notificationRuleMutableData3 =
53+
getNotificationRuleMutableData("rule3", "channel1", false);
5254
when(notificationRuleStore.getAllObjects(any())).thenReturn(List.of());
5355

5456
NotificationRule notificationRule1 =
@@ -86,8 +88,25 @@ void createReadUpdateDeleteNotificationRules() {
8688
.build())
8789
.getNotificationRule());
8890

91+
NotificationRule notificationRule3 =
92+
notificationStub
93+
.createNotificationRule(
94+
CreateNotificationRuleRequest.newBuilder()
95+
.setNotificationRuleMutableData(notificationRuleMutableData3)
96+
.build())
97+
.getNotificationRule();
98+
8999
assertEquals(
90-
List.of(notificationRule2, notificationRule1),
100+
notificationRule3,
101+
notificationStub
102+
.getNotificationRule(
103+
GetNotificationRuleRequest.newBuilder()
104+
.setNotificationRuleId(notificationRule3.getId())
105+
.build())
106+
.getNotificationRule());
107+
108+
assertEquals(
109+
List.of(notificationRule3, notificationRule2, notificationRule1),
91110
notificationStub
92111
.getAllNotificationRules(
93112
GetAllNotificationRulesRequest.newBuilder()
@@ -114,7 +133,35 @@ void createReadUpdateDeleteNotificationRules() {
114133
.build())
115134
.getNotificationRule();
116135
assertEquals(ruleToUpdate, updatedRule);
136+
// disable rule
137+
NotificationRule ruleToUpdate3 =
138+
notificationRule3.toBuilder()
139+
.setNotificationRuleMutableData(
140+
notificationRule3.getNotificationRuleMutableData().toBuilder()
141+
.setDisabled(true)
142+
.build())
143+
.build();
144+
NotificationRule updatedRule3 =
145+
notificationStub
146+
.updateNotificationRule(
147+
UpdateNotificationRuleRequest.newBuilder()
148+
.setNotificationRuleMutableData(ruleToUpdate3.getNotificationRuleMutableData())
149+
.setId(ruleToUpdate3.getId())
150+
.build())
151+
.getNotificationRule();
152+
assertEquals(ruleToUpdate3, updatedRule3);
117153

154+
assertEquals(
155+
List.of(updatedRule3, notificationRule2, updatedRule),
156+
notificationStub
157+
.getAllNotificationRules(
158+
GetAllNotificationRulesRequest.newBuilder()
159+
.setFilter(
160+
NotificationRuleFilter.newBuilder()
161+
.addEventConditionType("metricAnomalyEventCondition")
162+
.build())
163+
.build())
164+
.getNotificationRulesList());
118165
assertEquals(
119166
List.of(notificationRule2, updatedRule),
120167
notificationStub
@@ -123,6 +170,7 @@ void createReadUpdateDeleteNotificationRules() {
123170
.setFilter(
124171
NotificationRuleFilter.newBuilder()
125172
.addEventConditionType("metricAnomalyEventCondition")
173+
.setEnabled(true)
126174
.build())
127175
.build())
128176
.getNotificationRulesList());
@@ -131,6 +179,18 @@ void createReadUpdateDeleteNotificationRules() {
131179
DeleteNotificationRuleRequest.newBuilder()
132180
.setNotificationRuleId(notificationRule2.getId())
133181
.build());
182+
assertEquals(
183+
List.of(updatedRule3, updatedRule),
184+
notificationStub
185+
.getAllNotificationRules(
186+
GetAllNotificationRulesRequest.newBuilder()
187+
.setFilter(
188+
NotificationRuleFilter.newBuilder()
189+
.addEventConditionType("metricAnomalyEventCondition")
190+
.build())
191+
.build())
192+
.getNotificationRulesList());
193+
134194
assertEquals(
135195
List.of(updatedRule),
136196
notificationStub
@@ -139,19 +199,21 @@ void createReadUpdateDeleteNotificationRules() {
139199
.setFilter(
140200
NotificationRuleFilter.newBuilder()
141201
.addEventConditionType("metricAnomalyEventCondition")
202+
.setEnabled(true)
142203
.build())
143204
.build())
144205
.getNotificationRulesList());
145206
}
146207

147208
private NotificationRuleMutableData getNotificationRuleMutableData(
148-
String name, String channelId) {
209+
String name, String channelId, boolean disabled) {
149210
return NotificationRuleMutableData.newBuilder()
150211
.setRuleName(name)
151212
.setDescription("sample rule")
152213
.setChannelId(channelId)
153214
.setEventConditionType("metricAnomalyEventCondition")
154215
.setEventConditionId("rule-1")
216+
.setDisabled(disabled)
155217
.build();
156218
}
157219

0 commit comments

Comments
 (0)