Skip to content

fix(processor/deltatocumulative): sort data points by timestamp to handle out-of-order batches#46453

Open
EdgeN8v wants to merge 8 commits intoopen-telemetry:mainfrom
EdgeN8v:fix/issue-46441-deltatocumulative-sort
Open

fix(processor/deltatocumulative): sort data points by timestamp to handle out-of-order batches#46453
EdgeN8v wants to merge 8 commits intoopen-telemetry:mainfrom
EdgeN8v:fix/issue-46441-deltatocumulative-sort

Conversation

@EdgeN8v
Copy link
Copy Markdown

@EdgeN8v EdgeN8v commented Feb 26, 2026

Description

Currently, when the deltatocumulative processor receives metrics in reverse chronological order (e.g., newest-first from the Google Cloud Monitoring API), the internal state machine silently drops all historical data points per batch.

This PR resolves the issue by intercepting the metrics in ConsumeMetrics and performing an in-place sort of the data points by timestamp in ascending order before they are processed by the state machine and filter logic.

Link to tracking issue

Fixes #46441

Testing

  • Ran all existing unit tests in processor/deltatocumulativeprocessor successfully.
  • Updated testdata/timestamps/1.test to verify that out-of-order data points are correctly sorted, processed, and aggregated into the cumulative state without generating ErrOutOfOrder errors.

Documentation

No external documentation changes required. Addressed via inline code comments and a changelog entry.

@EdgeN8v EdgeN8v requested a review from a team as a code owner February 26, 2026 03:16
@EdgeN8v EdgeN8v requested a review from dmitryax February 26, 2026 03:16
@github-actions github-actions Bot added the first-time contributor PRs made by new contributors label Feb 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

@paulojmdias
Copy link
Copy Markdown
Member

/workflow-approve

@paulojmdias
Copy link
Copy Markdown
Member

/workflow-approve

@EdgeN8v
Copy link
Copy Markdown
Author

EdgeN8v commented Feb 27, 2026

@paulojmdias

It looks like the CI is currently failing on govulncheck across multiple components due to a newly disclosed vulnerability (GO-2026-4559) in golang.org/x/net@v0.50.0.

This appears to be a global dependency issue in the main branch and is unrelated to my changes in the deltatocumulative processor. I will wait for an upstream dependency bump before proceeding.

@paulojmdias
Copy link
Copy Markdown
Member

Already fixed by #46475

@paulojmdias
Copy link
Copy Markdown
Member

/workflow-approve

@EdgeN8v
Copy link
Copy Markdown
Author

EdgeN8v commented Feb 27, 2026

All checks are green. Ready for final review when you have a moment. Thanks! @paulojmdias

@github-actions
Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added the Stale label Mar 17, 2026
@EdgeN8v
Copy link
Copy Markdown
Author

EdgeN8v commented Mar 19, 2026

Pinging to keep this PR active. It has been approved by @RichieSams, but is now marked as stale.

Could @paulojmdias or @dmitryax please take a look for the final review when you have a moment? This fixes the out-of-order data point dropping issue in the delta-to-cumulative processor. Thanks!

@paulojmdias paulojmdias removed the Stale label Mar 19, 2026
Copy link
Copy Markdown
Member

@paulojmdias paulojmdias left a comment

Choose a reason for hiding this comment

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

LGTM. Just waiting for an approver to review it as is already approved by a code owner.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions Bot added the Stale label Apr 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions Bot closed this Apr 17, 2026
@braydonk braydonk reopened this Apr 17, 2026
switch metric.Type() {
case pmetric.MetricTypeSum:
if metric.Sum().AggregationTemporality() == pmetric.AggregationTemporalityDelta {
metric.Sum().DataPoints().Sort(func(a, b pmetric.NumberDataPoint) bool {
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.

To do this sorting regardless of any configuration and regardless of the current sorted state will introduce some amount of performance overhead that wasn't there before. Does this component have benchmarks we can use to compare the performance impact of this?

@github-actions github-actions Bot removed the Stale label Apr 18, 2026
@r0mdau
Copy link
Copy Markdown
Contributor

r0mdau commented Apr 21, 2026

In some scenarios it is important to refuse out of order datapoints, like @braydonk, I propose to add a configuration flag for this feature.

And in this scenario: you want to cumulate datapoints by chronological order, this will not work between batches, only within a processed batch. Knowing this, it seems more relevant to create a configuration flag allowing to aggregate numbers out of order and when a sample is out of order: aggregate number + use the last seen timestamp with +1 ns added.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deltatocumulative processor silently drops all but the first data point when points arrive in reverse chronological order

5 participants