On Thu, 23 Apr 2020 at 21:08, Chris Taylor <
[email protected]> wrote:

>
>
> On Thu, 23 Apr 2020 at 10:46, Brian Brazil <
> [email protected]> wrote:
>
>> On Wed, 22 Apr 2020 at 22:04, 'Chris Taylor' via Prometheus Developers <
>> [email protected]> wrote:
>>
>>> Dear Prometheans,
>>>
>>> posting this here because the Github issue template suggested discussing
>>> changes on the
>>> mailing list first.
>>>
>>> I just discovered the `promauto.With(Reigsterer)` API[1] today, which
>>> looked like a nice way
>>> to 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 to
>>> package 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 discovery
> that can be used in various contexts, but my question really applies to
> any time you'd want to
> wrap some interface in a version with instrumentation.
>

It sounds then like you'd curry the registry with the relevant labels
before passing it in then.

Brian


>
>
>>
>> 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 is
>>> a prometheus.AlreadyRegisteredError to get access to the
>>> previously-registered metric and
>>> uses 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 should
>>> look like?
>>>
>>> Thanks for your time!
>>> Chris
>>>
>>> [1]:
>>> https://pkg.go.dev/github.com/prometheus/[email protected]/prometheus/promauto?tab=doc#With
>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/prometheus-developers/97aa0973-1a26-4a16-af27-b1d926971c21%40googlegroups.com
>>> <https://groups.google.com/d/msgid/prometheus-developers/97aa0973-1a26-4a16-af27-b1d926971c21%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Brian Brazil
>> www.robustperception.io
>>
>

-- 
Brian Brazil
www.robustperception.io

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-developers/CAHJKeLqB%2B6Gkd5XWpH5V5Hdth7b1m58CscjP9GYqJcUL%2Bqk5zA%40mail.gmail.com.

Reply via email to