[METRICS] Observable instruments double count past the cardinality limit
Describe your environment
main at e89c12ad, macOS arm64, AppleClang 21, CMake RelWithDebInfo.
Steps to reproduce
One cumulative reader, and a view with a cardinality limit of 2 on an ObservableCounter. The callback reports these rounds:
{a=1, b=1}, then {x=7}, then {x=9}, then {x=9}
What is the expected behavior?
x reads 7, 9, 9. The spec says "Measurements MUST NOT be double-counted or dropped during an overflow."
What is the actual behavior?
x = 7, 16, 25
ObservableUpDownCounter gives the same values.
Additional context
last_observed_hash_map_ is full, so Get(x) finds nothing and the whole absolute value counts as a delta every round (async_metric_storage.h:166-176, :205-215).
#4484 keeps this behaviour and pins it in CardinalityLimitCapsCounterBaselines.
Reproduced on current main (c60031c), affects both ObservableCounter and ObservableUpDownCounter.
last_observed_hash_map_ is capped by the cardinality limit, so series past it never find their baseline. Baselines should be unbounded per source series; the delta map already enforces the limit on output.
I'd like to take this and open a PR.
Baselines should be unbounded per source series
Thanks for the reproduction.
Unbounded baselines bring back the growth #4484 just capped.
200k churned sets, one reader
uncapped +43 MiB
capped +0.8 MiB
#4484 moves this code and pins the current behaviour in CardinalityLimitCapsCounterBaselines, so a fix has to start from it.
Please wait for #4484 to merge, and keep the state bounded.
Thanks, fair point. I'll wait for #4484 to merge and look for a fix that keeps state bounded.