Commit graph

259 commits

Author SHA1 Message Date
Julien Pivotto
710dbb74c9 promql/parser: fix symmetric fill detection to compare values not pointers
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-06-03 15:33:23 +02:00
Julien
6926f90224
Merge pull request #18767 from roidelapluie/roidelapluie/fuzz-parseexpr-unexpected-error
fuzzing: detect parser runtime panics in FuzzParseExpr
2026-05-22 18:08:56 +02:00
Julien Pivotto
cec97e5948 promql/parser: extract helpers to reduce duplication in duration expression parsing
Add durationLiteralOutOfRange to centralise the int64 nanosecond overflow
check for numeric duration literals, replacing three identical inline
conditions in the grammar.

Add applyUnaryOpToDurationExpr to handle the unary +/- type-switch over
*DurationExpr/*NumberLiteral, collapsing two near-identical grammar
action blocks (offset_duration_expr and duration_expr) into single calls.

Regenerate generated_parser.y.go.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-22 17:29:46 +02:00
Julien Pivotto
5a152e815e promql/parser: fix panic on parenthesised number in offset_duration_expr
The `unary_op LEFT_PAREN duration_expr RIGHT_PAREN` production in
`offset_duration_expr` unconditionally asserted `$3.(*DurationExpr)`,
but `duration_expr` can also reduce to a `*NumberLiteral` (e.g. the
literal `0` or `5` inside parentheses).  This caused a runtime panic
recoverable only by the top-level recover in parse.go, which surfaced
as an opaque "unexpected error".

Replace the hard type-assertion with a type switch matching the same
pattern used by the `unary_op duration_expr` production in
`duration_expr`: handle `*DurationExpr` (set Wrapped, negate if SUB)
and `*NumberLiteral` (negate value if SUB, range-check, update pos),
with a fallback parse error for unexpected node types.

Regenerate generated_parser.y.go from the updated grammar.

Add regression tests: `foo offset +(5)` and `foo offset -(5)` now
parse correctly as ±5 s offsets.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-22 17:13:17 +02:00
Julien Pivotto
7a70afb5a4 fuzzing: detect parser runtime panics in FuzzParseExpr
Export ErrUnexpected from the parser package so the fuzz test can use
errors.Is to detect when the parser's recover() handler caught a
runtime panic. Previously these were silently swallowed; now
FuzzParseExpr fails on them.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-22 17:04:02 +02:00
Julien
f7bd18d767
Merge pull request #18764 from roidelapluie/roidelapluie/fix-smoothed-anchored-panic
promql/parser: fix panic in setAnchored/setSmoothed for non-selector ranges
2026-05-22 16:36:07 +02:00
Julien Pivotto
e84ac82175 promql/parser: fix panic in setAnchored/setSmoothed for non-selector ranges
When a MatrixSelector wraps a non-VectorSelector expression (e.g. `1[5m]`),
the grammar records a parse error but continues. The unchecked type assertions
in setAnchored and setSmoothed then panic. Use safe assertions and emit a
parse error instead.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-22 15:39:28 +02:00
Julien Pivotto
a74f0b2e7a PromQL: Rename greatest, least, to max_of, min_of.
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-19 13:07:16 +02:00
Julien Pivotto
7af21f195c promql: add least() and greatest() scalar functions
Implement least(a, b) and greatest(a, b) as scalar-returning PromQL
functions backed by math.Min and math.Max respectively.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-18 11:15:31 +02:00
Julien Pivotto
76c859969d promql: rename min/max duration expr functions to least/greatest
Rename the `min()` and `max()` duration expression functions to
`least()` and `greatest()` to avoid conflicts with the existing
PromQL aggregate functions `min` and `max`.

Update documentation and tests accordingly.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-13 17:35:52 +02:00
Julien Pivotto
502e31a82f promql: protect min(), max(), step(), and range() duration exprs with feature flag
min(), max(), step(), and range() in duration expression context were
not guarded by the ExperimentalDurationExpr feature flag, unlike the
binary operators (+, -, *, /, %, ^). Add the missing
experimentalDurationExpr() calls in both offset_duration_expr and
duration_expr grammar rules.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-13 09:59:50 +02:00
Julien Pivotto
7b29b912e3 Revert "PromQL: Promote duration expressions as stable"
This reverts commit 1463a5bb5a.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-13 09:59:50 +02:00
Julien
8c3cc3323c
Merge pull request #18646 from roidelapluie/roidelapluie/debugstatement
promql/parser: remove debug print statements from DurationExpr.Pretty
2026-05-08 13:43:27 +02:00
Julien Pivotto
a133c21326 promql/parser: remove debug print statements from DurationExpr.Pretty
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-08 13:13:34 +02:00
Julien
21dc203599
Merge pull request #18578 from ProjectMutilation/promql-fix-potential-panic
promql: prevent nil pointer dereference in DurationExpr.PositionRange
2026-05-08 11:39:27 +02:00
Maksim Korotkov
e4e65d1247 promql: prevent nil pointer dereference in DurationExpr.PositionRange
Fixed a bug in the `PositionRange` method where a panic occurred when `e.RHS` was nil.
Previously, the code checked `if e.RHS == nil` but then immediately
accessed `e.RHS.PositionRange().End`, causing a runtime error.

This commit updates the logic to correctly use `e.LHS.PositionRange().End`
when the RHS is missing.

Fixes: ee7d5158a ("Add step(), min(a,b) and max(a,b) in promql duration expressions")
Found by PostgresPro with the Svace static analyzer.

Signed-off-by: Maksim Korotkov <m.korotkov@postgrespro.ru>
2026-05-07 00:10:24 +03:00
Julien Pivotto
8739d37781 promql/parser: use map-based dispatch for duration keyword lexing
Replace the hardcoded switch over start characters and keyword names with
a map-driven approach. durationKeywordTokens maps lowercase keyword strings
to their token types, and isDurationKeywordStartChar derives the valid start
characters from that map, so adding a new duration keyword only requires one
change instead of three.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-06 13:16:56 +02:00
Julien Pivotto
483db9310d promql/parser: recognize range in duration expressions
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-05-06 12:42:42 +02:00
Julien Pivotto
1463a5bb5a PromQL: Promote duration expressions as stable
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-04-24 18:45:09 +02:00
Julien
5d0bc055ef
Merge pull request #17877 from roidelapluie/roidelapluie/funcs
PromQL: Add start() end() range() and step() functions
2026-04-17 13:51:37 +02:00
Julien Pivotto
ae9e52c868 PromQL: Add start() end() range() and step() functions
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-04-16 10:59:23 +02:00
Matthieu MOREL
44d617c671
build: update golangci-lint version to v2.11.4 (#18480)
fix(promql/parser): improve Pretty method for Expressions to handle empty cases

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2026-04-10 07:20:15 +02:00
Julien Pivotto
efe305b898 fuzzing: generate libFuzzer dictionary for FuzzParseExpr
Export parser.Keywords() and add GetDictForFuzzParseExpr() so that
the corpus generator can produce a stable fuzzParseExpr.dict file
derived directly from the PromQL grammar rather than maintained by hand.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-04-08 17:38:23 +02: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
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
Björn Rabenstein
82fec75982
Merge pull request #17626 from aviralgarg05/fix-promqltest-counter-reset-hint-comparison
promqltest: Add optional counter reset hint comparison for native histograms
2026-01-22 15:03:20 +01:00
sujal shah
e8bfcfcf1a promql: Implement </ and >/ operators for trimming native histograms.
This implements the TRIM_UPPER (</) and TRIM_LOWER (>/) operators
that allow removing observations below or above a threshold from
a histogram. The implementation zeros out buckets outside the desired
range. It also recalculates the sum, including only bucket counts within
the specified threshold range.

Fixes #14651.

Signed-off-by: sujal shah <sujalshah28092004@gmail.com>
2026-01-22 15:22:43 +02:00
Julius Volz
d3b6e61487 Put binop fill modifiers behind a feature flag
Some checks failed
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
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: Julius Volz <julius.volz@gmail.com>
2026-01-15 11:18:48 +01:00
Julius Volz
af3277f832 PromQL: Add fill*() binop modifiers to provide default values for missing series
Signed-off-by: Julius Volz <julius.volz@gmail.com>
2026-01-15 07:56:21 +01:00
Ben Kochie
e14795bbf4
Remove copyright date from headers (#17785)
Remove copyright dates from various files as part of [PROM-50].

[PROM-50]: https://github.com/prometheus/proposals/blob/main/proposals/0050-remove-copyright-dates.md

Signed-off-by: SuperQ <superq@gmail.com>
2026-01-05 13:46:21 +01:00
Julius Volz
9da9e6daf4
Merge pull request #17687 from ADITYATIWARI342005/fix/utf8
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/parser: fix UTF-8 label quoting in format_query endpoint
2025-12-28 12:08:07 +01:00
aviralgarg05
119e75d78b promqltest: Properly distinguish explicit counter_reset_hint specification
This commit addresses the PR feedback for issue #17615. The previous
implementation could not distinguish between:
- No counter reset hint specified (meaning "don't care")
- counter_reset_hint:unknown explicitly specified (meaning "verify it's unknown")

Changes:
- Added CounterResetHintSet field to parser.SequenceValue to track
  whether counter_reset_hint was explicitly specified in the test file
- Modified buildHistogramFromMap to set this flag when the hint is
  present in the descriptor map
- Updated newHistogramSequenceValue helper and histogramsSeries
  functions to propagate the flag through histogram series creation
- Updated yacc grammar to use the new helper function
- Modified compareNativeHistogram to accept the flag and only compare
  hints when explicitly specified

This allows tests to:
1. Not specify a hint (no comparison, backward compatible)
2. Explicitly specify counter_reset_hint:unknown (verify it's unknown)
3. Explicitly specify counter_reset_hint:gauge/reset/not_reset (verify match)

Fixes #17615

Signed-off-by: aviralgarg05 <gargaviral99@gmail.com>
2025-12-19 23:32:08 +05:30
ADITYA TIWARI
3a82dcc6c5 promql/parser: simplify BinaryExpr label formatting
Signed-off-by: ADITYA TIWARI <adityatiwari342005@gmail.com>
2025-12-16 12:31:39 +00:00
Aditya Tiwari
301b9eff44 Update comments to clarify label formatting method
Signed-off-by: Aditya Tiwari <142050150+ADITYATIWARI342005@users.noreply.github.com>
2025-12-16 12:31:39 +00:00
ADITYA TIWARI
2e4f5e8cfc promql/parser: consolidate label quoting logic
refactors binary expression formatting to reuse writeLabels() instead
of maintaining separate joinLabels() function. adds comprehensive
UTF-8 label tests for all expression types

Signed-off-by: ADITYA TIWARI <adityatiwari342005@gmail.com>
2025-12-16 12:31:39 +00:00
ADITYA TIWARI
5b299ef99e fix/promql/parser: Fix utf-8 label quoting in format_query endpoint
Signed-off-by: ADITYA TIWARI <adityatiwari342005@gmail.com>
2025-12-16 12:31:39 +00:00
Julien Pivotto
d0b122a711 PromQL: duration expression: add range()
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2025-12-10 16:27:18 +01:00
Julien
f73aba34cd
Merge pull request #17427 from roidelapluie/roidelapluie/ffapi
API: Add a /api/v1/features endpoint
2025-12-10 10:14:03 +01:00
Julien Pivotto
a5671a002f API: Add a /api/v1/features endpoint
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2025-12-09 16:13:14 +01:00
dongjiang
3239723098
Update golangci-lint and add modernize check (#17640)
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 modernize check

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>

* fix golangci lint

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>

---------

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
2025-12-05 09:29:10 +01:00
Julius Volz
39e11f50b2 Fix serialization for empty ignoring() in combination with group_x()
Currently both the backend and frontend printers/formatters/serializers
incorrectly transform the following expression:

```
up * ignoring() group_left(__name__) node_boot_time_seconds
```

...into:

```
up * node_boot_time_seconds
```

...which yields a different result (including the metric name in the result
vs. no metric name).

We need to keep empty `ignoring()` modifiers if there is a grouping modifier
present.

Signed-off-by: Julius Volz <julius.volz@gmail.com>
2025-12-03 14:15:16 +01:00
Ben Kochie
204249fcb5
Update golangci-lint (#17478)
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
* Update golangci-lint to v2.6.0
* Fixup various linting issues.
* Fixup deprecations.
* Add exception for `labels.MetricName` deprecation.

Signed-off-by: SuperQ <superq@gmail.com>
2025-11-05 13:47:34 +01:00
Ben Kochie
48956f60d7
Update modernize (#17471)
Apply additional Go modernize tool improvements.

Signed-off-by: SuperQ <superq@gmail.com>
2025-11-04 05:13:49 +00:00
Julius Volz
5318689046
Merge pull request #17380 from roidelapluie/roidelapluie/fixat
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/parser: Add string representation for AT token
2025-10-27 16:21:14 +01:00
Linas Medžiūnas
b2e7938e25
[BUGFIX] PromQL: avoid panic parsing malformed info call (#17379)
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
2025-10-23 09:42:19 +02:00