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

Use specific exception for duplicate timeseries #1074

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kajinamit
Copy link
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.

Copy link
Member

@csmarchbanks csmarchbanks left a comment

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.

prometheus_client/registry.py Outdated Show resolved Hide resolved
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>
@kajinamit
Copy link
Contributor Author

kajinamit commented Dec 10, 2024

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)

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.

2 participants