feat(reporter): count heals the gate suppresses
A drift whose fingerprint matches a heal from the last heal_min_interval seconds was counted as a drift event but never as a heal attempt, so the 24h counters showed a drift with no heal and no failure. Decide on the heal before recording the check and report heals_suppressed_24h and heals_suppressed_total, so every drift event is either a heal attempt or a suppressed heal. The suppression warning now names the earlier heal that did not hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
02ca338eb7
commit
4e8a4d6717
5 files changed
+50
-11
No files matched your search
+15
-3
@@ -97,16 +97,25 @@ class ReporterStateTests(unittest.TestCase):
|
||||
reporter = LocalStateReporter(state_file=state_file, node_name="n1")
|
||||
|
||||
reporter.update_status(False, 5, checks_increment=1, drift_events_increment=1)
|
||||
reporter.update_status(False, 5, checks_increment=1, drift_events_increment=1)
|
||||
reporter.update_status(False, 5, heal_result="failed")
|
||||
reporter.update_status(False, 5, heal_result="success")
|
||||
reporter.update_status(
|
||||
False, 5, checks_increment=1, drift_events_increment=1, heal_suppressed=True
|
||||
)
|
||||
|
||||
with open(state_file, "r") as f:
|
||||
payload = json.load(f)
|
||||
|
||||
self.assertEqual(2, payload["drift_events_total"])
|
||||
self.assertEqual(1, payload["drift_heal_attempts_total"])
|
||||
self.assertEqual(1, payload["heals_suppressed_total"])
|
||||
self.assertEqual(2, payload["drift_events_24h"])
|
||||
self.assertEqual(1, payload["drift_heal_attempts_24h"])
|
||||
self.assertEqual(1, payload["heals_suppressed_24h"])
|
||||
# Every drift is accounted for: a heal attempt or a suppressed heal.
|
||||
self.assertEqual(
|
||||
payload["drift_events_24h"],
|
||||
payload["drift_heal_attempts_24h"] + payload["heals_suppressed_24h"],
|
||||
)
|
||||
|
||||
@patch("reporter.time.time")
|
||||
def test_update_status_rolls_24h_window(self, time_mock):
|
||||
@@ -117,7 +126,9 @@ class ReporterStateTests(unittest.TestCase):
|
||||
|
||||
# Initial write at hour 1000.
|
||||
time_mock.return_value = 1000 * 3600
|
||||
reporter.update_status(False, 1, drift_events_increment=1, heal_result="failed")
|
||||
reporter.update_status(
|
||||
False, 1, drift_events_increment=1, heal_result="failed", heal_suppressed=True
|
||||
)
|
||||
|
||||
# New write 25 hours later; previous hour should be pruned from 24h view.
|
||||
time_mock.return_value = (1000 + 25) * 3600
|
||||
@@ -130,6 +141,7 @@ class ReporterStateTests(unittest.TestCase):
|
||||
self.assertEqual(0, payload["drift_heal_attempts_24h"])
|
||||
self.assertEqual(0, payload["heals_24h"])
|
||||
self.assertEqual(0, payload["heal_failures_24h"])
|
||||
self.assertEqual(0, payload["heals_suppressed_24h"])
|
||||
|
||||
def test_update_status_preserves_last_heal_timestamp_when_no_new_heal(self):
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
|
||||
Reference in new issue
Block a user