Skip to content

metrics-endpoint: encode the registry off the async worker (spawn_blocking) #3524

Description

@chet

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    No fields configured for Enhancement.

    Projects

    Status
    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions