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] [email protected]

-- 
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/20200423230311.GI2315%40jahnn.

Reply via email to