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
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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.NewRegistrybuilds oneprometheus.Registrycarrying the Go runtime and process collectors the global default had. fx provides it, plus the delivery metric setmetrics.Newbuilds on it.middleware.Newbuilds the HTTP recorder once, on that registry;Metrics()reuses it, so several routers over one graph no longer register twice.metrics.Default()is gone, and nothing registers on the global default any more./metricsis served by the newHandlers.HandleMetrics: the samepromhttpwiringpromhttp.Handler()uses, pointed at the new registry. Same route, same auth.TestTwoMetricsRoutersInOneProcessbuilds two metrics-enabled routers over separate graphs and a third over the first graph again.Worth knowing
go_*,process_*andpromhttp_metric_handler_*included./metricsis enabled; with it off nothing serves them.metrics.Newnow takes*prometheus.Registryrather thanprometheus.Registerer, so fx can supply it directly.script/testtakes no flags;-count=2was applied asGOFLAGS=-count=2 make test.Model: opus-5-5
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.