Add metrics endpoint#4
Merged
Merged
Conversation
Synthesize a Prometheus /metrics endpoint from the per-request data we
already receive, plus live worker-pool state. tsheadroom calls headroom's
bare compress() in isolated workers, so headroom's own aggregate metrics
(proxy/client Prometheus, OTel) are never populated by us; instead we
accumulate our own lifetime counters in Go.
Two families are emitted:
- headroom_*: reuse the names headroom's proxy emits for the subset we
can populate faithfully (requests, tokens in/saved, our processing
overhead, per-provider/model, inbound HTTP), so existing headroom
dashboards can be repointed at this endpoint.
- tsheadroom_*: native metrics with no headroom analog (pool
saturation gauges, per-outcome counts, cold starts, tokens_after).
Response-dependent proxy metrics (completion tokens, TTFB, cache
read/write/bust, per-transform timing, waste signals) have no source on
a pre_request hook and are deliberately omitted rather than reported as
misleading zeros.
Also parse aperture's always-present metadata.{provider,model} (sent
regardless of the hook's send config) and prefer metadata.model as the
authoritative model for compress() and the metric labels, falling back
to the request body's model field.
The Metrics type is nil-safe so the handler tests construct a Handler
without one. The pool exposes a busy-slot atomic for the live gauges.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Luke Kosewski <lkosewsk@tailscale.com>
Add a Metrics section to the README: the curl invocation, tables for the headroom_* (repoint-compatible) and tsheadroom_* (native) families, the rationale for the omitted proxy-only metrics, and an access note. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Luke Kosewski <lkosewsk@tailscale.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Simulate headroom's own proxy metrics endpoint.
Add a few other fun metrics that at tsheadroom_ metrics only.