Dear Prometheans,posting this here because the Github issue template suggested discussing changes on themailing list first.I just discovered the `promauto.With(Reigsterer)` API[1] today, which looked like a nice wayto ensure that metrics are registered with a Registerer when they are created.In my use-case, the code receives the Registerer as a dependency.Since it may be called multiple times, I'd like to be able to register metrics multiple times,As an example, imagine writing a middleware to instrument an HTTP handler, similar topackage promhttp:
func InstrumentedHandler(r Registerer, next http.Handler) http.Handler {// register a bunch of metrics on `r` and return a Handler that// bumps them appropriately}Currently, my code uses prometheus.Register(), and checks whether the returned error isa prometheus.AlreadyRegisteredError to get access to the previously-registered metric anduses that instead.It'd be easy enough to write a "lenient" version of promauto.Filter that uses this logic.Would it make sense to add this to client_golang? If so, what do you think the API shouldlook like?Thanks for your time!Chris
--
You received this message because you are subscribed to the Google Groups "Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-devel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-developers/97aa0973-1a26-4a16-af27-b1d926971c21%40googlegroups.com.
On Wed, 22 Apr 2020 at 22:04, 'Chris Taylor' via Prometheus Developers <prometheus...@googlegroups.com> wrote:Dear Prometheans,posting this here because the Github issue template suggested discussing changes on themailing list first.I just discovered the `promauto.With(Reigsterer)` API[1] today, which looked like a nice wayto ensure that metrics are registered with a Registerer when they are created.In my use-case, the code receives the Registerer as a dependency.Since it may be called multiple times, I'd like to be able to register metrics multiple times,As an example, imagine writing a middleware to instrument an HTTP handler, similar topackage promhttp:It sounds like your instrumentation might be at the wrong level, have you tried instrumenting this at the http router instead?
On Thu, 23 Apr 2020 at 10:46, Brian Brazil <brian....@robustperception.io> wrote:On Wed, 22 Apr 2020 at 22:04, 'Chris Taylor' via Prometheus Developers <prometheus...@googlegroups.com> wrote:Dear Prometheans,posting this here because the Github issue template suggested discussing changes on themailing list first.I just discovered the `promauto.With(Reigsterer)` API[1] today, which looked like a nice wayto ensure that metrics are registered with a Registerer when they are created.In my use-case, the code receives the Registerer as a dependency.Since it may be called multiple times, I'd like to be able to register metrics multiple times,As an example, imagine writing a middleware to instrument an HTTP handler, similar topackage promhttp:It sounds like your instrumentation might be at the wrong level, have you tried instrumenting this at the http router instead?sorry, I wasn't clear enough. The HTTP handler was just supposed to be a familiar stand-in for"some library code that is instrumented with metrics that users instantiate multiple times".The concrete use-case I was looking at when I wrote the email related to service discoverythat can be used in various contexts, but my question really applies to any time you'd want towrap some interface in a version with instrumentation.
Brian--func InstrumentedHandler(r Registerer, next http.Handler) http.Handler {// register a bunch of metrics on `r` and return a Handler that// bumps them appropriately}Currently, my code uses prometheus.Register(), and checks whether the returned error isa prometheus.AlreadyRegisteredError to get access to the previously-registered metric anduses that instead.It'd be easy enough to write a "lenient" version of promauto.Filter that uses this logic.Would it make sense to add this to client_golang? If so, what do you think the API shouldlook like?Thanks for your time!Chris
You received this message because you are subscribed to the Google Groups "Prometheus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-devel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-developers/97aa0973-1a26-4a16-af27-b1d926971c21%40googlegroups.com.
--Brian Brazil