From 22f9bf0669e30b65343f8ff1059fb35266b8ace1 Mon Sep 17 00:00:00 2001 From: Artyom Antonov Date: Wed, 26 Jun 2024 20:22:40 +0500 Subject: [PATCH] fix: check if consolidation function is set --- .../testcases/consolidateBy/consolidateBy.yaml | 14 +++++++++++++- expr/expr.go | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/mockbackend/testcases/consolidateBy/consolidateBy.yaml b/cmd/mockbackend/testcases/consolidateBy/consolidateBy.yaml index 654bfadec..997b89a61 100644 --- a/cmd/mockbackend/testcases/consolidateBy/consolidateBy.yaml +++ b/cmd/mockbackend/testcases/consolidateBy/consolidateBy.yaml @@ -66,7 +66,19 @@ test: URL: "/render?format=json&target=consolidateBy(metric*, 'somefunc')&maxDataPoints=2" expectedResponse: httpCode: 400 - contentType: "text/plain; charset=utf-8" + contentType: "text/plain; charset=utf-8" + - endpoint: "http://127.0.0.1:8081" + type: "GET" + URL: "/render?format=json&target=limit(metric*, 2)&maxDataPoints=2" + expectedResponse: + httpCode: 200 + contentType: "application/json" + - endpoint: "http://127.0.0.1:8081" + type: "GET" + URL: "/render?format=json&target=consolidateBy(seriesByTag('name=rps', 'env=prod'), 'sum')&maxDataPoints=2" + expectedResponse: + httpCode: 200 + contentType: "application/json" listeners: diff --git a/expr/expr.go b/expr/expr.go index 77ef43625..1fba2faec 100644 --- a/expr/expr.go +++ b/expr/expr.go @@ -55,9 +55,9 @@ func (eval Evaluator) Fetch(ctx context.Context, exprs []parser.Expr, from, unti Until: fetchRequest.StopTime, } - if eval.passFunctionsToBackend { + if eval.passFunctionsToBackend && m.ConsolidationFunc != "" { if _, ok := consolidateBy.ValidAggregateFunctions[m.ConsolidationFunc]; !ok { - return nil, merry.WithMessagef(parser.ErrInvalidArg, "invalid consolidateBy argument: %s", m.ConsolidationFunc) + return nil, merry.WithMessagef(parser.ErrInvalidArg, "invalid consolidateBy argument: '%s'", m.ConsolidationFunc) } fetchRequest.FilterFunctions = append(fetchRequest.FilterFunctions, &pb.FilteringFunction{ Name: "consolidateBy",