Files
Christian HaudumandGitHub 4bbb89047b Upgrade Cortex to v1.10.1-0.20211104100946-3f329a21cad4 (#1100)
Signed-off-by: Christian Haudum <[email protected]>
Co-authored-by:  Susana Ferreira <[email protected]>

Fix duplicate metrics registration

Signed-off-by: Christian Haudum <[email protected]>

Add debug logs to hedge request test

Signed-off-by: Christian Haudum <[email protected]>

Fix e2e test metric names

Remove prometheus/common replace in go.mod

Signed-off-by: Christian Haudum <[email protected]>
2021-11-05 13:17:17 -04:00

27 lines
770 B
Go

package grpcclient
import (
"context"
"golang.org/x/time/rate"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// NewRateLimiter creates a UnaryClientInterceptor for client side rate limiting.
func NewRateLimiter(cfg *Config) grpc.UnaryClientInterceptor {
burst := cfg.RateLimitBurst
if burst == 0 {
burst = int(cfg.RateLimit)
}
limiter := rate.NewLimiter(rate.Limit(cfg.RateLimit), burst)
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
err := limiter.Wait(ctx)
if err != nil {
return status.Error(codes.ResourceExhausted, err.Error())
}
return invoker(ctx, method, req, reply, cc, opts...)
}
}