feature(metrics): expose a Prometheus /metrics endpoint#251
Open
nghiadaulau wants to merge 1 commit into
Open
Conversation
Versus had zero self-observability — nothing to scrape for dashboards or
alerting on the alerter itself. Add a Prometheus endpoint.
- pkg/metrics: a leaf package (imports only client_golang, never a versus
package) holding a private registry, the exposition Handler, and exported
collectors so any subsystem can record a metric without an import cycle.
Registers the Go runtime + process collectors for free.
- GET /metrics, registered in routes.go before the SPA fallback and
unauthenticated like /healthz (exposition data only — no secrets, so a
cluster scraper needs no gateway secret). Served via the fiber net/http
adaptor; the SPA fallback defers the path.
- versus_incidents_total{status} incremented by the incident service after
fan-out (sent / partial / failed), counted even when storage is disabled.
- versus_agent_patterns gauge wired at agent startup via a GaugeFunc over
Catalog.Len().
New dependency: github.com/prometheus/client_golang — the de-facto standard
Prometheus client.
Tests: httptest over Handler() asserts the exposition serves
versus_incidents_total, the patterns gauge, and Go runtime metrics.
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.
Summary
Versus had no self-observability — nothing to scrape for dashboards or for
alerting on the alerter itself. This adds a Prometheus
GET /metricsendpoint.
Design
pkg/metricsis a leaf package — it imports onlyclient_golang, never any versus package — so any subsystem can record ametric without creating an import cycle. It owns a private registry (not
the global default, for predictable tests), the exposition
Handler(),and the exported collectors. Go runtime + process collectors are
registered for free.
GET /metricsis registered inroutes.go(before the SPA fallback,which now defers the path) and is unauthenticated like
/healthz—exposition data only, no secrets, so a cluster scraper needs no gateway
secret. Served through fiber's
net/httpadaptor.Metrics
versus_incidents_totalstatus(sent/partial/failed)versus_agent_patternsGaugeFuncoverCatalog.Len(), wired at agent startup (present only when the agent is enabled)go_*,process_*This is the first metrics surface; further series (source lag, LLM tokens
by task, emissions by verdict) can be layered on incrementally since the
package and endpoint now exist.
New dependency
github.com/prometheus/client_golang— the de-facto standard Prometheusclient for Go. Justified per CONTRIBUTING's "justify new modules".
Testing
pkg/metricshttptest overHandler(): asserts the exposition servesversus_incidents_total, the patterns gauge, and Go runtime metrics./metrics(HTTP 200,go_goroutinespresent,
versus_incidents_totalabsent until first incident), POSTed anincident, re-scraped →
versus_incidents_total{status="sent"} 1.gofmt,go vet,go build ./...,go test -race ./pkg/...green(one unrelated pre-existing failure:
TestGitChangeFeed_RealRepo_Einoclones a remote repo and fails offline).
Checklist
src/configuration/configuration.md)feature:prefix); CHANGELOG updated