Skip to content

Commit

Permalink
fix: check if consolidation function is set
Browse files Browse the repository at this point in the history
  • Loading branch information
mchrome committed Jun 26, 2024
1 parent 36d32a1 commit 22f9bf0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion cmd/mockbackend/testcases/consolidateBy/consolidateBy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions expr/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 22f9bf0

Please sign in to comment.