Skip to content

PromQL: Refactor parser to use instance configuration instead of global flags#17977

Merged
roidelapluie merged 4 commits into
prometheus:mainfrom
tinitiuset:tinitiuset/parser-configuration
Feb 11, 2026
Merged

PromQL: Refactor parser to use instance configuration instead of global flags#17977
roidelapluie merged 4 commits into
prometheus:mainfrom
tinitiuset:tinitiuset/parser-configuration

Conversation

@tinitiuset

Copy link
Copy Markdown
Contributor

This PR addresses the package-level parser flags. They are now configured per engine/API/loader via parser.Options and WithOptions(...).

  • Updated test so they no longer rely on overriding global package variables.
  • Parser config is thread-safe and per-instance.

Which issue(s) does the PR fix:

Fixes #17874

Does this PR introduce a user-facing change?

NONE

@tinitiuset
tinitiuset force-pushed the tinitiuset/parser-configuration branch 2 times, most recently from ce83e52 to 01bfd18 Compare January 30, 2026 18:59
@tinitiuset
tinitiuset marked this pull request as ready for review January 30, 2026 19:33
@tinitiuset
tinitiuset requested review from a team, dgl and roidelapluie as code owners January 30, 2026 19:33
@roidelapluie

Copy link
Copy Markdown
Member

I believe we should have a unique parser accross the whole binary, not one for each section, WDYT?

@tinitiuset

Copy link
Copy Markdown
Contributor Author

Yes, I think that's fair. It's also cleaner now IMO.

@tinitiuset
tinitiuset force-pushed the tinitiuset/parser-configuration branch 2 times, most recently from e38f06f to c8e0b6f Compare February 2, 2026 16:46
Comment thread promql/parser/features.go Outdated
Comment thread cmd/promtool/main.go Outdated
Comment thread cmd/prometheus/main.go Outdated

@roidelapluie roidelapluie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here's my opinion:

We should have promqlParser := parser.NewParser() and pass it where needed (rules, query, web, ..).

Inside of the Parser package, Parser could be an interface and NewParser would return the PromQL implementation.

@tinitiuset
tinitiuset force-pushed the tinitiuset/parser-configuration branch from 53b40cc to d149c3f Compare February 11, 2026 10:12
…al 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 <[email protected]>
@tinitiuset
tinitiuset force-pushed the tinitiuset/parser-configuration branch from d149c3f to 4ab58fa Compare February 11, 2026 10:16
@tinitiuset
tinitiuset force-pushed the tinitiuset/parser-configuration branch from 4ab58fa to eb5a0e1 Compare February 11, 2026 10:22

@roidelapluie roidelapluie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@roidelapluie
roidelapluie merged commit 7d40cd4 into prometheus:main Feb 11, 2026
32 checks passed
tinitiuset added a commit to tinitiuset/prometheus that referenced this pull request Feb 16, 2026
… rules

Both are regressions from the parser refactoring in prometheus#17977.

- Fixes prometheus#18092
- Fixes prometheus#18093

Signed-off-by: Martin Valiente Ainz <[email protected]>
aknuds1 pushed a commit that referenced this pull request Feb 16, 2026
… rules (#18097)

Both are regressions from the parser refactoring in #17977.

- Fixes #18092
- Fixes #18093

Signed-off-by: Martin Valiente Ainz <[email protected]>
bwplotka added a commit that referenced this pull request Feb 23, 2026
* Isolate fix: Remove 5s sleep for 99% speedup. Discarded unwanted code.

Signed-off-by: 3Juhwan <[email protected]>
Signed-off-by: Sammy Tran <[email protected]>

* Add regex optimization for simple contains alternations

Signed-off-by: Casie Chen <[email protected]>

* enable experimental functions in promql benchmarks

Signed-off-by: Dan Cech <[email protected]>

* Fix a couple of broken links in configuration.md (#18045)

Signed-off-by: kakabisht <[email protected]>

* promql: info function: support multiple name matchers (#17968)

* 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 <[email protected]>

* tsdb: Optimize LabelValues for sparse intersections (Fixes #14551)

Signed-off-by: Divyansh Mishra <[email protected]>

* fix: handle ErrTooOldSample as 400 Bad Request in OTLP and v2 histogram write paths

The OTLP write handler and the PRW v2 histogram append path were missing
ErrTooOldSample from their error type checks, causing these errors to
fall through to the default case and return HTTP 500 Internal Server Error.
This triggered unnecessary retries in OTLP clients like the Python SDK.

The PRW v1 write handler (line 115) and the PRW v2 sample append path
(line 377) already correctly handle ErrTooOldSample as a 400, and this
change makes the remaining paths consistent.

Also adds ErrTooOldSample to the v1 sample/histogram log checks so
these errors are properly logged instead of silently returned.

Fixes #16645

Signed-off-by: Varun Chawla <[email protected]>

* fix: prevent stale exemplars leaking to histogram _sum/_count across data points (#18056)

In addHistogramDataPoints, exemplars assigned to the +Inf bucket of one
data point were carried over into the _sum and _count Append calls of
the next data point via the shared appOpts. Clear appOpts.Exemplars at
the start of each loop iteration to restore the nil-exemplar semantics
that existed before the AppenderV2 migration.

Signed-off-by: Arve Knudsen <[email protected]>

* tsdb: fix flaky TestBlockRanges by using explicit compaction

Replace polling loops (for range 100 { time.Sleep }) with explicit
db.Compact() calls after disabling background compaction, eliminating
CI flakiness on slow machines. Also fix incorrect overlap assertions
that were checking the wrong direction (LessOrEqual -> GreaterOrEqual).

Signed-off-by: Arve Knudsen <[email protected]>

* rules: fix flaky TestAsyncRuleEvaluation on Windows (#17965)

Convert all timing-sensitive subtests of TestAsyncRuleEvaluation to use
synctest for deterministic testing. This fixes flakiness on Windows
caused by timer granularity and scheduling variance.

The timing assertions are preserved using synctest's fake time, which
allows accurate verification of sequential vs concurrent execution
timing without relying on wall-clock time.

Fixes #17961

Signed-off-by: Arve Knudsen <[email protected]>

* Move krajorama to general maintainer (#18095)

He's been participating in the bug scrub for a year and provides
reviews all over the code base. Also fix name spelling.

Signed-off-by: György Krajcsovits <[email protected]>

* promtool: fix --enable-feature flags ignored in check config and test rules (#18097)

Both are regressions from the parser refactoring in #17977.

- Fixes #18092
- Fixes #18093

Signed-off-by: Martin Valiente Ainz <[email protected]>

* tsdb/wlog: Remove any temproary checkpoints when creating a Checkpoint (#17598)

* RemoveTmpDirs function to tsdbutil
* Refactor db to use RemoveTmpDirs and no longer cleanup checkpoint tmp dirs
* Use RemoveTmpDirs in wlog checkpoint to cleanup all checkpoint tmp folders
* Add tests for RemoveTmpDirs
* Ensure db.Open will still cleanup extra temporary checkpoints

Signed-off-by: Kyle Eckhart <[email protected]>

* 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 <[email protected]>

* chore: enable staticcheck linter and update golangci-lint to 2.10.1

Signed-off-by: Matthieu MOREL <[email protected]>

* PromQL: Add experimental histogram_quantiles variadic function (#17285)

Signed-off-by: Linas Medziunas <[email protected]>
Signed-off-by: Björn Rabenstein <[email protected]>
Signed-off-by: beorn7 <[email protected]>
Co-authored-by: Björn Rabenstein <[email protected]>
Co-authored-by: beorn7 <[email protected]>

* Upgrade `mongo-driver` to v1.17.9 (#18077)

Signed-off-by: Sayuru <[email protected]>

* tests: add CI job for ompliance testing (#18121)

Signed-off-by: bwplotka <[email protected]>

* chore: Add consistent closing logging (#18119)

Signed-off-by: bwplotka <[email protected]>

* fix(deps): update github.com/hashicorp/nomad/api digest to daca79d (#18128)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update aws go dependencies (#18135)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Fix renovate PR body (#18154)

* chore(deps): update actions/stale action to v10.2.0 (#18144)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update actions/setup-node action to v6.2.0 (#18143)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update github/codeql-action action to v4.32.4 (#18147)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update kubernetes go dependencies to v0.35.1 (#18136)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependabot/fetch-metadata action to v2.5.0 (#18145)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update module github.com/prometheus/alertmanager to v0.31.1 (#18142)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update module github.com/klauspost/compress to v1.18.4 (#18138)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update github.com/nsf/jsondiff digest to 8e8d90c (#18129)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update google.golang.org/genproto/googleapis/api digest to 42d3e9b (#18132)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Fixup renovate PR note (#18156)

* fix(deps): update module golang.org/x/sys to v0.41.0 (#18163)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update module github.com/grpc-ecosystem/grpc-gateway/v2 to v2.28.0 (#18159)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update module github.com/envoyproxy/go-control-plane/envoy to v1.37.0 (#18158)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update module github.com/digitalocean/godo to v1.175.0 (#18157)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update module google.golang.org/api to v0.267.0 (#18165)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [FEATURE] AWS SD:  Add Elasticache Role (#18099)

* AWS SD: Elasticache

This change adds Elasticache to the AWS SD.

Co-authored-by: Ben Kochie <[email protected]>
Signed-off-by: Matt <[email protected]>

---------

Signed-off-by: Matt <[email protected]>
Co-authored-by: Ben Kochie <[email protected]>

* fix(deps): update module golang.org/x/text to v0.34.0 (#18164)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update module github.com/envoyproxy/protoc-gen-validate to v1.3.3 (#18137)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix test after merge

Signed-off-by: bwplotka <[email protected]>

---------

Signed-off-by: 3Juhwan <[email protected]>
Signed-off-by: Sammy Tran <[email protected]>
Signed-off-by: Casie Chen <[email protected]>
Signed-off-by: Dan Cech <[email protected]>
Signed-off-by: kakabisht <[email protected]>
Signed-off-by: Jeanette Tan <[email protected]>
Signed-off-by: Divyansh Mishra <[email protected]>
Signed-off-by: Varun Chawla <[email protected]>
Signed-off-by: Arve Knudsen <[email protected]>
Signed-off-by: György Krajcsovits <[email protected]>
Signed-off-by: Martin Valiente Ainz <[email protected]>
Signed-off-by: Kyle Eckhart <[email protected]>
Signed-off-by: Julien Pivotto <[email protected]>
Signed-off-by: Matthieu MOREL <[email protected]>
Signed-off-by: Linas Medziunas <[email protected]>
Signed-off-by: Björn Rabenstein <[email protected]>
Signed-off-by: beorn7 <[email protected]>
Signed-off-by: Sayuru <[email protected]>
Signed-off-by: bwplotka <[email protected]>
Signed-off-by: Matt <[email protected]>
Co-authored-by: 3Juhwan <[email protected]>
Co-authored-by: Casie Chen <[email protected]>
Co-authored-by: Dan Cech <[email protected]>
Co-authored-by: hridyesh bisht <[email protected]>
Co-authored-by: Julien <[email protected]>
Co-authored-by: zenador <[email protected]>
Co-authored-by: Divyansh Mishra <[email protected]>
Co-authored-by: Varun Chawla <[email protected]>
Co-authored-by: Arve Knudsen <[email protected]>
Co-authored-by: George Krajcsovits <[email protected]>
Co-authored-by: Martin Valiente Ainz <[email protected]>
Co-authored-by: Bryan Boreham <[email protected]>
Co-authored-by: Kyle Eckhart <[email protected]>
Co-authored-by: Matthieu MOREL <[email protected]>
Co-authored-by: Linas Medžiūnas <[email protected]>
Co-authored-by: Björn Rabenstein <[email protected]>
Co-authored-by: beorn7 <[email protected]>
Co-authored-by: Sayuru <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Ben Kochie <[email protected]>
Co-authored-by: Matt <[email protected]>
codeboten pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this pull request Apr 9, 2026
#### Description

This PR bumps the Prometheus dependency to v0.311.1 and addresses API
breaking changes.

The breaking changes identified were: 
* prometheus/prometheus#18067 - Changes a
private field, so it's not really an API breaking change. But somehow we
manage to depend even on private fields 😅
* prometheus/prometheus#17977 - Refactors PromQL
parser and updates the web API signature to depend on the parser
* prometheus/prometheus#18362 - Adds a replace
directive because one of Prometheus dependencies requires older versions
of `github.com/go-openapi/testify/v2`

---------

Signed-off-by: Arthur Silva Sens <[email protected]>
AndrewCharlesHay pushed a commit to AndrewCharlesHay/opentelemetry-collector-contrib that referenced this pull request Apr 23, 2026
#### Description

This PR bumps the Prometheus dependency to v0.311.1 and addresses API
breaking changes.

The breaking changes identified were: 
* prometheus/prometheus#18067 - Changes a
private field, so it's not really an API breaking change. But somehow we
manage to depend even on private fields 😅
* prometheus/prometheus#17977 - Refactors PromQL
parser and updates the web API signature to depend on the parser
* prometheus/prometheus#18362 - Adds a replace
directive because one of Prometheus dependencies requires older versions
of `github.com/go-openapi/testify/v2`

---------

Signed-off-by: Arthur Silva Sens <[email protected]>
bruegth pushed a commit to bruegth/opentelemetry-collector-contrib that referenced this pull request Jul 22, 2026
#### Description

This PR bumps the Prometheus dependency to v0.311.1 and addresses API
breaking changes.

The breaking changes identified were: 
* prometheus/prometheus#18067 - Changes a
private field, so it's not really an API breaking change. But somehow we
manage to depend even on private fields 😅
* prometheus/prometheus#17977 - Refactors PromQL
parser and updates the web API signature to depend on the parser
* prometheus/prometheus#18362 - Adds a replace
directive because one of Prometheus dependencies requires older versions
of `github.com/go-openapi/testify/v2`

---------

Signed-off-by: Arthur Silva Sens <[email protected]>
@GiedriusS

Copy link
Copy Markdown
Contributor

After this, I think there's no other way to add custom functions except to modify parser.Functions (no more func WithFunctions(functions map[string]*Function) Opt {). Is this intended?

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.

PromQL: Refactor parser to use instance configuration instead of global flags

3 participants