feat(v1): expose pool env-server stats on an optional Prometheus /metrics endpoint#2077
feat(v1): expose pool env-server stats on an optional Prometheus /metrics endpoint#2077dumko2001 wants to merge 2 commits into
Conversation
…rics endpoint Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c942773634
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try: | ||
| request_line = await reader.readline() | ||
| method, path, *_ = request_line.decode("ascii", "replace").split() |
There was a problem hiding this comment.
Bound idle HTTP connections before awaiting a request line
When metrics are enabled and reachable by an untrusted process (for example, with metrics_address=0.0.0.0), each client can open a TCP connection and send no newline, leaving this readline() task and its socket alive indefinitely. Enough idle connections exhaust the broker process's file descriptors/memory and can disrupt worker scaling or new service connections; apply a short request-read timeout and/or a connection limit.
Useful? React with 👍 / 👎.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Description
The v1 env-server pool (
verifiers/v1/serve/pool.py) — the process that actually serves rollouts during training — has no observability surface today: no stats snapshot, no/metrics, no way to see how many rollouts are in flight or whether a worker is saturated. The only existing metrics work (#1415) targets the legacy v0verifiers/serve/server/architecture, so v1 runs blind.This adds a small, dependency-free Prometheus endpoint for the v1 pool, addressing #1188.
What it does
verifiers/v1/serve/metrics.py: a hand-rendered Prometheus text renderer (PoolMetrics) plus a minimalasyncio.start_server-basedMetricsServerexposingGET /metrics. No new dependencies.EnvServerPool.run()updates cheap, O(1) counters/gauges as it dispatches and reaps requests; the metrics server is started/stopped inside the existingtry/finallyso its lifecycle is coupled to the broker.metrics_portis unset by default (no port → no server).metrics_addressdefaults to127.0.0.1(loopback) rather than binding all interfaces. Both are threaded throughServeConfigand theserveCLI.Metrics exposed
Deliberately scoped to observability: no worker-restart or event-loop-lag gauges, since the pool has no restart controller or lag monitor yet (exposing those would be misleading, and lifecycle work is being handled separately in #1993/#1995). The reply path does no payload decoding, so the broker's zero-copy
copy=Falseforward is preserved.Type of Change
Testing
uv run pytestlocally (targeted:tests/v1/test_configs.py,tests/test_env_server.py— 26 passed).Per AGENTS.md ("Do not add unit tests to your PRs"), no unit tests are added. Verified with a throwaway script that starts a real one-worker
EnvServerPool, issues a request, and curls the endpoint:Checklist
Additional Notes
No new dependencies. Endpoint is disabled unless
metrics_portis set, and binds to loopback by default. Related: #1188 (request), #1415 (v0 equivalent).Note
Low Risk
Opt-in metrics on loopback by default; broker hot path only adds O(1) counter updates and does not change rollout protocol or single-server behavior.
Overview
Adds opt-in observability for the v1
EnvServerPoolbroker via a dependency-freeGET /metricsHTTP endpoint.New
metrics.pydefinesPoolMetrics(Prometheus text) and a minimalMetricsServeronasyncio.start_server. The pool broker updates gauges/counters on dispatch and reply (active rollouts, per-worker load, pending depth, request totals, dispatch→reply latency) without decoding response payloads, so zero-copy forwarding is unchanged. The metrics server starts only whenmetrics_portis set and shuts down in the existingfinallyblock.ServeConfigand theserveCLI gainmetrics_address(default127.0.0.1) andmetrics_port(unset = disabled), threaded throughserve_env→EnvServerPool. Pool-only: single in-process server mode ignores metrics and logs a warning if configured.Reviewed by Cursor Bugbot for commit c942773. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Expose pool env-server stats on an optional Prometheus
/metricsendpointMetricsServer, a minimal asyncio HTTP server serving Prometheus text format at/metrics, andPoolMetrics, a model tracking active rollouts, workers, pending depth, request counts, and latency summaries in verifiers/v1/serve/metrics.py.EnvServerPooloptionally startsMetricsServerwhenmetrics_portis configured, updating metrics on every dispatch and reply, and shuts it down cleanly on exit.ServeConfiggains two new fields:metrics_address(default"0.0.0.0") andmetrics_port(defaultNone; unset disables metrics entirely).Macroscope summarized 65836a6.