ws_host_service_stats.rs has two suppressions: run_collector (line 83) and handle_stats_socket (line 166), both #[allow(clippy::cognitive_complexity)].
What they do
run_collector (~50 lines) — streams stats from docker.stats() in a loop, computes CPU delta, inserts into history ring buffer, broadcasts to subscribers
handle_stats_socket (~55 lines) — replays history buffer to a newly connected WebSocket client, then runs a tokio::select! loop relaying broadcast receiver output to the socket
What to do
1. Extract stats chunk processing in run_collector
Lines 105–125 process a single stats chunk: extract values, lock history, push to ring, send via broadcast. Extract:
async fn process_stats_chunk(
state: &AppState,
key: &str,
stats: Stats,
prev_cpu_total: &mut u64,
prev_cpu_system: &mut u64,
tx: &broadcast::Sender<serde_json::Value>,
)
2. Extract history replay in handle_stats_socket
Lines 170–180 replay the history ring to the socket. Extract:
async fn replay_stats_history(
socket: &mut WebSocket,
state: &AppState,
key: &str,
) -> ControlFlow<()>
3. Extract broadcast forwarding loop
Lines 195–218 run the tokio::select! loop that either forwards a broadcast message or handles inbound WebSocket messages. This pattern is shared with ws_stats.rs and ws_service_stats.rs. Consider a shared helper:
async fn relay_broadcast_to_socket(
socket: &mut WebSocket,
rx: &mut broadcast::Receiver<serde_json::Value>,
key: &str,
)
4. Add unit tests
process_stats_chunk (if extraction allows):
- Empty ring → new chunk inserted
- Ring at cap → oldest evicted, new pushed
Important
The workspace Cargo.toml sets cognitive_complexity, too_many_lines, too_many_arguments, and several other clippy lints to warn globally. Run make lint after every change and make sure the output is clean. Don't fix a suppression here only to create new warnings elsewhere.
Acceptance criteria
Related
Tracking issue pattern from previous PRs: #122, #133, #157, #158, #171, #172, #173, #174, #175
ws_host_service_stats.rshas two suppressions:run_collector(line 83) andhandle_stats_socket(line 166), both#[allow(clippy::cognitive_complexity)].What they do
run_collector(~50 lines) — streams stats fromdocker.stats()in a loop, computes CPU delta, inserts into history ring buffer, broadcasts to subscribershandle_stats_socket(~55 lines) — replays history buffer to a newly connected WebSocket client, then runs atokio::select!loop relaying broadcast receiver output to the socketWhat to do
1. Extract stats chunk processing in
run_collectorLines 105–125 process a single stats chunk: extract values, lock history, push to ring, send via broadcast. Extract:
2. Extract history replay in
handle_stats_socketLines 170–180 replay the history ring to the socket. Extract:
3. Extract broadcast forwarding loop
Lines 195–218 run the
tokio::select!loop that either forwards a broadcast message or handles inbound WebSocket messages. This pattern is shared withws_stats.rsandws_service_stats.rs. Consider a shared helper:4. Add unit tests
process_stats_chunk(if extraction allows):Important
The workspace
Cargo.tomlsetscognitive_complexity,too_many_lines,too_many_arguments, and several other clippy lints towarnglobally. Runmake lintafter every change and make sure the output is clean. Don't fix a suppression here only to create new warnings elsewhere.Acceptance criteria
process_stats_chunkextracted (fromrun_collector)replay_stats_historyextracted (fromhandle_stats_socket)relay_broadcast_to_socketextracted (shared across WS stats handlers if possible)make test)make lintpasses with zero new warnings#[allow(clippy::cognitive_complexity)]suppressions ifmake lintpasses without them, keep any that are still needed (note why)Related
Tracking issue pattern from previous PRs: #122, #133, #157, #158, #171, #172, #173, #174, #175