Skip to content

Commit

Permalink
refactor: check for variants before samples in roundtripper
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorwhitney committed Feb 20, 2025
1 parent 4137c05 commit f7d5608
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions pkg/querier/queryrange/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,31 @@ func (r roundTripper) Do(ctx context.Context, req base.Request) (base.Response,
}

switch e := op.Plan.AST.(type) {
case syntax.VariantsExpr:
if err := validateMaxEntriesLimits(ctx, op.Limit, r.limits); err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

matchers := e.Matchers()

if err := validateMatchers(ctx, r.limits, matchers); err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

for _, v := range e.Variants() {
groups, err := v.MatcherGroups()
if err != nil {
level.Warn(logger).Log("msg", "unexpected matcher groups error in roundtripper", "err", err)
}

for _, g := range groups {
if err := validateMatchers(ctx, r.limits, g.Matchers); err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
}
}

return r.variants.Do(ctx, req)
case syntax.SampleExpr:
// The error will be handled later.
groups, err := e.MatcherGroups()
Expand Down Expand Up @@ -444,31 +469,6 @@ func (r roundTripper) Do(ctx context.Context, req base.Request) (base.Response,
return r.limited.Do(ctx, req)
}
return r.log.Do(ctx, req)
case syntax.VariantsExpr:
if err := validateMaxEntriesLimits(ctx, op.Limit, r.limits); err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

matchers := e.Matchers()

if err := validateMatchers(ctx, r.limits, matchers); err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

for _, v := range e.Variants() {
groups, err := v.MatcherGroups()
if err != nil {
level.Warn(logger).Log("msg", "unexpected matcher groups error in roundtripper", "err", err)
}

for _, g := range groups {
if err := validateMatchers(ctx, r.limits, g.Matchers); err != nil {
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}
}
}

return r.variants.Do(ctx, req)
default:
return r.next.Do(ctx, req)
}
Expand Down

0 comments on commit f7d5608

Please sign in to comment.