Skip to content

Fix: preserve delta start timestamp in fast path#4069

Open
fmutlu68 wants to merge 6 commits into
open-telemetry:mainfrom
fmutlu68:fix-delta-start-ts
Open

Fix: preserve delta start timestamp in fast path#4069
fmutlu68 wants to merge 6 commits into
open-telemetry:mainfrom
fmutlu68:fix-delta-start-ts

Conversation

@fmutlu68
Copy link
Copy Markdown

@fmutlu68 fmutlu68 commented May 8, 2026

Fixes #4038

Changes

  • Track the last delta collection timestamp in the fast path
  • Use the previous collection time as the start timestamp for delta metrics

@fmutlu68 fmutlu68 requested a review from a team as a code owner May 8, 2026 17:52
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 8, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: fmutlu68 / name: Furkan Mutlu (39f0888, c6738ce)
  • ✅ login: ThomsonTan / name: Tom Tan (7e4e191)

@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.09%. Comparing base (90de1e1) to head (06e92a4).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4069      +/-   ##
==========================================
+ Coverage   82.09%   82.09%   +0.01%     
==========================================
  Files         385      385              
  Lines       15989    15994       +5     
==========================================
+ Hits        13124    13129       +5     
  Misses       2865     2865              
Files with missing lines Coverage Δ
sdk/src/metrics/state/temporal_metric_storage.cc 97.73% <100.00%> (+0.14%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fmutlu68 fmutlu68 changed the title fix: preserve delta start timestamp in fast path Fix: preserve delta start timestamp in fast path May 10, 2026
has_last_delta_collection_ts_ = true;
}
// If no metrics, early return
if (delta_metrics->Size() == 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the empty-collection path, the function early-returns when delta_metrics->Size() == 0 before updating last_delta_collection_ts_. If a cycle at t2 is empty and the next cycle at t3 has data, the emitted point will carry start_ts = t1 (the last non-empty collection) rather than t2, even though the delta map only contains activity from (t2, t3]. Successive delta windows then overlap instead of abutting, which violates the OTel data model's requirement that start_ts(n) == end_ts(n-1) and causes rate computations (value / (end - start)) to under-report. The slow path doesn't have this issue because last_reported_metrics_[collector].collection_ts is updated on every call, including empty ones.

@ThomsonTan
Copy link
Copy Markdown
Contributor

Thanks @fmutlu68 for the fix. Please add a unit test that calls buildMetrics for a single delta collector across at least three collection cycles (with one empty cycle in the middle) and asserts that each MetricData::start_ts equals the previous end_ts. Without it, the fast path can silently regress again.

@fmutlu68
Copy link
Copy Markdown
Author

@ThomsonTan Thank you for your detailed feedback. I have created a unit test which contains 3 cycles which you mentioned. Could you check it ?

if (reported != last_reported_metrics_.end())
{
// To save the time for next cycle
reported->second.collection_ts = collection_ts;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I want to double check before approving: this new slow-path update may be unreachable. Once a collector has reported, we create an entry in unreported_metrics_ for it, and later we only move present->second, we never erase the map key. So present == end() may not really happen together with reported != end(). Can you confirm whether this branch is actually expected to run?

@fmutlu68 fmutlu68 force-pushed the fix-delta-start-ts branch from e701055 to 06e92a4 Compare May 12, 2026 18:19
@fmutlu68
Copy link
Copy Markdown
Author

Could anyone have a look at here ? @ThomsonTan @lalitb It passes all checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delta temporality fast path in TemporalMetricStorage::buildMetrics sets start_ts to SDK start time instead of previous collection time

3 participants