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

(cherry picked from commit 1afa9f6)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
charleskorn committed Nov 25, 2024
1 parent 23f9fb6 commit 72da039
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 @@ -14,7 +14,7 @@
* `cortex_alertmanager_alerts`
* `cortex_alertmanager_silences`
* [CHANGE] Distributor: Drop experimental `-distributor.direct-otlp-translation-enabled` flag, since direct OTLP translation is well tested at this point. #9647
* [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 #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 #9874 #9998
* [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] gRPC: Support S2 compression. #9322
* `-alertmanager.alertmanager-client.grpc-compression=s2`
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 72da039

Please sign in to comment.