Skip to content

Commit

Permalink
Fix @ modifier for subquery when split
Browse files Browse the repository at this point in the history
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
  • Loading branch information
harry671003 committed Dec 20, 2024
1 parent bb59466 commit f56b281
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
* [BUGFIX] Ring: update ring with new ip address when instance is lost, rejoins, but heartbeat is disabled. #6271
* [BUGFIX] Ingester: Fix regression on usage of cortex_ingester_queried_chunks. #6398
* [BUGFIX] Ingester: Fix possible race condition when `active series per LabelSet` is configured. #6409
* [BUGFIX] Query Frontend: Fix @ modifier not being applied correctly on sub queries. #6450

## 1.18.1 2024-10-14

Expand Down
9 changes: 9 additions & 0 deletions pkg/querier/tripperware/queryrange/split_by_interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ func evaluateAtModifierFunction(query string, start, end int64) (string, error)
}
selector.StartOrEnd = 0
}
if selector, ok := n.(*parser.SubqueryExpr); ok {
switch selector.StartOrEnd {
case parser.START:
selector.Timestamp = &start
case parser.END:
selector.Timestamp = &end
}
selector.StartOrEnd = 0
}
return nil
})
return expr.String(), err
Expand Down
8 changes: 8 additions & 0 deletions pkg/querier/tripperware/queryrange/split_by_interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ func Test_evaluateAtModifier(t *testing.T) {
[2m:])
[10m:])`,
},
{
in: `irate(kube_pod_info{namespace="test"}[1h:1m] @ start())`,
expected: `irate(kube_pod_info{namespace="test"}[1h:1m] @ 1546300.800)`,
},
{
in: `irate(kube_pod_info{namespace="test"} @ end()[1h:1m] @ start())`,
expected: `irate(kube_pod_info{namespace="test"} @ 1646300.800 [1h:1m] @ 1546300.800)`,
},
{
// parse error: @ modifier must be preceded by an instant vector selector or range vector selector or a subquery
in: "sum(http_requests_total[5m]) @ 10.001",
Expand Down

0 comments on commit f56b281

Please sign in to comment.