Skip to content

Prefer to not register metrics globally #12549

@ptodev

Description

@ptodev

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:

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions