First, there is a bug in the existing code. Calling Metrology.gauge('name', my_gauge_instance) twice fails the second time, because the isinstance call here (https://github.com/cyberdelia/metrology/blob/master/metrology/registry.py#L70) will be called with my_gauge_instance instead of a class object, which fails.
I also run into the case of having a gauge that measures the length of a queue object, and the queue object will be replaced during the lifetime of the program, which means the gauge itself has to be replaced as well (it is not feasible in my case to implement a gauge subclass that can be pointed to a different queue).
Since:
The gauge api requires a custom gauge instance to be passed Metrology.gauge('foo', gauge_instance)
Two calls to these line of code currently return an error.
This is currently based on https://github.com/cyberdelia/metrology/pull/38, but that needn't be the case.
There are a couple elements here.
First, there is a bug in the existing code. Calling
Metrology.gauge('name', my_gauge_instance)
twice fails the second time, because theisinstance
call here (https://github.com/cyberdelia/metrology/blob/master/metrology/registry.py#L70) will be called withmy_gauge_instance
instead of a class object, which fails.I also run into the case of having a gauge that measures the length of a queue object, and the queue object will be replaced during the lifetime of the program, which means the gauge itself has to be replaced as well (it is not feasible in my case to implement a gauge subclass that can be pointed to a different queue).
Since:
The gauge api requires a custom gauge instance to be passed
Metrology.gauge('foo', gauge_instance)
Two calls to these line of code currently return an error.
The proper behaviour of
Metrology.gauge('foo', gauge_instance1) Metrology.gauge('foo', gauge_instance2)
not currently beging defined, it made sense to me to implement it such that the latter call will replace the metric in the registry.