Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(instrumentation): allow passing in any prometheus.Registerer (#369)
The prometheus client_go library primarily uses the prometheus.Registerer interface instead of the prometheus.Registry struct for registering metrics. Especially the global default registry is only exposed as the interfaces `prometheus.Registerer` and `prometheus.Gatherer`[0]. Users that want to use the default registry currently need to make a type assertion to get the struct from the exported interface: hcloud.WithInstrumentation(prometheus.DefaultGatherer.(*prometheus.Registry)) This could fail at any point if the library changes the underlying implmentation to a different struct. controller-runtime is another example of an SDK that only exports the registry as the interface. I had to implement the above type assertation to get hcloud-go metrics in cluster-api-provider-hetzner[1]. This will not break any user code, because the struct we currently accept implements the interface we will accept from now on. [0]: https://github.com/prometheus/client_golang/blob/046e3203b61d1b5000b162e210a91975f098d742/prometheus/registry.go#L54-L58 [1]: https://github.com/syself/cluster-api-provider-hetzner/blob/b421af694d62a6b66ecbb7a6db2ea1f78a620179/pkg/services/hcloud/client/client.go#L88-L92
- Loading branch information