[METRICS] Support synchronous gauge with delta temporality#4152
[METRICS] Support synchronous gauge with delta temporality#4152pranitaurlam wants to merge 2 commits into
Conversation
|
Hi @lalitb @marcalff @ThomsonTan — I've opened #4152 to address this. The fix removes the error/fallback in MetricCollector::GetAggregationTemporality and relies on the existing delta fast-path in TemporalMetricStorage, which already provides the correct window-scoped last-value semantics (the live attributes_hashmap_ is swapped and reset on every collection, so stale attribute sets are never in the snapshot). Tests added for the scenarios you mentioned: record → collect → no record → collect (emits nothing), stale attribute not re-emitted, and recovery after an empty window. Happy to adjust based on your feedback. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4152 +/- ##
==========================================
+ Coverage 82.01% 82.09% +0.08%
==========================================
Files 385 386 +1
Lines 16093 16207 +114
==========================================
+ Hits 13197 13303 +106
- Misses 2896 2904 +8
🚀 New features to boost your workflow:
|
Fixes #4146
Summary
Removes the block in
MetricCollector::GetAggregationTemporalitythat logged an error and silently fell back to cumulative when delta was requested for a synchronous gauge instrument.The existing delta fast-path in
TemporalMetricStorage::buildMetricsalready provides the correct window-scoped last-value semantics for gauge: becauseSyncMetricStorage::Collectswaps and resets the liveattributes_hashmap_on every collection,delta_metricscontains only values recorded since the previous collection. Stale attribute sets that were not updated in the current window are simply absent from the snapshot and are never re-emitted.Changes:
metric_collector.cc: remove the gauge+delta error/fallback; return the reader-requested temporality directly.temporal_metric_storage.cc: update fast-path comment to mention gauge and its window-scoped last-value behavior.sync_metric_storage_gauge_test.cc:kDeltato bothINSTANTIATE_TEST_SUITE_Psuites and assert values for both temporalities.GaugeDeltaWindowTest.NoRecordWindowEmitsNothing: record → collect → no record → collect emits nothing.GaugeDeltaWindowTest.StaleAttributeNotReemitted: record A+B → collect → record A only → collect emits only A.GaugeDeltaWindowTest.RecordAfterEmptyWindowEmitsNewValue: empty window followed by a new recording is exported correctly.Test plan
NoRecordWindowEmitsNothing: second collection with no new recordings emits 0 points.StaleAttributeNotReemitted: attribute not recorded in the current window is not re-exported.RecordAfterEmptyWindowEmitsNewValue: new recording after an empty window is exported correctly.