Skip to content

Use specific exception for duplicate timeseries - #1074

Merged
csmarchbanks merged 1 commit into
prometheus:masterfrom
kajinamit:specific-exc
May 6, 2026
Merged

Use specific exception for duplicate timeseries#1074
csmarchbanks merged 1 commit into
prometheus:masterfrom
kajinamit:specific-exc

Conversation

@kajinamit

Copy link
Copy Markdown
Contributor

Use sub-class of ValueError instead of ValueError, so that we can distinguish issues caused by wrong input (like invalid name format) from duplicate metrics being registered into the same registry.

@csmarchbanks csmarchbanks 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.

Just curious what you would do when you encounter a duplicate name vs a different ValueError? I am not opposed to this if it is helpful but would like to understand as well/not encourage bad practices.

Comment thread prometheus_client/registry.py Outdated
@kajinamit

kajinamit commented Dec 10, 2024

Copy link
Copy Markdown
Contributor Author

Just curious what you would do when you encounter a duplicate name vs a different ValueError? I am not opposed to this if it is helpful but would like to understand as well/not encourage bad practices.

We are currently using this client to export metrics of virtual machines running on a specific hypervisor. In this use case we have to register metrics dynamically, because virtual machines might be created/deleted/moved anytime. To achieve the dynamic detection, we check all virtual machines in a host and register metrics for them periodically, but we can't safely check if the virtual machine metrics were registered in the previous cycle without this. (For now we inspect _names_to_collectors before calling register but that's requires external access to a private item, which I want to get rid of)

@kajinamit
kajinamit force-pushed the specific-exc branch 2 times, most recently from a1089eb to 9bd935b Compare May 3, 2026 15:57
Use sub-class of ValueError instead of ValueError, so that we can
distinguish issues caused by wrong input (like invalid name format)
from duplicate metrics being registered into the same registry.

Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
@csmarchbanks
csmarchbanks merged commit 6133347 into prometheus:master May 6, 2026
12 checks passed
@kajinamit
kajinamit deleted the specific-exc branch May 7, 2026 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants