Re: [prometheus-developers] client_golang: lenient version of promauto.Filter

2020-04-23 Thread Bjoern Rabenstein
On 22.04.20 14:04, 'Chris Taylor' via Prometheus Developers wrote:
> 
> 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?

When creating the promauto package, I was actually considering if it
should work that way by default, i.e. instead of creating a new
pre-registered collector, return the already existing one.

However, it appeared to prone to surprises. Also, as you can see from
Brian's answer, often you can avoid the multiple registrations by
structuring your instrumentation code differently. Currying the
registry with `WrapRegistererWith` is a possibility, see
https://pkg.go.dev/github.com/prometheus/client_golang/prometheus?tab=doc#WrapRegistererWith

Or you could use const labels.

There might be a few cases left where you would really like to test
for the double registration. That's exactly why the pattern with the
`AlreadyRegisteredError` exist. However, even that is not completely
uncontroversial. https://github.com/prometheus/prometheus/pull/7005 is
an example where such a case was discussed (without an outcome – the
discussion was postponed, because the PR was primarily about something
else).

Another point is that there was a function `RegisterOrGet` in previous
version and removed it, because the use case was so rare.

That sets the bar for a (re-)introduction of a similar feature quite
high.

-- 
Björn Rabenstein
[PGP-ID] 0x851C3DA17D748D03
[email] bjo...@rabenste.in

-- 
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-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-developers/20200423230311.GI2315%40jahnn.


Re: [prometheus-developers] client_golang: lenient version of promauto.Filter

2020-04-23 Thread Brian Brazil
On Thu, 23 Apr 2020 at 21:08, Chris Taylor <
christopher.tay...@soundcloud.com> wrote:

>
>
> On Thu, 23 Apr 2020 at 10:46, Brian Brazil <
> brian.bra...@robustperception.io> wrote:
>
>> On Wed, 22 Apr 2020 at 22:04, 'Chris Taylor' via Prometheus Developers <
>> prometheus-developers@googlegroups.com> 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/client_golang@v1.5.1/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 prometheus-developers+unsubscr...@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
>> 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 prometheus-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-developers/CAHJKeLqB%2B6Gkd5XWpH5V5Hdth7b1m58CscjP9GYqJcUL%2Bqk5zA%40mail.gmail.com.


Re: [prometheus-developers] client_golang: lenient version of promauto.Filter

2020-04-23 Thread 'Chris Taylor' via Prometheus Developers
On Thu, 23 Apr 2020 at 10:46, Brian Brazil 
wrote:

> On Wed, 22 Apr 2020 at 22:04, 'Chris Taylor' via Prometheus Developers <
> prometheus-developers@googlegroups.com> 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.


>
> 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/client_golang@v1.5.1/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 prometheus-developers+unsubscr...@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
> 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 prometheus-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-developers/CACXQWu6fA%2BT8q-0Z8iqj4WOLyjwuH8MNPWf4F-RATzdSpUNh5Q%40mail.gmail.com.


Re: [prometheus-developers] client_golang: lenient version of promauto.Filter

2020-04-23 Thread Brian Brazil
On Wed, 22 Apr 2020 at 22:04, 'Chris Taylor' via Prometheus Developers <
prometheus-developers@googlegroups.com> 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?

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/client_golang@v1.5.1/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 prometheus-developers+unsubscr...@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
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 prometheus-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-developers/CAHJKeLqkVaLwvFM4N3cARW%2BTUVd72M0sDF_Zcx3CAqZ16Fd15g%40mail.gmail.com.


Re: [prometheus-developers] client_golang: lenient version of promauto.Filter

2020-04-23 Thread Sivan Esan
https://youtu.be/cYjF4zTJxP4

Check it out and let me know

On Thu 23 Apr, 2020, 2:34 AM 'Chris Taylor' via Prometheus Developers, <
prometheus-developers@googlegroups.com> 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:
>
> 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/client_golang@v1.5.1/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 prometheus-developers+unsubscr...@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
> 
> .
>

-- 
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-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-developers/CAOiV00WNGUn2Z8s74Sg4waWGsi7KwyHCpyKT_aSaf9YCDe8OGg%40mail.gmail.com.


[prometheus-developers] client_golang: lenient version of promauto.Filter

2020-04-22 Thread 'Chris Taylor' via Prometheus Developers
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:

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/client_golang@v1.5.1/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 prometheus-developers+unsubscr...@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.