From 6f03fcb0ba777d4f6159b5ec502c8ac0ab6d927b Mon Sep 17 00:00:00 2001 From: Harry John Date: Thu, 26 Dec 2024 15:38:17 -0800 Subject: [PATCH] QFE: Fix @ modifier not being applied correctly on subqueries (#8016) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 🌲 Harry 🌊 John 🏔 --- CHANGELOG.md | 1 + .../cortex/querier/queryrange/split_by_interval.go | 12 +++++++++++- .../querier/queryrange/split_by_interval_test.go | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a26715c0c..cb965c19fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/internal/cortex/querier/queryrange/split_by_interval.go b/internal/cortex/querier/queryrange/split_by_interval.go index 2ae53f7c50..1267e6bbac 100644 --- a/internal/cortex/querier/queryrange/split_by_interval.go +++ b/internal/cortex/querier/queryrange/split_by_interval.go @@ -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" @@ -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 diff --git a/internal/cortex/querier/queryrange/split_by_interval_test.go b/internal/cortex/querier/queryrange/split_by_interval_test.go index 00654a911c..73fbbae994 100644 --- a/internal/cortex/querier/queryrange/split_by_interval_test.go +++ b/internal/cortex/querier/queryrange/split_by_interval_test.go @@ -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",