fix(simple_metrics): skip invalid interval_minutes and restart a malformed healthy_streak (SIENTIAPDE-2191)

- interval_minutes is untyped Mongo config: a string or null now warns and
  skips the adaptive state instead of failing every run (TypeError).
- A hand-edited healthy_streak (null, text, inf) restarts the count and keeps
  escalated, instead of raising on every run.
- README: step 4 runs on every schedule, so a MongoDB failure fails the run.
This commit is contained in:
PedroHMCosme
2026-10-09 10:06:05 -03:00
parent a812acd4e9
commit e1b94b1da4
5 changed files with 31 additions and 6 deletions

View File

@@ -1267,6 +1267,9 @@ def _state(escalated: bool, streak: int) -> dict:
(_state(True, 2), False, 3, _state(False, 0)), # N-th healthy run recovers
(_state(True, 2), True, 3, _state(True, 0)), # breach resets the streak
(_state(True, 0), False, 1, _state(False, 0)), # N=1 recovers on first healthy run
(_state(True, None), False, 3, _state(True, 1)), # hand-edited streak restarts
(_state(True, 'x'), False, 3, _state(True, 1)),
(_state(True, float('inf')), False, 3, _state(True, 1)),
],
)
def test_next_adaptive_state(state, breached, runs, expected):

View File

@@ -322,6 +322,22 @@ def test_adaptive_state_invalid_frequency_alert_is_skipped(
mongo_activities.warning.assert_called_once()
@mark.parametrize('interval_minutes', ['60', None])
def test_adaptive_state_invalid_interval_minutes_is_skipped(
mongo_activities, mongo, interval_minutes
):
# Untyped Mongo config: "60" * 60 is a string, None * 60 a TypeError.
mongo.find_one.return_value = _pipeline(frequency_alert='5m')
result = mongo_activities.update_simple_metrics_adaptive_state(
{**_BREACH_INPUT, 'interval_minutes': interval_minutes}
)
assert result is None
mongo.update_one.assert_not_called()
mongo_activities.warning.assert_called_once()
@mark.parametrize('adaptive_state', ['garbage', ['escalated']])
def test_adaptive_state_malformed_state_is_not_escalated(mongo_activities, mongo, adaptive_state):
mongo.find_one.return_value = _pipeline(frequency_alert='5m', adaptive_state=adaptive_state)