lablink_client_service.heartbeat¶
lablink_client_service.heartbeat
¶
Liveness heartbeat for the LabLink client VM.
Sends a small POST to the allocator every HEARTBEAT_INTERVAL_SECONDS so the allocator can detect silent failures (dead container, broken network, hung host, OOM, out-of-band EC2 termination). The body also carries a handful of cheap health signals for early warning.
Attributes¶
BOOT_ID_PATH = '/proc/sys/kernel/random/boot_id'
module-attribute
¶
HEARTBEAT_INTERVAL_SECONDS = 30
module-attribute
¶
HEARTBEAT_POST_TIMEOUT_SECONDS = 5
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
Functions:¶
build_payload(vm_id, boot_id)
¶
Build the heartbeat JSON payload.
Source code in packages/client/src/lablink_client_service/heartbeat.py
main(cfg)
¶
Source code in packages/client/src/lablink_client_service/heartbeat.py
read_boot_id()
¶
Read the kernel-assigned per-boot UUID. Cached by the caller.
Source code in packages/client/src/lablink_client_service/heartbeat.py
run_heartbeat_loop(allocator_url, client_secret='', interval=HEARTBEAT_INTERVAL_SECONDS, stop_event=None)
¶
Long-running loop that sends a heartbeat every interval seconds.
Mirrors the AutoRebootService loop shape in reboot.py: an Event-driven sleep so callers can stop the loop, and an outer exception guard so a rogue exception in a sampler does not silently kill the thread and leave the container running with no liveness signal.
Source code in packages/client/src/lablink_client_service/heartbeat.py
sample_disk_free_pct(path='/')
¶
Return integer percent of free space on the filesystem at path.
Source code in packages/client/src/lablink_client_service/heartbeat.py
send_heartbeat(base_url, headers, payload)
¶
POST one heartbeat. Swallows network errors — never raises.
Heartbeat integrity is in the allocator noticing when we stop sending. A failed individual POST is not worth crashing the client.