Skip to content

prometheus: Add CollectorRegistry.unregister functions - #55

Open
last-genius wants to merge 2 commits into
mirage:masterfrom
last-genius:unregister
Open

prometheus: Add CollectorRegistry.unregister functions#55
last-genius wants to merge 2 commits into
mirage:masterfrom
last-genius:unregister

Conversation

@last-genius

Copy link
Copy Markdown

Sources of metrics can sometimes disappear at runtime (a VM being destroyed, disk being unplugged), and rather than continuing to present the last value, it is useful to remove them altogether.

Other Prometheus client libraries do implement similar functions as well, see https://docs.rs/prometheus/latest/prometheus/struct.Registry.html#method.unregister for example.

Andrii Sultanov added 2 commits June 29, 2026 15:19
Sources of metrics can sometimes disappear at runtime (a VM being
destroyed, disk being unplugged), and rather than continuing to present
the last value, it is useful to remove them altogether.

Other Prometheus client libraries do implement similar functions as
well, see https://docs.rs/prometheus/latest/prometheus/struct.Registry.html#method.unregister
for example.

Signed-off-by: Andrii Sultanov <andrii.sultanov@cloud.com>
…ily's metric

Signed-off-by: Andrii Sultanov <andrii.sultanov@cloud.com>
@avsm

avsm commented Aug 6, 2026

Copy link
Copy Markdown
Member

This looks good to me; I'll add it into my release queue unless anyone has any further thoughts (@talex5?)

@talex5

talex5 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

unregister_labels does mean you can now use labels to get a metric, then do unregister_labels and end up with a reference to a metric that will be ignored. Maybe there should be a warning about that in the documentation?

@avsm

avsm commented Aug 6, 2026

Copy link
Copy Markdown
Member

On that note, the prometheus spec recommends:

CollectorRegistry SHOULD offer register()/unregister() functions, and a Collector SHOULD be allowed to be registered to multiple CollectorRegistrys.
...
Metrics with labels SHOULD support a remove() method with the same signature as labels() that will remove a Child from the metric no longer exporting it, and a clear() method that removes all Children from the metric. These invalidate caching of Children.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants