Skip to content

Prometheus: Add query_range REST endpoint backed by ES|QL PROMQL command#144294

Closed
felixbarny wants to merge 7 commits intoelastic:mainfrom
felixbarny:promql-query-range-endpoint
Closed

Prometheus: Add query_range REST endpoint backed by ES|QL PROMQL command#144294
felixbarny wants to merge 7 commits intoelastic:mainfrom
felixbarny:promql-query-range-endpoint

Conversation

@felixbarny
Copy link
Copy Markdown
Member

@felixbarny felixbarny commented Mar 16, 2026

Overview

This PR provides a full overview of the change. For easier reviewing, the implementation is split into focused PRs:

What this adds

A Prometheus-compatible /_prometheus/api/v1/query_range endpoint that:

  1. Accepts the standard Prometheus range query parameters (query, start, end, step, optional index).
  2. Translates the PromQL expression into an ES|QL PROMQL command and executes it via EsqlQueryAction.
  3. Converts the columnar ES|QL response into the Prometheus matrix JSON format and returns it to the caller.

Follow-up in #144416 switches the endpoint from query-string construction to direct execution of a parsed EsqlStatement plan.

@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team v9.4.0 needs:triage Requires assignment of a team area label labels Mar 16, 2026
@felixbarny felixbarny added >non-issue :StorageEngine/PromQL PromQL support for Elastic labels Mar 16, 2026
@elasticsearchmachine elasticsearchmachine added Team:StorageEngine and removed needs:triage Requires assignment of a team area label labels Mar 16, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

Switch the prometheus endpoint to use a parameterized ESQL_QUERY
constant instead of buildEsqlQuery(), and append
| EVAL step = TO_LONG(step) to avoid date-parsing ambiguity.
…ponseListener

Moves the shared column-name constants from PrometheusQueryRangeRestAction to
PrometheusQueryRangeResponseListener, which is the class that validates those
column names in the ES|QL response. PrometheusQueryRangeRestAction now
references them from the listener. This makes the listener independently
compilable and keeps the contract for expected column names in one place.
@felixbarny felixbarny force-pushed the promql-query-range-endpoint branch from 10009ee to 9a4f271 Compare March 16, 2026 10:24
felixbarny and others added 3 commits March 16, 2026 19:15
Allow internal callers to supply a pre-built EsqlStatement that
bypasses ES|QL string construction and parsing. EsqlSession now
checks for a parsed statement before invoking the parser.
Replace ES|QL string construction and parameter binding with a
directly constructed logical plan. This adds a Project node to
restore the original PromqlCommand column order after the Eval
that converts step to long.
@dnhatn
Copy link
Copy Markdown
Member

dnhatn commented Mar 18, 2026

@felixbarny Do we have a plan to also add an async endpoint for this?

@felixbarny
Copy link
Copy Markdown
Member Author

No, I don't think so. PromQL doesn't support any kind of async endpoint so there would be no consumers for it.

@dnhatn
Copy link
Copy Markdown
Member

dnhatn commented Mar 18, 2026

No, I don't think so. PromQL doesn't support any kind of async endpoint so there would be no consumers for it.

Yes, but this could become an issue with our Cloud given the 5-minute hard proxy timeout.

@felixbarny
Copy link
Copy Markdown
Member Author

I don't know what's the alternative to it though. This endpoint is mainly so that we can integrate well into other dashboarding systems that know how to deal with the query_range endpoint already. If we made a query_range_asyc endpoint, who would be the consumer of that? At that point, clients could just use the ES|QL /_query/async endpoint with a PROMQL or even a TS command.

@dnhatn
Copy link
Copy Markdown
Member

dnhatn commented Mar 18, 2026

At that point, clients could just use the ES|QL /_query/async endpoint with a PROMQL or even a TS command.

Yeah, I think we can skip the async endpoint for this now.

Copy link
Copy Markdown
Contributor

@kkrik-es kkrik-es left a comment

Choose a reason for hiding this comment

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

Nice.

@felixbarny
Copy link
Copy Markdown
Member Author

Closing this PR as this was just meant to provide an overview and how the pieces fit together. Superseded by the sub-PRs.

@felixbarny felixbarny closed this Mar 19, 2026
@felixbarny felixbarny deleted the promql-query-range-endpoint branch March 19, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor Pull request authored by a developer outside the Elasticsearch team >non-issue :StorageEngine/PromQL PromQL support for Elastic Team:StorageEngine v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants