PromQL: auto-bucketing for step#142582
Conversation
* default to 100 buckets when start/end is set but step is absent * customizable number of buckets with `buckets` promql command parameter
|
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; |
There was a problem hiding this comment.
This could be adaptive, e.g. to have buckets at least every scrape_interval. Can be extended in the next iteration.
There was a problem hiding this comment.
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.
|
@stratoula this PR adds a |
|
Totally! |
|
I forgot to mention that this also makes the |
## 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>
## 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>
## 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>
This PR adds automatic step derivation for PromQL range queries in ES|QL when
stepis omitted. The goal is to reduce query boilerplate while keeping bucketed results deterministic.Range queries can now provide
buckets=<n>instead ofstep, and when neither parameter is provided the parser defaults tobuckets=100. During translation to ES|QL, the effective step duration is derived from the same date-rounding logic used byBUCKETover[start, end, buckets], and then used to build thestepcolumn. For example,start=00:00,end=00:01,buckets=3produces steps at00:00,00:20, and00:40; with default buckets over one minute, the inferred step is 10 seconds.The change also tightens parameter validation:
stepandbucketsare mutually exclusive for range queries, and both duration/integer values must be positive. A newPROMQL_BUCKETS_PARAMETERcapability 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
startandend. 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/scalar1).