client_java icon indicating copy to clipboard operation
client_java copied to clipboard

Add "increment to" to counters

Open Hoffs opened this issue 2 years ago • 0 comments

Similar to #554 I feel like it is pretty common and legitimate use-case when trying to expose external system metrics using prometheus. For example, there is a autoanalyze_count FROM pg_stat_user_tables stat which is pretty closely mapped to prometheus counter (name gives it away). The problem is that there is no easy safe way to accomplish correct increment. The "obvious" solution is to retrieve current counter value and increment the difference. But this has obvious race condition issues, where anything can happen between value is read and increment is added, where the end result becomes out of sync. In such case, what really is needed is "increment to" method. prometheus-net library provides exactly that: https://github.com/prometheus-net/prometheus-net/blob/master/Prometheus/Counter.cs#L55

Hoffs avatar Sep 13 '23 09:09 Hoffs