Lock-free Observations for Prometheus Histograms
Implementing metrics in a client library for Prometheus comes with an interesting challenge: Those metrics are typically updated a lot (like a counter that gets incremented each time a service processes a request) while reading their current value is relatively rare (each time the Prometheus server scrapes the instance, which happens a few times per minute). All those mutations and reads have to be concurrency-safe, but the otherwise quite handy RWMutex is only good for the opposite case: Many …