Commit graph

1502 commits

Author SHA1 Message Date
Bartlomiej Plotka
de56b4c528
Merge pull request #18263 from linasm/do-not-skip-buckets-if-trimming
fix(PromQL): do not skip histogram buckets when trimming
2026-03-10 12:37:57 +01:00
Linas Medziunas
5ba581748c fix(PromQL): do not skip histogram buckets when trimming
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-03-09 15:25:24 +02:00
Julien Pivotto
c2fc92e2f3 Fuzzing: Remove old go-fuzz infrastructure
After the migration to native Go fuzzing in PR #17393, this removes
the old dvyukov/go-fuzz based infrastructure. This enables a smooth
transition, because we can merge this pull request when upstream
OSS-Fuzz changes have been done.

This removes:
- promql/fuzz.go and promql/fuzz_test.go (old fuzz functions)
- promql/fuzz-data/ (old corpus files)

The new fuzzing infrastructure is in util/fuzzing/ and is now used
by the CI workflow.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-03-04 09:41:21 +01:00
Matthieu MOREL
45b9329e68
chore: fix emptyStringTest issues from gocritic (#18226)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2026-03-04 08:24:50 +01:00
Andrew Hall
3bda9a3396
promql: allow timestamp() to be wrapped as a step invariant depending on arguments (#17313)
Some timestamp functions can be safely wrapped as a step invariant.
Then once we do that we never need to check or unwrap at evaluation time.

For instance; `timestamp(metric @ 1)` is step invariant, whereas
`timestamp(abs(metric @ 1))` is not.

Currently all `timestamp` `*parser.Call` are excluded from being
considered step invariant since it is listed in the
`AtModifierUnsafeFunctions` map.

This PR adds an extra check for timestamp functions which consider
the arguments, and if the argument is a simple VectorSelector then
the entire `*parser.Call` can be safely wrapped as a step invariant.

Signed-off-by: Andrew Hall <andrew.hall@grafana.com>
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
2026-03-02 12:01:14 +00:00
Julien
02b1abab5e
Merge pull request #18189 from ringerc/log-trace-id
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Compliance testing (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
Add traceID to query logs
2026-02-26 17:06:48 +01:00
Bartlomiej Plotka
b53d7386d0
Merge pull request #17159 from linasm/optimize-join-performance-5
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Compliance testing (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
[PERF] PromQL: replace maps with slices and reuse matching data structures in VectorBinop/And/Or/Unless
2026-02-25 13:50:31 +00:00
Linas Medžiūnas
c317f9254e
chore(histogram): Move histogram trimming code out of engine.go (#18185)
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-25 09:10:42 +01:00
Craig Ringer
d4b00499e8 Add traceID to query logs
The query log embeds a spanID, but omits the traceID, making
log/trace correlation significantly more difficult.

Add the trace ID as well.

This might be better done with the otelslog wrapper in
https://github.com/go-slog/otelslog but this change is more
minimal.

This does not add trace and span IDs to other logging
emitted to Prometheus's standard logger during the processing
of activities in which traces may be active.

Fixes #18188

Signed-off-by: Craig Ringer <craig.ringer@enterprisedb.com>
2026-02-25 12:24:11 +13:00
George Krajcsovits
5d3f9ee39b
Merge pull request #17904 from linasm/trim_histogram
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Compliance testing (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
promql: Implement </ and >/ operators for trimming native histograms
2026-02-24 17:16:24 +01:00
Björn Rabenstein
b2e63376da
Merge pull request #18105 from mmorel-35/staticcheck
chore: enable staticcheck linter and update golangci-lint to 2.10.1
2026-02-19 12:44:00 +01:00
Linas Medžiūnas
5bd0d00f8c
PromQL: Add experimental histogram_quantiles variadic function (#17285)
Some checks failed
buf.build / lint and publish (push) Has been cancelled
CI / Go tests (push) Has been cancelled
CI / More Go tests (push) Has been cancelled
CI / Go tests with previous Go version (push) Has been cancelled
CI / UI tests (push) Has been cancelled
CI / Go tests on Windows (push) Has been cancelled
CI / Mixins tests (push) Has been cancelled
CI / Build Prometheus for common architectures (push) Has been cancelled
CI / Build Prometheus for all architectures (push) Has been cancelled
CI / Check generated parser (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / fuzzing (push) Has been cancelled
CI / codeql (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CI / Report status of build Prometheus for all architectures (push) Has been cancelled
CI / Publish main branch artifacts (push) Has been cancelled
CI / Publish release artefacts (push) Has been cancelled
CI / Publish UI on npm Registry (push) Has been cancelled
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Signed-off-by: beorn7 <beorn@grafana.com>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: beorn7 <beorn@grafana.com>
2026-02-18 17:32:29 +01:00
Matthieu MOREL
addc3dcb47 chore: enable staticcheck linter and update golangci-lint to 2.10.1
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2026-02-18 15:58:16 +00:00
Linas Medziunas
38a7befa14 Add test case with join
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-18 15:49:23 +02:00
Linas Medziunas
c753252028 Update/fix test comments
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-18 15:38:27 +02:00
Julien Pivotto
7d0a39ac93 chore(lint): enable wg.Go
Since our minimum supported go version is now go 1.25, we can use wg.Go.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-02-17 15:21:51 +01:00
Linas Medziunas
a448a5cfbf Use matching.Card == parser.CardOneToOne for slice selection
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-17 13:55:34 +02:00
zenador
8937cbd395
promql: info function: support multiple name matchers (#17968)
Some checks failed
buf.build / lint and publish (push) Has been cancelled
CI / Go tests (push) Has been cancelled
CI / More Go tests (push) Has been cancelled
CI / Go tests with previous Go version (push) Has been cancelled
CI / UI tests (push) Has been cancelled
CI / Go tests on Windows (push) Has been cancelled
CI / Mixins tests (push) Has been cancelled
CI / Build Prometheus for common architectures (push) Has been cancelled
CI / Build Prometheus for all architectures (push) Has been cancelled
CI / Check generated parser (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / fuzzing (push) Has been cancelled
CI / codeql (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CI / Report status of build Prometheus for all architectures (push) Has been cancelled
CI / Publish main branch artifacts (push) Has been cancelled
CI / Publish release artefacts (push) Has been cancelled
CI / Publish UI on npm Registry (push) Has been cancelled
* Add new test cases for multiple name matchers in PromQL info function
* Fix handling of multiple name matchers in PromQL info function

---------

Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2026-02-13 17:22:58 +01:00
Linas Medziunas
86248a5ceb Fix for nhcb +Inf bucket
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-13 16:43:25 +02:00
Linas Medziunas
c657e859e3 Fix for nhcb [-Inf; -x) bucket
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-13 16:21:12 +02:00
Linas Medziunas
9a6c170d15 Fix midpoint of NHCB 1st bucket
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-13 15:39:42 +02:00
Linas Medziunas
538ad96136 Don't use extra digits in expected float values
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-13 15:39:27 +02:00
Dan Cech
32922edd7b
enable experimental functions in promql benchmarks
Signed-off-by: Dan Cech <dcech@grafana.com>
2026-02-12 18:40:14 -05:00
Björn Rabenstein
b84d7dcc56
Merge pull request #18058 from zenador/fix-avg-over-time-nh
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
promql: fix avg_over_time for single native histogram
2026-02-11 12:42:27 +01:00
Martin Valiente Ainz
eb5a0e1eed
Refactor parse.go into an instance-based Parser interface
Signed-off-by: Martin Valiente Ainz <64830185+tinitiuset@users.noreply.github.com>
2026-02-11 11:21:49 +01:00
Martin Valiente Ainz
539936c861
Replace per-component parser options with default instance
Signed-off-by: Martin Valiente Ainz <64830185+tinitiuset@users.noreply.github.com>
2026-02-11 11:16:04 +01:00
Martin Valiente Ainz
af16f35ad6
PromQL: Refactor parser to use instance configuration instead of global flags
Parser configuration is now per-engine/API/loader and no longer uses package-level flags, so behavior is consistent and tests don't rely on save/restore of global variables.

Signed-off-by: Martin Valiente Ainz <64830185+tinitiuset@users.noreply.github.com>
2026-02-11 11:16:04 +01:00
Jeanette Tan
d2bb5605dc promql: Fix avg_over_time for single histogram
avg_over_time would produce +Inf count/sum and NaN zero bucket when
averaging a single histogram, because the count variable was initialized
to 0 instead of 1. This caused a division by zero at the end of the
function.

The float version of avg_over_time already correctly initializes count
to 1, this change makes the histogram version consistent with that.

Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2026-02-11 05:06:53 +08:00
Jeanette Tan
9fddb70b8c promql: Add test case for avg_over_time single histogram fix
Add regression test for the bug where avg_over_time with a single
histogram sample would produce +Inf count/sum and NaN zero bucket
due to division by zero. The test verifies that both regular
exponential histograms and native histograms with custom buckets
(NHCB) correctly return the histogram unchanged when averaging
a single sample.

Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2026-02-11 05:06:53 +08:00
Linas Medziunas
0615b6af4f Handle zero_bucket_only case (plus more tests)
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-10 16:02:01 +02:00
Linas Medziunas
5c49187719 Fix NHCB first bucket handling
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-10 14:37:13 +02:00
Linas Medziunas
34f71ba96f Detect more noop trimmings
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-10 14:32:30 +02:00
Linas Medziunas
b3066144d1 Add test cases trimming a biased zero bucket
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-10 13:42:24 +02:00
Linas Medziunas
16c801d04e Change interpolation within zero bucket
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-09 17:40:23 +02:00
Sasha
1dcdb07d30
promql: use Kahan summation for Native Histograms (#15687)
As for float samples, Kahan summation is used for the `sum` and `avg` aggregation and for the respective `_over_time` functions.

Kahan summation is not perfect. This commit also adds tests that even Kahan summation cannot reliably pass.
These tests are commented out.

Note that the behavior might be different on other hardware platforms. We have to keep an eye on test failing on other hardware platforms and adjust them accordingly.

Signed-off-by: Aleksandr Smirnov <5targazer@mail.ru>
2026-02-08 00:52:22 +01:00
Linas Medziunas
a3a52004ba Update native_histograms.test following the feedback
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-06 13:41:51 +02:00
Julien
eaf47798af
promql: fix panic with @ modifier on empty ranges (#18020)
When using the @ modifier with a timestamp that has no data, several
PromQL range functions were panicking with "index out of range [0]
with length 0". This was introduced by #16797 which changed function
signatures to use concrete types instead of interfaces.

The panic occurred because functions were accessing array elements
(matrixVal[0], vectorVals[0][0]) without checking if the arrays were
empty first.

Fixes #18018

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-02-06 08:30:15 +00:00
zenador
4321a5573c
Use custom annotation for histogram quantile monotonicity info to provide more details (#15578)
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2026-02-05 18:35:48 +01:00
Bryan Boreham
02c68154bc
Merge pull request #17548 from linasm/improve-BenchmarkJoinQuery
PromQL: Improve BenchmarkJoinQuery
2026-02-03 11:53:08 +00:00
Linas Medziunas
35aba0bbde Compute resulting sum based on surviving buckets
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-02-02 15:46:32 +02:00
Julien Pivotto
55193c3058 promql: fix smoothed interpolation across counter resets
Fix incorrect interpolation when counter resets occur in smoothed range
selector evaluation. Previously, the asymmetric handling of counter
resets (y1=0 on left edge, y2+=y1 on right edge) produced wrong values.

Now uniformly set y1=0 when a counter reset is detected, correctly
modeling the counter as starting from 0 post-reset.

This fixes rate calculations across counter resets. For example,
rate(metric[10s] smoothed) where metric goes from 100 to 10 (a reset)
now correctly computes 0.666... by treating the counter as resetting
to 0 rather than producing inflated values from the old behavior.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-02-02 11:54:35 +01:00
Linas Medziunas
b69ec3f39c Only track signs of surviving buckets
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-01-28 15:11:10 +02:00
Linas Medziunas
e6c07126a6 Midpoint of negative bucket must be negative
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-01-28 15:07:24 +02:00
Linas Medziunas
cde7bbf9e7 [PERF] PromQL: reuse matching data structures in VectorBinop/And/Or/Unless
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-01-28 09:39:30 +02:00
beorn7
b812c6457d promqltest: Document testing for counter reset hints in histograms
Signed-off-by: beorn7 <beorn@grafana.com>
2026-01-27 14:53:38 +01:00
Linas Medziunas
d0b7fe402f Edge test cases with Exponential Histogram
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-01-27 11:17:26 +02:00
Linas Medziunas
001fc1bfea Handle infinity buckets conservatively
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2026-01-27 09:37:27 +02:00
Arve Knudsen
65f8482335 fix(promql): prevent panic in trimStringByBytes on invalid UTF-8
Add bounds check to prevent index out of range panic when
trimStringByBytes receives a string containing only UTF-8 continuation
bytes (0x80-0xBF). Previously, the loop would decrement size below 0
when no valid rune start byte was found, causing a panic.

A malicious query string with only continuation bytes could crash
the Prometheus server via the ActiveQueryTracker before the query
was parsed or validated.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2026-01-24 16:06:42 +01:00
Bartlomiej Plotka
0d116b0994
tests(teststorage): Close Storage in the helper (#17902)
Signed-off-by: bwplotka <bwplotka@gmail.com>
2026-01-23 08:41:35 +00:00
zenador
9a49316c59
promql: info function: fix unit test for ignoring info metrics themselves (#17911)
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2026-01-22 15:24:41 +01:00