From 5606a941e0f4a6e86dc16f8534d80a11b0eb0894 Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Wed, 29 Mar 2023 09:33:06 +0200 Subject: [PATCH] Validates label matchers in the querier --- pkg/querier/querier.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/querier/querier.go b/pkg/querier/querier.go index 9a31d54f9..52c1d4c7f 100644 --- a/pkg/querier/querier.go +++ b/pkg/querier/querier.go @@ -18,6 +18,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/common/model" + "github.com/prometheus/prometheus/promql/parser" "github.com/samber/lo" "golang.org/x/sync/errgroup" @@ -224,6 +225,10 @@ func (q *Querier) SelectMergeStacktraces(ctx context.Context, req *connect.Reque if err != nil { return nil, connect.NewError(connect.CodeInvalidArgument, err) } + _, err = parser.ParseMetricSelector(req.Msg.LabelSelector) + if err != nil { + return nil, connect.NewError(connect.CodeInvalidArgument, err) + } ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -280,6 +285,10 @@ func (q *Querier) SelectMergeProfile(ctx context.Context, req *connect.Request[q if err != nil { return nil, connect.NewError(connect.CodeInvalidArgument, err) } + _, err = parser.ParseMetricSelector(req.Msg.LabelSelector) + if err != nil { + return nil, connect.NewError(connect.CodeInvalidArgument, err) + } ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -338,6 +347,11 @@ func (q *Querier) SelectSeries(ctx context.Context, req *connect.Request[querier return nil, connect.NewError(connect.CodeInvalidArgument, err) } + _, err = parser.ParseMetricSelector(req.Msg.LabelSelector) + if err != nil { + return nil, connect.NewError(connect.CodeInvalidArgument, err) + } + if req.Msg.Start > req.Msg.End { return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("start must be before end")) }