Skip to content

PromQL: use start timestamps for rate()-like calculations#18344

Merged
krajorama merged 21 commits into
prometheus:mainfrom
vpranckaitis:use_start_timestamps_in_rate_like_functions
Apr 21, 2026
Merged

PromQL: use start timestamps for rate()-like calculations#18344
krajorama merged 21 commits into
prometheus:mainfrom
vpranckaitis:use_start_timestamps_in_rate_like_functions

Conversation

@vpranckaitis
Copy link
Copy Markdown
Contributor

@vpranckaitis vpranckaitis commented Mar 23, 2026

Which issue(s) does the PR fix:

Implemented a change to use start timestamps for rate() and increase() calculations. This is a part of OTLP Delta Support project.

After this change, counter resets are not only detected by looking at datapoint values, but also by checking start timestamps. As described in PROM-77 proposal, this allows querying deltas with rate() and increase() functions, as long as they have valid start timestamps. Additionally, it should also improve counter reset detection for cumulative counters, where the first scraped value after a counter reset is as high as it was before the reset.

This PR also follows some of the ideas expressed in this comment by @enisoc which are meant to minimize memory usage impact when start timestamps usage is not enabled or when their values would be not useful for the PromQL evaluation.

This PR does not include the changes necessary for start timestamps to work when anchored and smoothed modifiers are used. It was agreed in OTLP Delta Support Working Group meetings that we want to first see a working end-to-end solution before addressing experimental anchored and smoothed modifiers.

Does this PR introduce a user-facing change?

[FEATURE] Use start timestamps for `rate()`, `irate()`, and `increase()` calculations, behind a feature flag `use-start-timestamps`. Doesn't work together with extended range selectors `anchored` and `smoothed`.

Signed-off-by: Vilius Pranckaitis <vpranckaitis@gmail.com>
Comment thread promql/engine_test.go Outdated
Copy link
Copy Markdown
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

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

some minor comments, this is looking pretty good

Comment thread tsdb/db.go
Comment thread promql/engine.go
Comment thread promql/functions.go
Comment thread promql/functions.go Outdated
Comment thread promql/functions.go Outdated
Comment thread docs/feature_flags.md Outdated
Comment thread promql/functions.go Outdated
Signed-off-by: Vilius Pranckaitis <vpranckaitis@gmail.com>
Signed-off-by: Vilius Pranckaitis <vpranckaitis@gmail.com>
@vpranckaitis vpranckaitis requested a review from krajorama March 24, 2026 12:45
Signed-off-by: Vilius Pranckaitis <vpranckaitis@gmail.com>
@vpranckaitis vpranckaitis changed the title PromQL: use start timestamps for rate() and increase() calculations PromQL: use start timestamps for rate()-like calculations Mar 31, 2026
@vpranckaitis vpranckaitis force-pushed the use_start_timestamps_in_rate_like_functions branch from 28f1519 to b5682a1 Compare April 3, 2026 07:26
Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>
@vpranckaitis vpranckaitis marked this pull request as ready for review April 3, 2026 08:39
@vpranckaitis vpranckaitis requested review from a team and roidelapluie as code owners April 3, 2026 08:39
Copy link
Copy Markdown
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

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

Looks good, almost there. I've tried a number of times to wrap my head around the T=ST case ... seems ok, but maybe we could walk through it at the next WG meeting.
I've made a bunch of suggestions to the tests and code.

Comment thread promql/engine.go Outdated
Comment thread promql/functions.go Outdated
Comment thread promql/functions.go Outdated
Comment thread promql/functions.go Outdated
Comment thread promql/promqltest/testdata/start_timestamps.test
Comment thread promql/promqltest/testdata/start_timestamps.test Outdated
Comment thread promql/promqltest/testdata/start_timestamps.test
Comment thread promql/functions.go
Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>
Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>
Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>
Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>
@vpranckaitis vpranckaitis requested a review from krajorama April 13, 2026 10:58
Copy link
Copy Markdown
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

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

Last 3 comments.

Comment thread promql/functions.go Outdated
Comment thread promql/functions.go Outdated
Comment thread docs/feature_flags.md Outdated
Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>
@vpranckaitis vpranckaitis requested a review from krajorama April 14, 2026 09:45
Copy link
Copy Markdown
Member

@krajorama krajorama left a comment

Choose a reason for hiding this comment

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

LGTM.
I think it's too early to add it to features API. We'll need native histograms support for that and extended range selectors.

Comment thread promql/functions.go Outdated
vamsi-01 added a commit to vamsi-01/prometheus that referenced this pull request Apr 20, 2026
Implement detection of overlapping delta aggregation windows where
a sample's start timestamp is less than the previous sample's timestamp.

This resolves issue prometheus#18534 by:
- Collecting start timestamps during matrix evaluation
- Checking for overlaps in both float and histogram samples
- Emitting DeltaStartTimeOverlapWarning annotations when detected
- Warning once per series to avoid spam

The implementation builds on PR prometheus#18344's start timestamp infrastructure,
which propagates ST values through the query path via StartTimestamps struct.

Changes:
- Add DeltaStartTimeOverlapWarning annotation type with merging support
- Implement checkDeltaStartTimeOverlaps() to detect overlapping windows
- Enable ST collection in matrixSelector for overlap detection
- Add comprehensive unit tests for overlap detection logic
- Test various scenarios: normal case, overlaps, nil/zero STs

Depends on: prometheus#18344 (PromQL: use start timestamps for rate-like calculations)
Fixes: prometheus#18534

```release-notes
[FEATURE] PromQL: Annotate a warning when delta samples have overlapping start times (start time < previous timestamp).
```

Signed-off-by: Vamsi Mathala <vmathala@redhat.com>
Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>
@krajorama krajorama enabled auto-merge (squash) April 21, 2026 14:48
Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>
auto-merge was automatically disabled April 21, 2026 14:53

Head branch was pushed to by a user without write access

@krajorama krajorama merged commit 321fe34 into prometheus:main Apr 21, 2026
34 checks passed
vamsi-01 added a commit to vamsi-01/prometheus that referenced this pull request Apr 21, 2026
Implement detection of overlapping delta aggregation windows where
a sample's start timestamp is less than the previous sample's timestamp.

This resolves issue prometheus#18534 by:
- Collecting start timestamps during matrix evaluation
- Checking for overlaps in both float and histogram samples
- Emitting DeltaStartTimeOverlapWarning annotations when detected
- Warning once per series to avoid spam

The implementation builds on PR prometheus#18344's start timestamp infrastructure,
which propagates ST values through the query path via StartTimestamps struct.

Changes:
- Add DeltaStartTimeOverlapWarning annotation type with merging support
- Implement checkDeltaStartTimeOverlaps() to detect overlapping windows
- Enable ST collection in matrixSelector for overlap detection
- Add comprehensive unit tests for overlap detection logic
- Test various scenarios: normal case, overlaps, nil/zero STs

Depends on: prometheus#18344 (PromQL: use start timestamps for rate-like calculations)
Fixes: prometheus#18534

```release-notes
[FEATURE] PromQL: Annotate a warning when delta samples have overlapping start times (start time < previous timestamp).
```

Signed-off-by: Vamsi Mathala <vmathala@redhat.com>
vamsi-01 added a commit to vamsi-01/prometheus that referenced this pull request Apr 21, 2026
Implement detection of overlapping delta aggregation windows where
a sample's start timestamp is less than the previous sample's timestamp.

This resolves issue prometheus#18534 by:
- Collecting start timestamps during matrix evaluation
- Checking for overlaps in both float and histogram samples
- Emitting DeltaStartTimeOverlapWarning annotations when detected
- Warning once per series to avoid spam

The implementation builds on PR prometheus#18344's start timestamp infrastructure,
which propagates ST values through the query path via StartTimestamps struct.

Changes:
- Add DeltaStartTimeOverlapWarning annotation type with merging support
- Implement checkDeltaStartTimeOverlaps() to detect overlapping windows
- Enable ST collection in matrixSelector for overlap detection
- Add comprehensive unit tests for overlap detection logic
- Test various scenarios: normal case, overlaps, nil/zero STs

Fixes: prometheus#18534

```release-notes
[FEATURE] PromQL: Annotate a warning when delta samples have overlapping start times (start time < previous timestamp).
```

Signed-off-by: Vamsi Mathala <vmathala@redhat.com>
vamsi-01 added a commit to vamsi-01/prometheus that referenced this pull request Apr 22, 2026
Implement detection of overlapping aggregation windows where a sample's
start timestamp is less than the previous sample's timestamp. This applies
to both delta and cumulative counter metrics.

This resolves issue prometheus#18534 by:
- Checking for overlaps in rate/increase/delta function calls
- Using condition: currST != 0 && currST < prevT && currST != prevST
- This correctly handles both delta and cumulative counter metrics
- Emitting StartTimeOverlapWarning annotations when detected
- Warning once per series to avoid spam
- Only extracting metric name when overlap is detected (performance)

The implementation builds on PR prometheus#18344's start timestamp infrastructure,
which propagates ST values through the query path via StartTimestamps struct.

Changes:
- Add StartTimeOverlapWarning annotation type with merging support
- Implement checkStartTimeOverlap() to detect overlapping windows
- Add overlap checks in extrapolatedRate() for float samples
- Add overlap checks in histogramRate() for histogram samples
- Add promqltest tests for overlap detection scenarios
- Remove engine.go matrixSelector check (moved to function call path)

Fixes: prometheus#18534
Signed-off-by: Vamsi Mathala <vmathala@redhat.com>
vamsi-01 added a commit to vamsi-01/prometheus that referenced this pull request Apr 23, 2026
Implement detection of overlapping aggregation windows where a sample's
start timestamp is less than the previous sample's timestamp. This applies
to both delta and cumulative counter metrics.

This resolves issue prometheus#18534 by:
- Checking for overlaps in rate/increase/delta function calls
- Using condition: currST != 0 && currST < prevT && currST != prevST
- This correctly handles both delta and cumulative counter metrics
- Emitting StartTimeOverlapWarning annotations when detected
- Warning once per series to avoid spam
- Only extracting metric name when overlap is detected (performance)

The implementation builds on PR prometheus#18344's start timestamp infrastructure,
which propagates ST values through the query path via StartTimestamps struct.

Changes:
- Add StartTimeOverlapWarning annotation type with merging support
- Implement checkStartTimeOverlap() to detect overlapping windows
- Add overlap checks in extrapolatedRate() for float samples
- Add overlap checks in histogramRate() for histogram samples
- Add promqltest tests for overlap detection scenarios
- Remove engine.go matrixSelector check (moved to function call path)

Fixes: prometheus#18534
Signed-off-by: Vamsi Mathala <vmathala@redhat.com>
rbizos pushed a commit to rbizos/prometheus that referenced this pull request Apr 29, 2026
…us#18344)

* PromQL: use start timestamps for rate() and increase() calculations

* implement start timestamps reset detection for `irate()`
* add `start_timestamps.test`
* add a couple of tests with subqueries
* add a test for cumulative with unknown start timestamp
* update `enable-features` CLI parameter description
* `make cli-documentation`

Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>

---------

Signed-off-by: Vilius Pranckaitis <vpranckaitis@gmail.com>
Signed-off-by: vpranckaitis <vpranckaitis@gmail.com>
Signed-off-by: Raphael Bizos <r.bizos@criteo.com>
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.

3 participants