Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Adding new metrics after registering collector #1421

Unanswered
piotrpio asked this question in Q&A
Discussion options

I am writing a custom exporter with collectors discovering and adding new metrics based on response from the server. Up until now, we were simply sending a single request when the exporter starts up and based on the response we were adding metrics and then registering collectors. However, we have a use case where not all metrics we may want to track are available when the exporter first starts, so I would like to be able to add new metrics to the collector during scrape (basically in Collect()).

Simply creating e.g. NewGaugeVec() with config for the new metric seems to work, but there is a problem when I try to unregister the collector - since I added new metrics and those are exposed in my Describe() implementation, the collectorID calculated in func (r *Registry) Unregister(c Collector) bool will be different from the one calculated when first registering the collector. Because of that, the collector is never removed from collectors map in Registry (https://github.com/prometheus/client_golang/blob/main/prometheus/registry.go#L383).
Is my approach to the problem even valid? If so, do you have any suggestions how this problem can be solved?

You must be logged in to vote

Replies: 1 comment

Comment options

Any updates on this? If it's a bug (not recalculating the ID), I can issue a fix, but I did not want to attempt that unless it's confirmed...

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.