Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new metrics after registering collector #1430

Open
Jarema opened this issue Jan 11, 2024 Discussed in #1421 · 0 comments
Open

Adding new metrics after registering collector #1430

Jarema opened this issue Jan 11, 2024 Discussed in #1421 · 0 comments
Labels

Comments

@Jarema
Copy link

Jarema commented Jan 11, 2024

Discussed in #1421

Originally posted by piotrpio January 2, 2024
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant