Skip to content

[metrics]: Eliminate global Prometheus registry#207

Open
pseudomuto wants to merge 1 commit intomainfrom
metrics_registry
Open

[metrics]: Eliminate global Prometheus registry#207
pseudomuto wants to merge 1 commit intomainfrom
metrics_registry

Conversation

@pseudomuto
Copy link
Copy Markdown

What was changed

I replaced the package-level vars and init() with a metrics.Registry struct that registers its collectors against an injected prometheus.Registerer and prometheus.Gatherer. Then I threaded *metrics.Registry through all callers.

Notes

  • Metric names, namespaces, subsystems, and label names are identical to the former package-level variables.
  • Added TestNewProxy_TwoInstancesInSameProcess as a regression test.

Why?

Metrics in prometheus_defs.go were registered against prometheus.DefaultRegisterer in an init() function. Creating two Proxy instances in the same process would panic with a duplicate registration error, making it impossible to run multiple proxies or run certain tests without process isolation.

@pseudomuto pseudomuto requested a review from a team as a code owner April 1, 2026 17:49
Metrics in prometheus_defs.go were registered against
prometheus.DefaultRegisterer in an init() function. Creating two Proxy
instances in the same process would panic with a duplicate registration
error, making it impossible to run multiple proxies or run certain tests
without process isolation.

I replaced the package-level vars and init() with a metrics.Registry
struct that registers its collectors against an injected
prometheus.Registerer and prometheus.Gatherer. Thread *metrics.Registry
through all callers. Wire it via fx in proxy/fx.go and metrics/fx.go.

* Metric names, namespaces, subsystems, and label names are identical to
  the former package-level variables.
* Added TestNewProxy_TwoInstancesInSameProcess as a regression test.
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