promql-engine icon indicating copy to clipboard operation
promql-engine copied to clipboard

execution: Utilize hints to limit the number of samples fetch when using limitk

Open Saumya40-codes opened this issue 7 months ago • 0 comments

This PR follows up #547 after adding liimitk aggregation

This is based on -> https://github.com/thanos-io/promql-engine/pull/547#issuecomment-2800094704

In current implementation we fetch all the samples based on vector selector, only take first k. We can utilize hints we set under certain conditions, to only fetch required samples (which gets taken care during q.Select() on thanos side)

Limitations

If query is something like limitk(2, topk(5, some_metric)) then setting limits will give wrong results, additionally we should also refrain from doing this when a grouping (by/without) is used.

in other case for e.g. if query is limitk(2, some_metric) say that metric has >1000 samples, we will only have 2 of them in engine)

Saumya40-codes avatar May 18 '25 11:05 Saumya40-codes