Skip to content

Commit

Permalink
MQE: fix issue where subqueries could return series with no points (#…
Browse files Browse the repository at this point in the history
…9998)

* MQE: fix issue where subqueries could return series with no points

* Add changelog entry

* Add more test cases
  • Loading branch information
charleskorn authored Nov 25, 2024
1 parent bf3d420 commit 1afa9f6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* [CHANGE] Ingester: remove experimental flags `-ingest-storage.kafka.ongoing-records-per-fetch` and `-ingest-storage.kafka.startup-records-per-fetch`. They are removed in favour of `-ingest-storage.kafka.max-buffered-bytes`. #9906
* [CHANGE] Ingester: Replace `cortex_discarded_samples_total` label from `sample-out-of-bounds` to `sample-timestamp-too-old`. #9885
* [CHANGE] Ruler: the `/prometheus/config/v1/rules` does not return an error anymore if a rule group is missing in the object storage after been successfully returned by listing the storage, because it could have been deleted in the meanwhile. #9936
* [FEATURE] Querier: add experimental streaming PromQL engine, enabled with `-querier.query-engine=mimir`. #9367 #9368 #9398 #9399 #9403 #9417 #9418 #9419 #9420 #9482 #9504 #9505 #9507 #9518 #9531 #9532 #9533 #9553 #9558 #9588 #9589 #9639 #9641 #9642 #9651 #9664 #9681 #9717 #9719 #9724 #9874
* [FEATURE] Querier: add experimental streaming PromQL engine, enabled with `-querier.query-engine=mimir`. #9367 #9368 #9398 #9399 #9403 #9417 #9418 #9419 #9420 #9482 #9504 #9505 #9507 #9518 #9531 #9532 #9533 #9553 #9558 #9588 #9589 #9639 #9641 #9642 #9651 #9664 #9681 #9717 #9719 #9724 #9874 #9998
* [FEATURE] Distributor: Add support for `lz4` OTLP compression. #9763
* [FEATURE] Query-frontend: added experimental configuration options `query-frontend.cache-errors` and `query-frontend.results-cache-ttl-for-errors` to allow non-transient responses to be cached. When set to `true` error responses from hitting limits or bad data are cached for a short TTL. #9028
* [FEATURE] Query-frontend: add middleware to control access to specific PromQL experimental functions on a per-tenant basis. #9798
Expand Down
16 changes: 16 additions & 0 deletions pkg/streamingpromql/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,22 @@ func TestSubqueries(t *testing.T) {
},
Start: time.Unix(10, 0),
},
{
// A query where SeriesMetadata returns some series but evaluates to no samples should not return anything.
Query: `(metric > Inf)[20s:10s]`,
Start: time.Unix(30, 0),
Result: promql.Result{
Value: promql.Matrix{},
},
},
{
// A nested subquery with the same properties as above.
Query: `last_over_time((metric > Inf)[20s:10s])[30s:5s]`,
Start: time.Unix(30, 0),
Result: promql.Result{
Value: promql.Matrix{},
},
},
{
Query: "metric[20s:5s]",
Result: promql.Result{
Expand Down
6 changes: 6 additions & 0 deletions pkg/streamingpromql/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,12 @@ func (q *Query) populateMatrixFromRangeVectorOperator(ctx context.Context, o typ
return nil, err
}

if len(floats) == 0 && len(histograms) == 0 {
types.FPointSlicePool.Put(floats, q.memoryConsumptionTracker)
types.HPointSlicePool.Put(histograms, q.memoryConsumptionTracker)
continue
}

m = append(m, promql.Series{
Metric: s.Labels,
Floats: floats,
Expand Down
6 changes: 6 additions & 0 deletions pkg/streamingpromql/testdata/ours/subqueries.test
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ eval range from 0 to 4m step 20s sum_over_time(sum_over_time(metric[2m:30s])[3m:

eval range from 0 to 4m step 3m sum_over_time(sum_over_time(sum_over_time(metric[2m:30s])[3m:15s])[4m:20s])
{} 0 86

eval range from 0 to 4m step 15s last_over_time((metric > Inf)[20s:10s])
# Should produce no results.

eval instant at 3m last_over_time((metric > Inf)[20s:10s])
# Should produce no results.

0 comments on commit 1afa9f6

Please sign in to comment.