Skip to content

Commit

Permalink
QFE: Fix @ modifier not being applied correctly on subqueries (thanos…
Browse files Browse the repository at this point in the history
…-io#8016)

Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
  • Loading branch information
harry671003 authored Dec 26, 2024
1 parent 2d041dc commit 6f03fcb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
### Fixed

- [#7978](https://github.com/thanos-io/thanos/pull/7978) Receive: Fix deadlock during local writes when `split-tenant-label-name` is used
- [#8016](https://github.com/thanos-io/thanos/pull/8016) Query Frontend: Fix @ modifier not being applied correctly on sub queries.

### Added

Expand Down
12 changes: 11 additions & 1 deletion internal/cortex/querier/queryrange/split_by_interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ package queryrange

import (
"context"
"github.com/thanos-io/thanos/pkg/extpromql"
"net/http"
"time"

"github.com/thanos-io/thanos/pkg/extpromql"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/promql/parser"
Expand Down Expand Up @@ -112,6 +113,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 internal/cortex/querier/queryrange/split_by_interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,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 6f03fcb

Please sign in to comment.