-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Description
Proposal
A lot of packages register metrics with the default Prometheus registry. This is a problem for applications such as Grafana Agent, where there could be multiple instances of the same service discovery component, or multiple scrape components. Different instances of these components should have different series, so that we can differentiate them. At a minimum, we will need this for metrics prefixed with:
prometheus_target_prometheus_sd_
One way to achieve this would be via passing a Registerer to constructors such as:
- scrape.NewManager
- SD constructors such as dns.NewDiscovery
This is similar to how we currently pass custom loggers. Since a metrics registerer is also a type of telemetry settings, it makes sense to pass them in the same way as logging settings.
I believe we should only register with the global registry if a custom one is not provided:
- If someone is supplying a custom registry, the chances are that they don't need the global one and using it would just add unnecessary series to it.
- This would make this a breaking change, because currently metrics are registered during
init(). This means that metrics are registered even if some components are not used. If we use constructors for registering, then if a component is never used its metrics will never be registered (even with the global registry).