Repository navigation
feat(camera-api): reboot frozen or silent cameras, with a daily budget - #461
Conversation
|
Tested on pi-test (Pi 5, Debian 13, Docker 29), branch develop + #419 + #459 + #461, images built on the Pi, Camera without fresh image, API reboot with budget: OK
Not tested: Remarks:
|
7a5ea49 to
a4a683a
Compare
719ea53 to
3bc0f60
Compare
…atrols The Shelly watchdog reads /health to decide whether to power-cycle the Pi.
The healthcheck kills on every curl failure but rc 7, which looked like a hole: a uvicorn that never binds would stay unhealthy forever. Killing on rc 7 would loop at startup instead, as the kill runs during start_period too, and a hang before the bind is bounded by the 10 s timeout on every camera call.
… camera - The pass only collected the frames it received, so one night frame next to a camera answering 204 (no fresh image, PR #458) read as "every camera reports night" and put the site to sleep for an hour. The site now sleeps only when every expected frame came back and all of them are night frames; one day frame still wakes it. - After the night sleep, only the first camera was probed: in infrared or down, it kept the whole site asleep in daylight. Every camera is probed until one shows daylight, and the site stays asleep only when all of them answer night.
…at answered A single infrared frame dropped the camera's detection history, and with it an ongoing event: cameras flicker between colour and infrared at dusk. The history is now dropped after 3 night frames in a row, and a camera in infrared while the others see daylight is warned once, as it sends no heartbeat. A camera without a fresh image never counted as night, so one dead camera kept the site awake all night: PTZ patrols ran, autofocus ran on infrared images, and the stuck detector spent its reboot budget overnight. Only cameras with a fresh frame count now, and the site sleeps after 3 all-night passes. The frozen frame case is already handled by the API, which drops it after max_age_s. Same rule for the wake-up probe. The identical frame log goes to DEBUG: the engine reads the API cache, which the patrol refreshes slower than the loop runs, so the same frame twice is the normal case. The API's stuck detector diagnoses frozen cameras. The healthcheck killed the API after 25 s of failed checks, as the kill runs inside the check and `retries` gives no margin. The probe now retries for about 2 min, still well under the 10 min stall limit. The image ships no curl anymore, so the probe uses Python's HTTP client with the same retries. Also: - an unchanged frame no longer counts as a new night frame, so one cached infrared capture read on several passes cannot drop an ongoing event - an unchanged frame still sends the camera heartbeat, so a slow URL camera does not look offline
… grace after reboot - Reboot attempts were in memory with monotonic times, so every container restart (healthcheck, update) handed out three new attempts. They are now wall-clock times saved in data/camera_recovery.json (RECOVERY_STATE_FILE) and loaded at startup, pruned to the last 24 h. - `Reboot raised: <exc>` logged the Reolink URL with the camera password. Only the exception type is logged. - A static camera rebooted by the detector failed its next two captures while booting and entered the 30 min skip window. The detector now resets the failure count and gives it 90 s before captures count again. - /patrol_status iterated the attempts deque while the detector appended to it: both sides now hold a lock. - "reboot budget spent" is logged once per episode instead of every 5 min.
/patrol_status showed one attempt in the last 24 h but no last_reboot_attempt once the detector restarted: derive it from the attempts loaded from disk.
137c461 to
d26367e
Compare
a4a683a to
8bfb1f9
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #461 +/- ##
===========================================
+ Coverage 81.05% 84.32% +3.27%
===========================================
Files 7 7
Lines 871 938 +67
===========================================
+ Hits 706 791 +85
+ Misses 165 147 -18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
fe51
left a comment
There was a problem hiding this comment.
LGTM,
One thing before or right after merge: the detector now runs on every camera, including adapters without reboot_camera (URL, RTSP, rest). When can_reboot is false, hits keeps growing and every check logs Camera X and its adapter cannot reboot it at ERROR, forever. A URL camera refreshing every 5 min or slower is seen as frozen at each check, so it would log a WARNING + ERROR every 5 min all day.
Suggestion: log it once per episode like the budget message (hits == CONSECUTIVE_HITS_BEFORE_REBOOT), or skip frozen for cameras that cannot reboot, since it is not actionable.
…eboot A URL or REST source may serve the same cached picture for minutes, which was seen as frozen and logged an error every check.
fe51
left a comment
There was a problem hiding this comment.
Thanks @MateoLostanlen for taking the feedback into account, lets merge !
Part of pyronear/roadmap#16, fixes #445 (API reboot step). Stacked on #458.