Description
Chatting with a user about the idle timeout support in metrics-exporter-prometheus
made me realize that there's one particular -- maybe fatal? -- flaw with the handle-based design: orphaned metrics.
Consider a normal invocation of counter!("key", 1)
:
- we acquire a handle to a counter identified by "key"
- we update that handle
As is, with the handle-based design, that handle is wrapping an Arc<T>
, but we query the handle right before modifying it. Either the metric already exists, or it doesn't -- either because it's brand-new or because it was previously expired and removed from the registry -- but we always get a valid handle as of the time of the call to the registry.
Now, consider when we take a handle to a metric via register_counter!(...)
. The steps to do so are nearly identical to before, specifically in that we query the registry, and the handle is either found if it exists, or is created if it doesn't... but then we never query for it again. If the metric is removed from the registry, the underlying storage may live on (Arc<T>
) but it is disconnected from the registry where it originated.