1407 Commits

Author SHA1 Message Date
Neeraj Gartia
a177376d72 fix promql-test error message and readme
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-05-05 23:23:35 +05:30
Charles Korn
2c0f02a702
promql: don't emit a value from histogram_fraction or histogram_quantile if classic and native histograms are present at the same timestamp
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2025-05-05 16:23:08 +10:00
Arve Knudsen
e7e3ab2824
Fix linting issues found by golangci-lint v2.0.2 (#16368)
* Fix linting issues found by golangci-lint v2.0.2

---------

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2025-05-03 19:05:13 +02:00
Aman
26bddcf068
promql: histogram_stddev and histogram_stdvar should use arithmetic mean for custom buckets
Signed-off-by: amanycodes <amanycodes@gmail.com>
2025-04-24 14:48:58 +02:00
Zhang Zhanpeng
0658923bf0 fix conversion from time range in seconds to time duration at parser
Signed-off-by: Zhang Zhanpeng <zhangzhanpeng.zzp@alibaba-inc.com>
2025-04-24 16:29:33 +08:00
Michael Hoffmann
d6d9f97bac
promql: histogram_fraction for bucket histograms (#16095)
* promql: histogram_fraction for bucket histograms

This PR extends the histogram_fraction function to also work with classic bucket histograms. This is beneficial because it allows expressions like sum(increase(my_bucket{le="0.5"}[10m]))/sum(increase(my_total[10m])) to be written without knowing the actual values of the "le" label, easing the transition to native histograms later on.
It also feels natural since histogram_quantile also can deal with classic histograms.

Signed-off-by: Michael Hoffmann <mhoffmann@cloudflare.com>

* promql: histogram_fraction for bucket histograms

* Add documentation and reduce code duplication
* Fix a bug in linear interpolation between bucket boundaries
* Add more PromQL tests

Signed-off-by: Michael Hoffmann <mhoffmann@cloudflare.com>

* Update docs/querying/functions.md

Co-authored-by: Björn Rabenstein <github@rabenste.in>
Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>

---------

Signed-off-by: Michael Hoffmann <mhoffmann@cloudflare.com>
Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
2025-04-23 00:28:31 +02:00
Julien
f4ca1368ff
Merge pull request #16249 from roidelapluie/arythmetics
PromQL: allow arithmetic operations in durations in PromQL parser
2025-04-22 10:17:41 +02:00
Neeraj Gartia
a511164615
[REFACTOR] PromQL: DRY stddev and stdvar functions (#16451)
* DRY stddev and stdvar

---------

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-04-20 11:17:03 +02:00
David Leadbeater
e647f7954f
promtool: Add feature flags for promql features (#16443)
These are supported in the main prometheus binary but the feature flags
weren't supported in promtool.

Fixes #16412.

Signed-off-by: David Leadbeater <dgl@dgl.cx>
2025-04-17 10:29:44 +01:00
Björn Rabenstein
ba8609fbd0
Merge pull request #16352 from NeerajGartia21/promql/subquery_patch
[BUG] PromQL: Return early when `endtime` < `startime`
2025-04-16 01:00:19 +02:00
Julien Pivotto
e57512acfc Address feedback
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2025-04-07 12:58:34 +02:00
Neeraj Gartia
f83e964231 fix NH load expression with incrementation more than once
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-04-05 23:37:39 +05:30
Julien Pivotto
2cf2bf5b8f Address feedback
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2025-04-03 13:19:55 +02:00
Julien Pivotto
2f6ad79edf Move calculation to the engine
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2025-04-03 10:56:02 +02:00
Julien Pivotto
9cfd6f7df8 PromQL duration expr: Add a check for durations our of range
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2025-04-03 10:56:02 +02:00
Julien Pivotto
7370d62acf PromQL: allow arithmetic in durations in PromQL parser
Updated the parser to allow calculations in PromQL durations.

This enables durations in the form of:

  rate(http_requests_total[10m+2s])

The computation of the calculations is done directly at the parse level and does not hit the PromQL Engine.
The lexer has also been updated and improved, in particular for subqueries.

Buxfix: rate(http_requests_total[0]) is no longer allowed.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2025-04-03 10:56:02 +02:00
Neeraj Gartia
6e51c2dbd6
[FEATURE] Promltest: support to test expectation annotations (#15995)
promqltest: add new expect lines for promql testing framework

---------

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-04-01 12:12:23 +02:00
Neeraj Gartia
9084c5247f fix subquery bug
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-03-31 00:41:08 +05:30
Matthieu MOREL
5fa1146e21
chore: enable gci linter (#16245)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-03-22 15:46:13 +00:00
Owen Williams
0bfbd462ac
Merge pull request #16080 from prometheus/owilliams/escapeconfig-00-cleanup
utf8: Remove support for legacy global validation setting
2025-03-13 14:21:09 -04:00
Owen Williams
94b43c5d4c utf8: Remove support for legacy global validation setting
Global and Data Source configurations can specify legacy mode, but Prometheus now requires that the overall validation mode be set to UTF-8

Signed-off-by: Owen Williams <owen.williams@grafana.com>
2025-03-13 10:47:24 -04:00
Charles Korn
c88d0b0e0a
promql: return NaN from irate() if second-last sample is NaN (#16199)
promql: return NaN from `irate()` if either of last two samples is NaN

Signed-off-by: Charles Korn <charles.korn@grafana.com>

---------

Signed-off-by: Charles Korn <charles.korn@grafana.com>
2025-03-13 15:06:17 +01:00
Arve Knudsen
56929ffa42 Upgrade to Go v1.24 (#16180)
* Upgrade to Go v1.24
* Upgrade golangci-lint

---------

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2025-03-07 11:28:26 +01:00
Giuliano Panzironi
2ef8706c27
fix: format float to avoid overflow (#16083)
Signed-off-by: giulianopz <panzironi.giuliano@gmail.com>
2025-03-03 09:03:45 +00:00
co63oc
0e4e5a71bd
Fix typos (#16076)
Signed-off-by: co63oc <co63oc@users.noreply.github.com>
2025-02-28 11:24:25 +11:00
Björn Rabenstein
7bbbb5cb97
Merge pull request #16006 from mmorel-35/revive/unused-parameter
chore: enable unused-parameter from revive
2025-02-21 13:56:04 +01:00
Charles Korn
8356990709
promql: fix double quoting in invalid label name error from count_values (#16054)
promql: fix double quoting in invalid label name error from `count_values`

---------

Signed-off-by: Charles Korn <charles.korn@grafana.com>
Signed-off-by: Charles Korn <charleskorn@users.noreply.github.com>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
2025-02-21 00:37:04 +01:00
Björn Rabenstein
fcc8e49d65
Merge pull request #16018 from charleskorn/charleskorn/quantile_over_time-annotation
promql: emit correct annotation in `quantile_over_time` when run over a range with histograms and floats
2025-02-20 22:49:30 +01:00
Matthieu MOREL
c7d4b53ec1 chore: enable unused-parameter from revive
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-02-19 19:50:28 +01:00
Charles Korn
0964b6e584
promql: emit correct annotation in quantile_over_time when run over a range with histograms and floats
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2025-02-12 16:46:57 +11:00
Björn Rabenstein
906f6a33b6
Merge pull request #15987 from prometheus/beorn7/histogram
promql: Fix counter reset detection in subqueries with histograms
2025-02-11 20:41:19 +01:00
beorn7
14bb63c467 promql: Fix counter reset detection in subqueries with histograms
Signed-off-by: beorn7 <beorn@grafana.com>
2025-02-11 20:04:10 +01:00
beorn7
6518941d73 promql: Expose problem with histogram counter resets in subquery
Signed-off-by: beorn7 <beorn@grafana.com>
2025-02-11 20:04:10 +01:00
Matthieu MOREL
b472ce7010 chore: enable early-return from revive
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-02-10 22:08:43 +01:00
Neeraj Gartia
20371118b6
[FIX] PromQL: Ignore histograms in scalar, sort and sort_desc functions (#15964)
PromQL: Ignore histograms in scalar, sort and sort_desc functions

---------

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-02-06 16:02:03 +01:00
Björn Rabenstein
cb096a8ea8
Merge pull request #15902 from prometheus/beorn7/promql
promql: fix rate calculation with a counter reset after the 1st sample
2025-02-05 22:10:45 +01:00
Björn Rabenstein
fa1bd02c99
Merge pull request #15974 from jhesketh/jhesketh/utf-label-replace
Allow UTF-8 labels in label_replace
2025-02-05 20:49:36 +01:00
Joshua Hesketh
5a5fdea7ad
Fix duplicate output vector if delayed name removal is disabled (#15975)
Fix duplicate output vector if delayed name removal is disabled

This error is emitted in cleanupMetricLabels, but is skipped if
enableDelayedNameRemoval is false.

This makes it consistent with label_replace

Signed-off-by: Joshua Hesketh <josh@nitrotech.org>

---------

Signed-off-by: Joshua Hesketh <josh@nitrotech.org>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
2025-02-05 16:40:23 +01:00
Joshua Hesketh
5be3197701 Update the test to invalid utf-8
"invalid-label-name" is valid in utf-8 mode

Signed-off-by: Joshua Hesketh <josh@nitrotech.org>
2025-02-05 23:08:24 +11:00
Joshua Hesketh
e4037b3ec3 Allow UTF-8 labels in label_replace
This makes it consistent with label_join.

Signed-off-by: Joshua Hesketh <josh@nitrotech.org>
2025-02-05 22:24:13 +11:00
Charles Korn
69ce0c24db
Fix issue
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2025-02-05 11:48:47 +11:00
Charles Korn
2fc6ba1c94
Expand TestInstantQueryWithRangeVectorSelector to include histograms
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2025-02-05 11:45:16 +11:00
Charles Korn
026d0198d5
Add unit tests
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2025-02-05 11:40:54 +11:00
Neeraj Gartia
8be416a67c
[FIX] PromQL: Updates annotation for bin op between incompatible histograms (#15895)
PromQL: Updates annotation for bin op between incompatible histograms

---------

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-02-01 22:57:29 +01:00
Neeraj Gartia
130cd024e0
[FEATURE] PromQL: Implements idelta and irate with histograms (#15853)
Add native histogram support to idelta and irate functions

---------

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-01-31 23:11:03 +01:00
beorn7
9f6c1d9cd3 promqltest: Small formatting improvement for native histograms
A `HistogramTestExpression` was missed in one case, which made the
formatting weird in case a histogram got unexpectedly returned.

Signed-off-by: beorn7 <beorn@grafana.com>
2025-01-29 17:26:08 +01:00
beorn7
2581c7d057 promql: fix rate calculation with a counter reset after the 1st histogram
If a rate (or increase) is calculated on native histograms, and there
is a counter reset between the 1st and 2nd histogram, we never have to
touch the 1st histogram, so it doesn't even matter if it has an
incompatible bucket layout. So we should not error out in that case.

This simply nulls out the 1st histogram in that case.

Signed-off-by: beorn7 <beorn@grafana.com>
2025-01-29 15:42:47 +01:00
Jan Fajerski
d734afab4d
Merge pull request #15870 from NeerajGartia21/promql/func_over_time
PromQL: Adds tests for `sum_over_time` and `avg_over_time` with histograms
2025-01-28 15:52:09 +01:00
Neeraj Gartia
b9fcc81695 adds tests for timestamp()
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-01-28 02:10:36 +05:30
Neeraj Gartia
21afc0beb4 adds tests for sum_over_time and avg_over_time
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2025-01-28 02:05:30 +05:30