Skip to content

Commit 692b3d6

Browse files
authored
Merge pull request #5 from mathspace/remove-ramping
Remove ramp up and ramp down support from schedule configuration
2 parents 0a874ec + 71e63b6 commit 692b3d6

File tree

4 files changed

+0
-103
lines changed

4 files changed

+0
-103
lines changed

src/feafea/__init__.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -879,23 +879,9 @@ def from_dict(c: DictConfig, ignore_undefined_refs: bool = False) -> CompiledCon
879879
end = _unix_seconds_from_tz_time(r["schedule"]["end"])
880880
if start >= end:
881881
raise ValueError("start must be before end")
882-
ramp_up = _seconds_from_human_duration(r["schedule"].get("ramp_up", "0m"))
883-
ramp_down = _seconds_from_human_duration(r["schedule"].get("ramp_down", "0m"))
884-
if ramp_up + ramp_down > end - start:
885-
raise ValueError("ramp_up + ramp_down must be less than end - start")
886882
py_common += [f"if attributes['__now'] < {start!r}: return None"]
887883
py_common += [f"if attributes['__now'] >= {end!r}: return None"]
888884

889-
if ramp_up > 0 or ramp_down > 0:
890-
schedule_seed = rule_name + "\0schedule"
891-
py_common = [f"schedule_target_percent = _hash_percent(target_id, seed={schedule_seed!r})"]
892-
if ramp_up > 0:
893-
py_common += [f"ramp_up_percent = 100 * (attributes['__now'] - {start!r}) / {ramp_up!r}"]
894-
py_common += ["if schedule_target_percent >= ramp_up_percent: return None"]
895-
if ramp_down > 0:
896-
py_common += [f"ramp_down_percent = 100 * ({end!r} - attributes['__now']) / {ramp_down!r}"]
897-
py_common += ["if schedule_target_percent >= ramp_down_percent: return None"]
898-
899885
# Compile the flag independent rule.
900886

901887
lines = ["def a(target_id, attributes):"]

src/feafea/config_schema.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@
127127
},
128128
"end": {
129129
"type": "string"
130-
},
131-
"ramp_up": {
132-
"type": "string"
133-
},
134-
"ramp_down": {
135-
"type": "string"
136130
}
137131
},
138132
"required": ["start", "end"]

tests/test_configs.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -258,42 +258,6 @@ def test_valid_schedule(self):
258258
ev = cc.flags["a"].eval("", {"__now": ts})
259259
self.assertEqual(ev.variant, expected)
260260

261-
def test_valid_schedule_ramp(self):
262-
cc = CompiledConfig.from_dict(
263-
{
264-
"flags": {
265-
"ramp": {
266-
"variants": [1, 2],
267-
"default": 1,
268-
},
269-
},
270-
"rules": {
271-
"r1": {
272-
"variants": {"ramp": 2},
273-
"schedule": {
274-
"start": "2024-03-12 00:00:00Z", # 1710201600
275-
"end": "2024-03-12 10:00:00Z", # 1710237600
276-
"ramp_up": "1h",
277-
"ramp_down": "2h",
278-
},
279-
},
280-
},
281-
}
282-
)
283-
284-
non_default_count = 0
285-
for i in range(10000):
286-
v = cc.flags["ramp"].eval(str(i), {"__now": 1710201600 + 360}).variant # 6m after start (or 10% into 1 hour)
287-
if v == 2:
288-
non_default_count += 1
289-
self.assertAlmostEqual(non_default_count / 10000, 0.1, delta=0.02)
290-
291-
non_default_count = 0
292-
for i in range(10000):
293-
v = cc.flags["ramp"].eval(str(i), {"__now": 1710237600 - 7200 + 720}).variant # 12m after start of ramp down
294-
if v == 2:
295-
non_default_count += 1
296-
self.assertAlmostEqual(non_default_count / 10000, 0.9, delta=0.02)
297261

298262

299263
class TestInvalidConfigs(unittest.TestCase):
@@ -370,11 +334,6 @@ def test_invalid_rules_def(self):
370334
({"variants": {"a": 2}, "schedule": {"start": "2024-10-10 10:10:10", "end": "2024-10-10 20:20:20"}}, ValueError, "Timezone missing"),
371335
({"variants": {"a": 2}, "schedule": {"start": "2024-10-10 20:10:10Z", "end": "2024-10-10 10:20:20Z"}}, ValueError, "start must be before end"),
372336
({"variants": {"a": 2}, "schedule": {"start": "2024-10-10 10:10:10Z", "end": "2024-10-10 10:10:10Z"}}, ValueError, "start must be before end"),
373-
(
374-
{"variants": {"a": 2}, "schedule": {"start": "2024-10-10 10:10:00Z", "end": "2024-10-10 10:20:00Z", "ramp_up": "8m", "ramp_down": "8m"}},
375-
ValueError,
376-
r"ramp_up \+ ramp_down must be less than end - start",
377-
),
378337
]
379338

380339
for case, expected_err, regex in cases:

tests/test_configs_undefined_refs.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -203,43 +203,6 @@ def test_valid_schedule(self):
203203
ev = cc.flags["a"].eval("", {"__now": ts})
204204
self.assertEqual(ev.variant, expected)
205205

206-
def test_valid_schedule_ramp(self):
207-
cc = CompiledConfig_from_dict(
208-
{
209-
"flags": {
210-
"ramp": {
211-
"variants": [1, 2],
212-
"default": 1,
213-
},
214-
},
215-
"rules": {
216-
"r1": {
217-
"variants": {"ramp": 2},
218-
"schedule": {
219-
"start": "2024-03-12 00:00:00Z", # 1710201600
220-
"end": "2024-03-12 10:00:00Z", # 1710237600
221-
"ramp_up": "1h",
222-
"ramp_down": "2h",
223-
},
224-
},
225-
},
226-
},
227-
)
228-
229-
non_default_count = 0
230-
for i in range(10000):
231-
v = cc.flags["ramp"].eval(str(i), {"__now": 1710201600 + 360}).variant # 6m after start (or 10% into 1 hour)
232-
if v == 2:
233-
non_default_count += 1
234-
self.assertAlmostEqual(non_default_count / 10000, 0.1, delta=0.02)
235-
236-
non_default_count = 0
237-
for i in range(10000):
238-
v = cc.flags["ramp"].eval(str(i), {"__now": 1710237600 - 7200 + 720}).variant # 12m after start of ramp down
239-
if v == 2:
240-
non_default_count += 1
241-
self.assertAlmostEqual(non_default_count / 10000, 0.9, delta=0.02)
242-
243206

244207
class TestInvalidConfigs(unittest.TestCase):
245208
def test_invalid_flag_def(self):
@@ -312,11 +275,6 @@ def test_invalid_rules_def(self):
312275
({"variants": {"a": 2}, "schedule": {"start": "2024-10-10 10:10:10", "end": "2024-10-10 20:20:20"}}, ValueError, "Timezone missing"),
313276
({"variants": {"a": 2}, "schedule": {"start": "2024-10-10 20:10:10Z", "end": "2024-10-10 10:20:20Z"}}, ValueError, "start must be before end"),
314277
({"variants": {"a": 2}, "schedule": {"start": "2024-10-10 10:10:10Z", "end": "2024-10-10 10:10:10Z"}}, ValueError, "start must be before end"),
315-
(
316-
{"variants": {"a": 2}, "schedule": {"start": "2024-10-10 10:10:00Z", "end": "2024-10-10 10:20:00Z", "ramp_up": "8m", "ramp_down": "8m"}},
317-
ValueError,
318-
r"ramp_up \+ ramp_down must be less than end - start",
319-
),
320278
]
321279

322280
for case, expected_err, regex in cases:

0 commit comments

Comments
 (0)