Skip to content

Commit

Permalink
Validates label matchers in the querier (grafana/phlare#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena authored Mar 29, 2023
1 parent c870fb5 commit 3e9237d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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"))
}
Expand Down

0 comments on commit 3e9237d

Please sign in to comment.