MCPcopy
hub / github.com/grafana/dskit / newRateLimiter

Function newRateLimiter

crypto/tls/test/tls_integration_test.go:716–729  ·  view source on GitHub ↗

newRateLimiter creates a UnaryClientInterceptor for client side rate limiting.

(cfg *grpcConfig)

Source from the content-addressed store, hash-verified

714
715// newRateLimiter creates a UnaryClientInterceptor for client side rate limiting.
716func newRateLimiter(cfg *grpcConfig) grpc.UnaryClientInterceptor {
717 burst := cfg.RateLimitBurst
718 if burst == 0 {
719 burst = int(cfg.RateLimit)
720 }
721 limiter := rate.NewLimiter(rate.Limit(cfg.RateLimit), burst)
722 return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
723 err := limiter.Wait(ctx)
724 if err != nil {
725 return status.Error(codes.ResourceExhausted, err.Error())
726 }
727 return invoker(ctx, method, req, reply, cc, opts...)
728 }
729}

Callers 1

DialOptionMethod · 0.85

Calls 3

LimitMethod · 0.65
WaitMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected