Skip to content

Commit 4c942a4

Browse files
authored
fix(aci): allow percent freq intervals (#85907)
1 parent 3b8a92f commit 4c942a4

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/sentry/workflow_engine/handlers/condition/event_frequency_handlers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from sentry.rules.conditions.event_frequency import (
44
COMPARISON_INTERVALS,
5+
PERCENT_INTERVALS,
56
STANDARD_INTERVALS,
67
percent_increase,
78
)
@@ -68,7 +69,7 @@ class PercentSessionsCountHandler(EventFrequencyCountHandler):
6869
comparison_json_schema = {
6970
"type": "object",
7071
"properties": {
71-
"interval": {"type": "string", "enum": list(STANDARD_INTERVALS.keys())},
72+
"interval": {"type": "string", "enum": list(PERCENT_INTERVALS.keys())},
7273
"value": {"type": "number", "minimum": 0, "maximum": 100},
7374
"filters": {
7475
"type": "array",
@@ -85,7 +86,7 @@ class PercentSessionsPercentHandler(EventFrequencyPercentHandler):
8586
comparison_json_schema = {
8687
"type": "object",
8788
"properties": {
88-
"interval": {"type": "string", "enum": list(STANDARD_INTERVALS.keys())},
89+
"interval": {"type": "string", "enum": list(PERCENT_INTERVALS.keys())},
8990
"value": {"type": "number", "minimum": 0, "maximum": 100},
9091
"comparison_interval": {"type": "string", "enum": list(COMPARISON_INTERVALS.keys())},
9192
"filters": {

tests/sentry/workflow_engine/handlers/condition/test_event_frequency_handlers.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from jsonschema import ValidationError
33

44
from sentry.rules.conditions.event_frequency import (
5+
PERCENT_INTERVALS,
6+
STANDARD_INTERVALS,
57
ComparisonType,
68
EventFrequencyCondition,
79
EventFrequencyPercentCondition,
@@ -140,6 +142,8 @@ def setUp(self):
140142
"comparisonType": ComparisonType.PERCENT,
141143
"comparisonInterval": "1d",
142144
}
145+
self.intervals = STANDARD_INTERVALS
146+
self.other_intervals = PERCENT_INTERVALS
143147

144148
def test_percent(self):
145149
dc = self.create_data_condition(
@@ -245,6 +249,18 @@ def test_json_schema(self):
245249
condition_result=True,
246250
)
247251

252+
invalid_interval = list(set(self.other_intervals.keys()) - set(self.intervals.keys()))[0]
253+
with pytest.raises(ValidationError):
254+
self.create_data_condition(
255+
type=self.condition,
256+
comparison={
257+
"interval": invalid_interval,
258+
"value": 100,
259+
"comparison_interval": "1d",
260+
},
261+
condition_result=True,
262+
)
263+
248264

249265
class TestEventUniqueUserFrequencyCountCondition(TestEventFrequencyCountCondition):
250266
def setUp(self):
@@ -276,24 +292,28 @@ def setUp(self):
276292
super().setUp()
277293
self.condition = Condition.PERCENT_SESSIONS_COUNT
278294
self.payload: dict[str, int | str] = {
279-
"interval": "1h",
295+
"interval": "30m", # only percent sessions allows 30m
280296
"id": EventFrequencyPercentCondition.id,
281297
"value": 17,
282298
"comparisonType": ComparisonType.COUNT,
283299
}
300+
self.intervals = PERCENT_INTERVALS
301+
self.other_intervals = STANDARD_INTERVALS
284302

285303

286304
class TestPercentSessionsPercentCondition(TestEventFrequencyPercentCondition):
287305
def setUp(self):
288306
super().setUp()
289307
self.condition = Condition.PERCENT_SESSIONS_PERCENT
290308
self.payload: dict[str, int | str] = {
291-
"interval": "1h",
309+
"interval": "30m", # only percent sessions allows 30m
292310
"id": EventFrequencyPercentCondition.id,
293311
"value": 17,
294312
"comparisonType": ComparisonType.PERCENT,
295313
"comparisonInterval": "1d",
296314
}
315+
self.intervals = PERCENT_INTERVALS
316+
self.other_intervals = STANDARD_INTERVALS
297317

298318

299319
class TestEventUniqueUserFrequencyConditionWithConditions(ConditionTestCase):

0 commit comments

Comments
 (0)