Skip to content

Add metrics endpoint#4

Merged
lkosewsk merged 2 commits into
mainfrom
lk/metrics
Jun 10, 2026
Merged

Add metrics endpoint#4
lkosewsk merged 2 commits into
mainfrom
lk/metrics

Conversation

@lkosewsk

@lkosewsk lkosewsk commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Simulate headroom's own proxy metrics endpoint.

Add a few other fun metrics that at tsheadroom_ metrics only.

lkosewsk and others added 2 commits June 10, 2026 04:40
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>
@lkosewsk lkosewsk merged commit 8b1aaa1 into main Jun 10, 2026
2 checks passed
@lkosewsk lkosewsk deleted the lk/metrics branch June 10, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant