Skip to content

Add first_over_time and ts_of_first_over_time as experimental functions#17021

Merged
roidelapluie merged 2 commits into
prometheus:mainfrom
ringerc:add_first_over_time
Sep 2, 2025
Merged

Add first_over_time and ts_of_first_over_time as experimental functions#17021
roidelapluie merged 2 commits into
prometheus:mainfrom
ringerc:add_first_over_time

Conversation

@ringerc

@ringerc ringerc commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

promql: add first_over_time(...) and ts_of_first_over_time(...) functions per #16963

Test cover is added for the functions and documentation is updated. make test-short passes; I'll run the longer suite too.

The first_over_time() function is particularly useful when used in a range query as first_over_time(m[step()]) with --enable-feature=promql-duration-expr to find the first sample within the step range. Using offset step() will instead select the newest sample outside the range, if such a sample exists.

Which issue(s) does the PR fix:

#16963

Does this PR introduce a user-facing change?

[FEATURE] PromQL: Add `first_over_time(...)` and `ts_of_first_over_time(...)` behind feature flag `experimental-promql-functions #17021 #16963

@ringerc

ringerc commented Aug 7, 2025

Copy link
Copy Markdown
Contributor Author

I have a second patch here that adds another test case, but this case does not pass and I can't figure out why yet.

Edit: Cause found, raised #17025 . It's a pre-existing bug in the appender, and not related to this PR or first_over_time. Removed no-longer relevant detail.

@ringerc

ringerc commented Aug 7, 2025

Copy link
Copy Markdown
Contributor Author

I've pushed the additional tests now, with a workaround for #17025 included.

@ringerc

ringerc commented Aug 8, 2025

Copy link
Copy Markdown
Contributor Author

make-test-out.txt

make test output

@beorn7

beorn7 commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

@roidelapluie could you have a look? (I have it on my list, too, but it is a long list, and I would feel better if you checked this anyway.)

Comment thread promql/functions.go Outdated
@ringerc
ringerc force-pushed the add_first_over_time branch from d9c40d3 to 92ea438 Compare August 19, 2025 22:03
@ringerc

ringerc commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

The CI test failed with

--- FAIL: TestShutdown (14.28s)
queue_manager_test.go:496: Took too long to shutdown: 1.296696568s > 1s

This strikes me as likely worker load related or unrelated to the PR; certainly I've changed nothing relevant there.

Would anybody mind re-running the test and having a look at the PR now I've addressed the comments in it?

@ringerc

ringerc commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

@roidelapluie Would you be willing to re-check this PR?

@ringerc
ringerc force-pushed the add_first_over_time branch from 92ea438 to 194840c Compare September 1, 2025 00:05
Comment thread docs/querying/functions.md Outdated
@roidelapluie

Copy link
Copy Markdown
Member

It feels counter intuitive to explicitly mention "including NaN samples" as this is the default for all prometheus functions.

@ringerc
ringerc force-pushed the add_first_over_time branch from 194840c to 2ed7d1d Compare September 1, 2025 22:13
@ringerc

ringerc commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

@roidelapluie Patched docs to remove the mention of "including NaN samples". No other changes. Thanks for the review, mind re-approving with the change you suggested?

Looks like some of the CI is a bit unstable too, as the CI windows test failed again despite no code changes.

Add a first_over_time function, and corresponding ts_of_first_over_time
function.  Both are behind the experimental functions feature flag.

Signed-off-by: Craig Ringer <[email protected]>
Add further tests for first_over_time (also covering existing
last_over_time, count_over_time, etc) to exercise vectors
containing a mix of float and histogram samples where the
histogram samples do not come last in the series.

This tripped over prometheus#17025
so it's structured a bit oddly to work around that bug in the
appender as used by promtest.

Signed-off-by: Craig Ringer <[email protected]>
@ringerc
ringerc force-pushed the add_first_over_time branch from 2ed7d1d to 30bf18f Compare September 1, 2025 22:24
@roidelapluie
roidelapluie merged commit 637b176 into prometheus:main Sep 2, 2025
28 checks passed
@ringerc

ringerc commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

@roidelapluie Thanks very much.

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