client_python icon indicating copy to clipboard operation
client_python copied to clipboard

Use specific exception for duplicate timeseries

Open kajinamit opened this issue 1 year ago • 1 comments

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.

kajinamit avatar Nov 22 '24 18:11 kajinamit

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 avatar Dec 10 '24 08:12 kajinamit