Prometheus: execute query_range via parsed EsqlStatement plan#144416
Merged
felixbarny merged 11 commits intoelastic:mainfrom Mar 26, 2026
Merged
Prometheus: execute query_range via parsed EsqlStatement plan#144416felixbarny merged 11 commits intoelastic:mainfrom
felixbarny merged 11 commits intoelastic:mainfrom
Conversation
This was referenced Mar 17, 2026
83aa788 to
a4ff343
Compare
a4ff343 to
1452692
Compare
Move the logical plan construction logic into a dedicated PromqlQueryPlanBuilder class, and add a matching test class with assertions on index pattern and query.
4e0de4e to
b108e1a
Compare
Keep PreparedEsqlQueryRequest approach from HEAD; pass the `index` path parameter to PromqlQueryPlanBuilder instead of the hardcoded "*".
- Pass query description to PreparedEsqlQueryRequest.sync (new required arg added in elastic#144415) - Pass index path param instead of hardcoded "*" to PromqlQueryPlanBuilder - Add INDEX_PARAM constant; replace unused EsqlQueryRequest import with PreparedEsqlQueryRequest
The Project node captured _timeseries attribute IDs at plan-build time.
After analysis, the promqlPlan inside PromqlCommand is transformed
(label matchers get resolved), creating a new InstantSelector instance
whose output() produces a fresh TimeSeriesMetadataAttribute with a new
NameId. The pre-built Project then referenced a stale ID, causing
PlanConsistencyChecker to report "optimized incorrectly due to missing
references [_timeseries{f}#N]".
The Project was also selecting the wrong step column: it kept
step(datetime) and discarded step_alias(long), so the response listener
never received step as a long at the last column position.
The fix: remove the Project entirely. Eval.mergeOutputAttributes already
produces the correct output — it drops step(datetime) because the
step_alias shadows it by name, then appends step_alias(long) at the end,
giving [value, ...dimensions, step(long)] as the listener expects.
a8ee806 to
d853bfa
Compare
Collaborator
|
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
Add an OrderBy(step ASC) node in PromqlQueryPlanBuilder so that values within each series are returned in chronological order. The AddImplicitLimit analyzer rule supplies the required bounding Limit(1_000_000) that ES|QL's plan verifier expects. Add ascending-timestamp assertions to PrometheusQueryRangeRestIT.
sidosera
approved these changes
Mar 25, 2026
This was referenced Mar 26, 2026
kkrik-es
approved these changes
Mar 26, 2026
kkrik-es
approved these changes
Mar 26, 2026
szybia
added a commit
to szybia/elasticsearch
that referenced
this pull request
Mar 26, 2026
* upstream/main: (146 commits) Revert "[Native] Gradle-related tweaks to improve handling of the simdvec native library (elastic#144539)" Fix ArrayIndexOutOfBoundsException in fetch phase with partial results (elastic#144385) ESQL: Correctly manage NULL data type for SUM (elastic#144942) [ESQL] Fixes GroupedTopNBenchmark not executing (elastic#144944) Fix reader context leak when query response serialization fails (elastic#144708) Validate individual offset values in BULK_OFFSETS bounds checks (elastic#144643) Merge main21 source set into main in simdvec (elastic#144921) [TEST] Unmute TsidExtractingIdFieldMapperTests (elastic#144848) [Native] Gradle-related tweaks to improve handling of the simdvec native library (elastic#144539) Fix `ThreadedActionListenerTests#testRejectionHandling` (elastic#144795) Add new DLM Frozen Tier Transition execution plugin and service (elastic#144595) Prometheus: execute query_range via parsed EsqlStatement plan (elastic#144416) Investigate `testBulkIndexingRequestSplitting` failure (elastic#144766) Add test utility for wrapping directories in FilterDirectory layer (elastic#143563) Fix ES|QL decay tests with negative scale (elastic#144657) Fix circuit breaker leak in percolator query construction (elastic#144827) Use XPerFieldDocValuesFormat in AbstractTSDBSyntheticIdCodec (elastic#144744) [DOCS] Document how reindex work in CPS (elastic#144016) Fix Int4 vector library tests failing on Java 21 (elastic#144830) [DiskBBQ] Fix index sorting on flush (elastic#144938) ...
seanzatzdev
pushed a commit
to seanzatzdev/elasticsearch
that referenced
this pull request
Mar 26, 2026
…c#144416) Move the logical plan construction logic into a dedicated PromqlQueryPlanBuilder class, and add a matching test class with assertions on index pattern and query.
seanzatzdev
pushed a commit
to seanzatzdev/elasticsearch
that referenced
this pull request
Mar 27, 2026
…c#144416) Move the logical plan construction logic into a dedicated PromqlQueryPlanBuilder class, and add a matching test class with assertions on index pattern and query.
mamazzol
pushed a commit
to mamazzol/elasticsearch
that referenced
this pull request
Mar 30, 2026
…c#144416) Move the logical plan construction logic into a dedicated PromqlQueryPlanBuilder class, and add a matching test class with assertions on index pattern and query.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR updates the
query_rangeendpoint to build and execute a pre-built ES|QLEsqlStatementinstead of constructing/parsing an ES|QL query string.Key changes
PromqlCommand-based logical plan directly inPrometheusQueryRangeRestActionstepwithTO_LONG(step)in-plan and add a projection to preserve original output orderPrometheusQueryRangeResponseListenerand related tests for the updated output contractStacking order
/api/v1/query_range) endpoint #144303