Files
frigate/frigate/test/test_analytics_collectors_health.py
T
Josh Hawkins b4ff802ddf report notice counts cumulatively from a database baseline
Moving watermarks after each accepted send kept the install ID and the notice baseline out of step: pre-consent notices went out, notices raised before the first send were dropped, and a send that finished after an off/on toggle overwrote the new identity's baseline. health.notices now carries cumulative counts since the install ID was created. Creating an ID copies the lifetime counts into the existing reported_* columns before the state file names it, and nothing is written after a send, so the backend diffs consecutive reports per install ID.
2026-11-01 12:30:35 -06:00

72 lines
2.3 KiB
Python

"""Tests for the health collector."""
import unittest
from frigate.analytics.collectors import health
from frigate.test.analytics_helpers import make_context
class TestHealthCollector(unittest.TestCase):
def test_collects_uptime_cpu_timings_and_notices_since_the_baseline(self):
stats = {
"service": {"uptime": 7300, "retention_unmet": True},
"cpu_usages": {"frigate.full_system": {"cpu": "23.6", "mem": "40"}},
"embeddings": {
"face_recognition_speed": 41.234,
"text_embedding_speed": 0,
"devices": {},
},
}
notice_stats = [
{
"kind": "detector_stuck",
"occurrences": 5,
"acknowledgements": 1,
"mutes": 0,
"reported_occurrences": 3,
"reported_acknowledgements": 1,
"reported_mutes": 0,
},
{
"kind": "shm_too_low",
"occurrences": 2,
"acknowledgements": 0,
"mutes": 0,
"reported_occurrences": 2,
"reported_acknowledgements": 0,
"reported_mutes": 0,
},
{
"kind": "update_available",
"occurrences": 4,
"acknowledgements": 0,
"mutes": 0,
"reported_occurrences": 0,
"reported_acknowledgements": 0,
"reported_mutes": 0,
},
]
section = health.collect(make_context(stats=stats, notice_stats=notice_stats))
self.assertEqual(section.uptime_hours, 2)
self.assertEqual(section.cpu_percent, 24)
self.assertEqual(section.enrichment_ms, {"face": 41.23})
self.assertTrue(section.retention_unmet)
self.assertEqual(
{
kind: (c.occurrences, c.acknowledgements, c.mutes)
for kind, c in section.notices.items()
},
{"detector_stuck": (2, 0, 0)},
)
def test_missing_stats_give_zeros(self):
section = health.collect(make_context())
self.assertEqual(
(section.uptime_hours, section.cpu_percent, section.enrichment_ms),
(0, 0, {}),
)
self.assertEqual(section.notices, {})