Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/util/querylimits/tripperware.go

51 lines
1.2 KiB

package querylimits
import (
"net/http"
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase"
)
type tripperwareWrapper struct {
next http.RoundTripper
wrapped http.RoundTripper
}
// WrapTripperware wraps the existing tripperware to make sure the query limit policy headers are propagated
func WrapTripperware(existing queryrangebase.Tripperware) queryrangebase.Tripperware {
return func(next http.RoundTripper) http.RoundTripper {
limitsTrw := &tripperwareWrapper{
next: next,
}
limitsTrw.wrapped = existing(queryrangebase.RoundTripFunc(limitsTrw.PostWrappedRoundTrip))
return limitsTrw
}
}
func (t *tripperwareWrapper) RoundTrip(r *http.Request) (*http.Response, error) {
ctx := r.Context()
limits := ExtractQueryLimitsContext(ctx)
if limits != nil {
ctx = InjectQueryLimitsContext(ctx, *limits)
r = r.Clone(ctx)
}
return t.wrapped.RoundTrip(r)
}
func (t *tripperwareWrapper) PostWrappedRoundTrip(r *http.Request) (*http.Response, error) {
ctx := r.Context()
limits := ExtractQueryLimitsContext(ctx)
if limits != nil {
err := InjectQueryLimitsHTTP(r, limits)
if err != nil {
return nil, err
}
}
return t.next.RoundTrip(r)
}