Skip to content

Fleet Reporting — Behavior Specification

Status: Normative. Reference implementation: Python (python/src/brinkhaustools/common/fleet/).

This document defines the runtime behavior every language port of the fleet client/monitor must exhibit. The shared test-fixtures/ and JSON schemas only validate payload shape; they do not catch a port that builds valid payloads but never sends them. That gap is exactly what caused brinkhaus/brinkhaustools#5 (the C++ — and latently Rust — client logged "started" but transmitted nothing).

Every port MUST satisfy this spec and ship a behavioral conformance test (see Conformance).

Components

  • FleetMonitorClient — low-level HTTPS client. Stateless w.r.t. scheduling; exposes send_heartbeat, send_diagnostics, send_status, send_snapshot, send_command_ack, plus connection-state accessors.
  • StatusMonitor — high-level bridge. Loads config, owns a client, and runs the periodic send loops. Implements StatusSource.

Required runtime behavior

1. start() MUST start the send loops

start() MUST cause data to be transmitted without any further caller action. Concretely, after start() the following background work MUST be running:

  • a heartbeat loop that calls send_heartbeat() immediately and then every heartbeat_interval (default 60 s, configurable via heartbeat_interval_sec);
  • a controller loop that, after a 10 s initial delay, every 60 s: retries config load, updates connection diagnosis, sends diagnostics, then sends a status snapshot (or a plain status if no StatusEngine is attached).

A start() that only records a start time / clears a flag is non-conformant.

2. Lifecycle status

  • On start(): send status running (message "Connected").
  • On stop(): best-effort send status stopped (message "Service stopped"), then stop the loops and join the threads. Failures during the final send MUST be swallowed.

3. Connection-state diagnosis codes

Code Meaning Set when Cleared when
7001 Config missing config file cannot be read at construction config loads (initial or retry)
7002 Connection error a send fails / client not connected a send succeeds (connected)

Code 7001 is severity info; code 7002 is severity error. If no diagnosis engine is attached, the monitor still runs (codes are simply not emitted).

4. Config retry

If the config file is absent at construction, the controller loop MUST retry reading it each tick; on success it reconfigures the client (base URL, customer, machine, token), updates the displayed server, and clears 7001.

5. Status derivation

Aggregate status is degraded when the diagnosis engine reports System Status == false, otherwise running. When a StatusEngine is present, send the full snapshot via send_snapshot(snapshot, status, message); otherwise send send_status(status, message).

6. TLS

HTTPS requests MUST verify the server certificate (peer + hostname). Ports built against an OpenSSL-backed HTTP stack with no system CA store (e.g. some Windows builds) MUST allow pointing at a CA bundle — by config field and/or the FLEET_CA_BUNDLE environment variable. The Python reference uses urllib's default verified SSL context; libcurl-based C++ sets CURLOPT_SSL_VERIFYPEER/ CURLOPT_SSL_VERIFYHOST (+ CURLOPT_CAINFO when a bundle is given); Rust uses rustls.

7. Switchability ("addable, not forced")

Fleet reporting is opt-in in every language and adds nothing unless enabled:

  • Python — App(fleet_config_path=...); pass None to disable.
  • Rust — App::builder(...).fleet_config(path) (behind the fleet cargo feature); omit to disable.
  • C++ — App::builder(...).fleetConfig(path); omit to disable.

The same principle applies to logging (LoggingHelper is optional in every port and the library never routes its own output through it).

Endpoints

POST {base_url}/api/ingest/{customer}/{machine}/{software}/{heartbeat|diagnostics|status|command-ack}

customer, machine, software are slugified (lowercased; non-alphanumeric → -; trimmed). Bodies carry an ISO-8601 ts (UTC, Z suffix). See the JSON schemas under test-fixtures/schemas/ for payload shape.

Conformance

Each port ships a CI test that points the monitor at a mock ingest server, starts it with shortened timings, and asserts that ≥1 heartbeat, ≥1 diagnostics and ≥1 status POST arrive within ~2× the interval. To support this, the monitor exposes a test-only timing override (initial delay + controller period).

Language Test Mock
Python python/tests/test_fleet_conformance.py http.server in-process
Rust rust/src/monitor.rs (conformance_run_sends_...) wiremock
C++ cpp/tests/test_fleet_conformance.cpp loopback TCP socket mock

Change process

Behavior changes land in the Python reference + this spec + fixtures first, then in the ports. Do not change a port's wire/loop behavior without updating this document and the conformance tests.