Retrieving an existing gauge, and possibly replacing it. #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is currently based on #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.