The shared metrics-endpoint crate encodes the Prometheus registry inline in its /metrics handler: TextEncoder::new() → registry.gather() → encode(), running on the tokio worker that serves the connection. For a large registry a scrape's gather/encode can briefly occupy that worker.
Surfaced by codex during the agent migration (#3180): the agent's previous bespoke /metrics server offloaded the encode to spawn_blocking, and moving to the shared endpoint adopts the inline form. That's consistent with every other consumer (dns, dhcp, dhcp-server, bmc-proxy, dsx-exchange-consumer, and now agent/fmds all encode inline), so it's not a regression -- but a shared-crate improvement would benefit all of them at once.
If done
Move the gather()/encode() in handle_metrics_request onto a blocking thread (tokio::task::spawn_blocking, or Handle::spawn_blocking) so a large scrape can't stall an async worker. Scrapes are infrequent and encode is usually fast, so this is a robustness nicety, not a correctness fix. Verify /metrics output stays byte-identical.
The shared
metrics-endpointcrate encodes the Prometheus registry inline in its/metricshandler:TextEncoder::new()→registry.gather()→encode(), running on the tokio worker that serves the connection. For a large registry a scrape's gather/encode can briefly occupy that worker.Surfaced by codex during the agent migration (#3180): the agent's previous bespoke
/metricsserver offloaded the encode tospawn_blocking, and moving to the shared endpoint adopts the inline form. That's consistent with every other consumer (dns, dhcp, dhcp-server, bmc-proxy, dsx-exchange-consumer, and now agent/fmds all encode inline), so it's not a regression -- but a shared-crate improvement would benefit all of them at once.If done
Move the
gather()/encode()inhandle_metrics_requestonto a blocking thread (tokio::task::spawn_blocking, orHandle::spawn_blocking) so a large scrape can't stall an async worker. Scrapes are infrequent and encode is usually fast, so this is a robustness nicety, not a correctness fix. Verify/metricsoutput stays byte-identical.