Serve /metrics from a registry of its own (closes #227) #346

Open
clawbot wants to merge 1 commits from issue-227-own-metrics-registry into next
Collaborator

Fixes #227: a second metrics-enabled router in one process panicked on a duplicate collector registration, because everything registered on Prometheus's global default registry.

What changed

  • metrics.NewRegistry builds one prometheus.Registry carrying the Go runtime and process collectors the global default had. fx provides it, plus the delivery metric set metrics.New builds on it.
  • middleware.New builds the HTTP recorder once, on that registry; Metrics() reuses it, so several routers over one graph no longer register twice.
  • The delivery engine and handlers take the metric set from fx; metrics.Default() is gone, and nothing registers on the global default any more.
  • /metrics is served by the new Handlers.HandleMetrics: the same promhttp wiring promhttp.Handler() uses, pointed at the new registry. Same route, same auth.
  • New test TestTwoMetricsRoutersInOneProcess builds two metrics-enabled routers over separate graphs and a third over the first graph again.

Worth knowing

  • The scrape keeps the same series names and labels, go_*, process_* and promhttp_metric_handler_* included.
  • The HTTP collectors now register when the middleware is built, whether or not /metrics is enabled; with it off nothing serves them.
  • metrics.New now takes *prometheus.Registry rather than prometheus.Registerer, so fx can supply it directly.
  • Delivery test engines each get a set on a fresh registry instead of sharing the global one.
  • script/test takes no flags; -count=2 was applied as GOFLAGS=-count=2 make test.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/webhooker/issues/227: a second metrics-enabled router in one process panicked on a duplicate collector registration, because everything registered on Prometheus's global default registry. **What changed** - `metrics.NewRegistry` builds one `prometheus.Registry` carrying the Go runtime and process collectors the global default had. fx provides it, plus the delivery metric set `metrics.New` builds on it. - `middleware.New` builds the HTTP recorder once, on that registry; `Metrics()` reuses it, so several routers over one graph no longer register twice. - The delivery engine and handlers take the metric set from fx; `metrics.Default()` is gone, and nothing registers on the global default any more. - `/metrics` is served by the new `Handlers.HandleMetrics`: the same `promhttp` wiring `promhttp.Handler()` uses, pointed at the new registry. Same route, same auth. - New test `TestTwoMetricsRoutersInOneProcess` builds two metrics-enabled routers over separate graphs and a third over the first graph again. **Worth knowing** - The scrape keeps the same series names and labels, `go_*`, `process_*` and `promhttp_metric_handler_*` included. - The HTTP collectors now register when the middleware is built, whether or not `/metrics` is enabled; with it off nothing serves them. - `metrics.New` now takes `*prometheus.Registry` rather than `prometheus.Registerer`, so fx can supply it directly. - Delivery test engines each get a set on a fresh registry instead of sharing the global one. - `script/test` takes no flags; `-count=2` was applied as `GOFLAGS=-count=2 make test`. Model: opus-5-5
clawbot added the needs-review label 2026-09-29 11:31:43 +02:00
clawbot self-assigned this 2026-09-29 11:31:43 +02:00
clawbot added 1 commit 2026-09-29 11:31:43 +02:00
The HTTP metrics recorder, the delivery collectors and the Go and
process collectors now register on one prometheus.Registry that fx
provides, instead of Prometheus's global default registry, and
/metrics serves that registry. A second metrics-enabled router in one
process, or the server tests run with -count=2, no longer panics on a
duplicate registration.

The middleware builds its recorder once, in New, so installing
Metrics() on more than one router over the same graph is also safe.
The scrape keeps the same series and labels, including go_*,
process_* and promhttp_metric_handler_*.

Model: opus-5-5
All checks were successful
check / check (push) Successful in 4m2s
You are not authorized to merge this pull request.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin issue-227-own-metrics-registry:issue-227-own-metrics-registry
git checkout issue-227-own-metrics-registry
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/webhooker#346