Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 1aadc44

Browse files
committed
Do not attempt to push down calls with offsets
We don't correctly handle pushdowns with offsets, so we just skip them instead of returning erroneous results.
1 parent 32c9aa1 commit 1aadc44

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ We use the following categories for changes:
1919

2020
### Fixed
2121
- Fix spans with end < start. Start and end are swapped in this case. [#1096]
22+
- Disable push downs which use `offset`, as they are broken [#1129]
2223

2324
## [0.9.0] - 2022-02-02
2425

pkg/pgmodel/querier/query_builder.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,25 @@ func canAttemptPushdown(metadata *promqlMetadata) bool {
242242
path := metadata.path // PromQL AST.
243243
queryHints := metadata.queryHints
244244
selectHints := metadata.selectHints
245-
return extension.ExtensionIsInstalled && queryHints != nil && !hasSubquery(path) && selectHints != nil
245+
246+
switch {
247+
// We can't push down without hints.
248+
case queryHints == nil || selectHints == nil:
249+
return false
250+
// We can't do pushdowns without the extension.
251+
case hasSubquery(path):
252+
return false
253+
// We can't handle subqueries in pushdowns.
254+
case !extension.ExtensionIsInstalled:
255+
return false
256+
default:
257+
// We can't handle offsets in pushdowns.
258+
vs, isVectorSelector := queryHints.CurrentNode.(*parser.VectorSelector)
259+
if isVectorSelector && vs.Offset != 0 {
260+
return false
261+
}
262+
}
263+
return true
246264
}
247265

248266
// tryPushDown inspects the AST above the current node to determine if it's

pkg/tests/end_to_end_tests/promql_query_endpoint_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,10 @@ func TestPromQLQueryEndpoint(t *testing.T) {
25062506
name: "two pushdowns, same metric different matchers",
25072507
query: `sum(rate(metric_2{foo = "bar"}[5m]))/sum(rate(metric_2[5m]))`,
25082508
},
2509+
{
2510+
name: "delta function over range selector with offset",
2511+
query: `delta(metric_2[1m] offset 3m)`,
2512+
},
25092513
}
25102514
start := time.Unix(startTime/1000, 0)
25112515
end := time.Unix(endTime/1000, 0)

0 commit comments

Comments
 (0)