Skip to content

Commit

Permalink
feat: return empty result instead of error for failed detected fields…
Browse files Browse the repository at this point in the history
… queries
  • Loading branch information
trevorwhitney committed Sep 20, 2024
1 parent 7b3529a commit c7a471d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/querier/queryrange/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,35 @@ func NewDetectedFieldsTripperware(
)
}

// detected fields is an approximation, so this is a hedge against failed requests to return
// an empty response instead of an error, in case other subqueries were successful
fallThroughMiddleware := base.MiddlewareFunc(func(next base.Handler) base.Handler {
return base.HandlerFunc(
func(ctx context.Context, r base.Request) (base.Response, error) {
resp, err := next.Do(ctx, r)
switch r := resp.(type) {
case *DetectedFieldsResponse:
if err != nil {
return &DetectedFieldsResponse{
Response: &logproto.DetectedFieldsResponse{
Fields: []*logproto.DetectedField{},
FieldLimit: r.Response.FieldLimit,
},
Headers: r.Headers,
}, err
}
}

return resp, err
},
)
})

queryRangeMiddleware = append(
queryRangeMiddleware,
fallThroughMiddleware,
)

limitedRT := NewLimitedRoundTripper(next, limits, schema.Configs, queryRangeMiddleware...)
return NewSketchRemovingHandler(limitedRT, limits, splitter)
}), nil
Expand Down

0 comments on commit c7a471d

Please sign in to comment.