feat(httpapi): Prometheus /metrics endpoint - #123
Merged
Conversation
Platform teams want to watch a reliability tool's own state alongside everything else they run. Add an authenticated GET /metrics endpoint that emits the Prometheus text exposition format (version 0.0.4) describing the daemon's governed-run state: runs by lifecycle status, halted runs by halt reason, total spend in dollars and tokens, priced model calls, and the pending human-in-the-loop approval-queue depth. The numbers are derived on the fly from the SQLite store the user already owns, so this honors the no-telemetry posture: local metrics the user scrapes, nothing emitted anywhere, no prompt content or PII. The exposition format is hand-rolled rather than pulling in prometheus/client_golang - the surface is tiny and a minimal dependency graph is the rule. The route is registered alongside the other authenticated routes and only when a durable store is configured. Includes docs/METRICS.md with the metric list and an example Prometheus scrape config.
prashar32
force-pushed
the
feat/metrics-endpoint
branch
from
June 13, 2026 17:45
10f0390 to
e843339
Compare
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.
Adds an authenticated Prometheus
/metricsendpoint so platform teams can watch RiskKernel's own state alongside everything else they run.What it exposes
GET /metricsreturns the Prometheus text exposition format (version 0.0.4), sourced from the durable store:riskkernel_runs_total{status}— governed runs by lifecycle status (running / halted / cancelled)riskkernel_runs_halted_total{reason}— halted runs by halt reason (token/dollar/loop/time budget, cancelled)riskkernel_spend_dollars_total— total spend in dollars, summed from the cost ledgerriskkernel_tokens_total— total prompt + completion tokensriskkernel_model_calls_total— priced model calls recorded in the ledgerriskkernel_approvals_pending— pending human-in-the-loop approval-queue depthEach metric carries proper
# HELPand# TYPElines; counters for monotonic spend/tokens/calls, gauges for the live status/queue counts.Notes
prometheus/client_golang.riskkernel_runs_totalseries so a scrape never reads an empty metric as a failed scrape.docs/METRICS.mddocuments the metric list and includes an example Prometheus scrape config.Tests
New
internal/httpapi/metrics_test.go(mirrors thenewTestServerharness): seeds a running / halted / cancelled run plus a pending approval, scrapes/metrics, and asserts 200, thetext/plain; version=0.0.4Content-Type, and the expected metric lines and values. Also covers the empty-daemon case and that auth is enforced (401 without the token, 200 with it).gofmt -lis clean,go vet ./...passes, andgo test ./...passes.Closes #91.