Skip to content

Add WrapCollectorWith and WrapCollectorWithPrefix - #1766

Merged
kakkoyun merged 1 commit into
prometheus:mainfrom
colega:wrap-collector
Apr 10, 2025
Merged

Add WrapCollectorWith and WrapCollectorWithPrefix#1766
kakkoyun merged 1 commit into
prometheus:mainfrom
colega:wrap-collector

Conversation

@colega

@colega colega commented Mar 6, 2025

Copy link
Copy Markdown
Contributor

I found myself in a situation where I had to instantiate multiple instances of a third party library that registered some metrics and never un-registered them.

In my app's lifecycle I needed to un-register them and then register them again, but I couldn't achieve that by wrapping the Registerer.

I decided to register that library's metrics in a separate Registry and register that Registry, but in order to handle multiple instances of the library, I also needed to wrap it with labels, and while such functionality existed already as part of the Registerer wrapping, it wasn't exposed.

This PR just exposes Collector wrapping as a public function.

I found myself in a situation where I had to instantiate multiple
instances of a third party library that registered some metrics and
never un-registered them.

In my app's lifecycle I needed to un-register them and then register
them again, but I couldn't achieve that by wrapping the Registerer.

I decided to register that library's metrics in a separate Registry and
register that Registry, but in order to handle multiple instances of the
library, I also needed to wrap it with labels, and while such
functionality existed already as part of the Registerer wrapping, it
wasn't exposed.

This PR just exposes Collector wrapping as a public function.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>

@ArthurSens ArthurSens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test and example, makes the review process pretty smooth and showcase why we'd ever want something like this :)

LGTM, but if possible I'd like to see an approval from someone else who has been more active than I've been during the last couple of months 😅. Maybe @bwplotka or @kakkoyun ?

@colega

colega commented Apr 8, 2025

Copy link
Copy Markdown
Contributor Author

Hi, any chance we could get this merged?

@kakkoyun kakkoyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Thanks for the detailed tests and examples.

@bwplotka any objections?

@kakkoyun

Copy link
Copy Markdown
Member

I'm merging it. We will still have time to have subsequent PRs until the next release if we want to change anything.

@kakkoyun
kakkoyun merged commit f6c417a into prometheus:main Apr 10, 2025
ying-jeanne pushed a commit to ying-jeanne/client_golang that referenced this pull request Apr 16, 2025
I found myself in a situation where I had to instantiate multiple
instances of a third party library that registered some metrics and
never un-registered them.

In my app's lifecycle I needed to un-register them and then register
them again, but I couldn't achieve that by wrapping the Registerer.

I decided to register that library's metrics in a separate Registry and
register that Registry, but in order to handle multiple instances of the
library, I also needed to wrap it with labels, and while such
functionality existed already as part of the Registerer wrapping, it
wasn't exposed.

This PR just exposes Collector wrapping as a public function.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
juliusmh pushed a commit to juliusmh/client_golang that referenced this pull request Jun 30, 2025
I found myself in a situation where I had to instantiate multiple
instances of a third party library that registered some metrics and
never un-registered them.

In my app's lifecycle I needed to un-register them and then register
them again, but I couldn't achieve that by wrapping the Registerer.

I decided to register that library's metrics in a separate Registry and
register that Registry, but in order to handle multiple instances of the
library, I also needed to wrap it with labels, and while such
functionality existed already as part of the Registerer wrapping, it
wasn't exposed.

This PR just exposes Collector wrapping as a public function.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants