Skip to content

PromQL: auto-bucketing for step#142582

Merged
felixbarny merged 2 commits intoelastic:mainfrom
felixbarny:promql-auto-step
Feb 17, 2026
Merged

PromQL: auto-bucketing for step#142582
felixbarny merged 2 commits intoelastic:mainfrom
felixbarny:promql-auto-step

Conversation

@felixbarny
Copy link
Copy Markdown
Member

@felixbarny felixbarny commented Feb 17, 2026

This PR adds automatic step derivation for PromQL range queries in ES|QL when step is omitted. The goal is to reduce query boilerplate while keeping bucketed results deterministic.

Range queries can now provide buckets=<n> instead of step, and when neither parameter is provided the parser defaults to buckets=100. During translation to ES|QL, the effective step duration is derived from the same date-rounding logic used by BUCKET over [start, end, buckets], and then used to build the step column. For example, start=00:00, end=00:01, buckets=3 produces steps at 00:00, 00:20, and 00:40; with default buckets over one minute, the inferred step is 10 seconds.

The change also tightens parameter validation: step and buckets are mutually exclusive for range queries, and both duration/integer values must be positive. A new PROMQL_BUCKETS_PARAMETER capability flag gates csv-spec coverage so clusters that do not support this feature remain BWC-safe.

User impact is simpler PromQL authoring and fewer manual step calculations in API and dashboard workflows, without changing rounding semantics.

A limitation is that auto-bucketing currently requires explicit start and end. The latter is addressed with #142580.

Creating this as a draft right now as the tests don't work yet. I think the issue is that it only creates buckets for time ranges that have data in the index, even when the query yields a constant value per bucket (such as the literal/scalar 1).

* default to 100 buckets when start/end is set but step is absent
* customizable number of buckets with `buckets` promql command parameter
@felixbarny felixbarny self-assigned this Feb 17, 2026
@felixbarny felixbarny added >non-issue :StorageEngine/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL labels Feb 17, 2026
@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team v9.4.0 labels Feb 17, 2026
@felixbarny felixbarny marked this pull request as ready for review February 17, 2026 09:04
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

private static final String TIME = "time", START = "start", END = "end", STEP = "step", INDEX = "index";
private static final Set<String> PROMQL_ALLOWED_PARAMS = Set.of(TIME, START, END, STEP, INDEX);
private static final String TIME = "time", START = "start", END = "end", STEP = "step", BUCKETS = "buckets", INDEX = "index";
private static final int DEFAULT_PROMQL_BUCKETS = 100;
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.

This could be adaptive, e.g. to have buckets at least every scrape_interval. Can be extended in the next iteration.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can discuss it but it's fine to have a step that is smaller than the scrape_interval. What matters is that the window is larger than the scrape_interval.

@felixbarny felixbarny merged commit 81dfc08 into elastic:main Feb 17, 2026
35 checks passed
@felixbarny
Copy link
Copy Markdown
Member Author

felixbarny commented Feb 17, 2026

@stratoula this PR adds a buckets parameter to PromQL, could you add support for it to Kibana? The parameter is numeric and defaults to 100. It has the same semantics as the buckets parameter of the BUCKET function.

@felixbarny felixbarny deleted the promql-auto-step branch February 17, 2026 15:56
@stratoula
Copy link
Copy Markdown

Totally!

@felixbarny
Copy link
Copy Markdown
Member Author

I forgot to mention that this also makes the step parameter optional. For now either step or start/end are required. However, once #142580 is merged, all parameters are optional as start/end can be inferred from the Query DSL filter.

bartoval added a commit to elastic/kibana that referenced this pull request Feb 18, 2026
## Summary
part of #246728

We add a new param called `buckets
`elastic/elasticsearch#142582



https://github.com/user-attachments/assets/a3faa37e-5cd6-4b6e-bc1d-d5afa717c2ff



This change makes the following behavior explicit:

- step is optional.
- If step is not set, it is derived from buckets, start, and end. If
buckets is not set, it defaults to 100.
- If buckets is set (or start and end are set), we still pass step as
next column.
- Steps and buckets are mutually exclusive for validation and
autocomplete (I added the video before implementing the autocomplete
part)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Stratou <stratoula1@gmail.com>
patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request Feb 19, 2026
## Summary
part of elastic#246728

We add a new param called `buckets
`elastic/elasticsearch#142582



https://github.com/user-attachments/assets/a3faa37e-5cd6-4b6e-bc1d-d5afa717c2ff



This change makes the following behavior explicit:

- step is optional.
- If step is not set, it is derived from buckets, start, and end. If
buckets is not set, it defaults to 100.
- If buckets is set (or start and end are set), we still pass step as
next column.
- Steps and buckets are mutually exclusive for validation and
autocomplete (I added the video before implementing the autocomplete
part)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Stratou <stratoula1@gmail.com>
ersin-erdal pushed a commit to ersin-erdal/kibana that referenced this pull request Feb 19, 2026
## Summary
part of elastic#246728

We add a new param called `buckets
`elastic/elasticsearch#142582



https://github.com/user-attachments/assets/a3faa37e-5cd6-4b6e-bc1d-d5afa717c2ff



This change makes the following behavior explicit:

- step is optional.
- If step is not set, it is derived from buckets, start, and end. If
buckets is not set, it defaults to 100.
- If buckets is set (or start and end are set), we still pass step as
next column.
- Steps and buckets are mutually exclusive for validation and
autocomplete (I added the video before implementing the autocomplete
part)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Stratou <stratoula1@gmail.com>
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/ES|QL Timeseries / metrics / PromQL / logsdb capabilities in ES|QL Team:StorageEngine v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants