SIGN IN SIGN UP

chore(buffers): Rework gauge metric handling (#23561)

* Move `update_and_get` within `update_buffer_gauge`

* Break out counter updating from emitting gauges

* Break up counter updating and gauge emission

* Move updating buffer counts into buffer usage data module

Note that the tests on the state of the gauges have been dropped as they now
would only test the proper operation of the metrics recorder.

* Use u64 values in the buffer counters map

* Add and subtract in multithread update test

* Use `update_and_get` to update category metrics atomics as well

* Add helper function to safely convert u64 to i64

* Move current buffer size counters into `BufferUsageData`

* Rename `update_and_get` to `update_counter` dropping the return

* Open code `fn emit_counter_gauge` into callers

* Add missing `buffer_discarded_bytes_total` counter

Corresponds to the existing `buffer_discarded_events_total` counter and
`buffer_byte_size` gauge.

* Add `buffer_id` to `BufferCreated` event

* Drop clamping u64 values to "safe" floats

The "safe" conversion from u64 values into f64 clamped integers that cannot be
exactly represented to the maximum safe integer value. These converted values
were always used to `set` a gauge value. When looking at that gauge, however,
retaining the magnitude is more important than keeping it exactly representable
as an integer, so the safe conversion is actually lossy in the wrong direction.

* Add missing `stage` to discarded event counters

* Only do atomic increments if the counts are non-zero

* Add test to ensure atomic updates obey clamping

* Warn when we overflow or underflow a counter value

* Fix increment test values

* Use "relaxed" ordering for all counter updates

---------

Co-authored-by: Pavlos Rontidis <pavlos.rontidis@gmail.com>
B
Bruce Guenter committed
efe2b0c86d0b9f285da35f80a5c19f590c8fcc18
Parent: d035b63
Committed by GitHub <noreply@github.com> on 8/18/2025, 6:05:50 PM