limithandler

package
v14.9.0-rc4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMaxQueueSize = errors.New("maximum queue size reached")

ErrMaxQueueSize indicates the concurrency queue has reached its maximum size

View Source
var ErrMaxQueueTime = errors.New("maximum time in concurrency queue reached")

ErrMaxQueueTime indicates a request has reached the maximum time allowed to wait in the concurrency queue.

Functions

func LimitConcurrencyByRepo added in v14.7.0

func LimitConcurrencyByRepo(ctx context.Context) string

LimitConcurrencyByRepo implements GetLockKey by using the repository path as lock.

Types

type ConcurrencyLimiter

type ConcurrencyLimiter struct {
	// contains filtered or unexported fields
}

ConcurrencyLimiter contains rate limiter state

func NewLimiter

func NewLimiter(perKeyLimit, globalLimit int, maxWaitTickerGetter QueueTickerCreator, monitor ConcurrencyMonitor) *ConcurrencyLimiter

NewLimiter creates a new rate limiter

func (*ConcurrencyLimiter) Limit

func (c *ConcurrencyLimiter) Limit(ctx context.Context, lockKey string, f LimitedFunc) (interface{}, error)

Limit will limit the concurrency of f

type ConcurrencyMonitor

type ConcurrencyMonitor interface {
	Queued(ctx context.Context)
	Dequeued(ctx context.Context)
	Enter(ctx context.Context, acquireTime time.Duration)
	Exit(ctx context.Context)
	Dropped(ctx context.Context, message string)
}

ConcurrencyMonitor allows the concurrency monitor to be observed

type GetLockKey

type GetLockKey func(context.Context) string

GetLockKey function defines the lock key of an RPC invocation based on its context

type LimitedFunc

type LimitedFunc func() (resp interface{}, err error)

LimitedFunc represents a function that will be limited

type LimiterMiddleware

type LimiterMiddleware struct {
	// contains filtered or unexported fields
}

LimiterMiddleware contains rate limiter state

func New

func New(cfg config.Cfg, getLockKey GetLockKey) *LimiterMiddleware

New creates a new rate limiter

func (*LimiterMiddleware) Collect added in v14.7.0

func (c *LimiterMiddleware) Collect(metrics chan<- prometheus.Metric)

Collect is used to collect Prometheus metrics.

func (*LimiterMiddleware) Describe added in v14.7.0

func (c *LimiterMiddleware) Describe(descs chan<- *prometheus.Desc)

Describe is used to describe Prometheus metrics.

func (*LimiterMiddleware) StreamInterceptor

func (c *LimiterMiddleware) StreamInterceptor() grpc.StreamServerInterceptor

StreamInterceptor returns a Stream Interceptor

func (*LimiterMiddleware) UnaryInterceptor

func (c *LimiterMiddleware) UnaryInterceptor() grpc.UnaryServerInterceptor

UnaryInterceptor returns a Unary Interceptor

type QueueTickerCreator added in v14.8.0

type QueueTickerCreator func() helper.Ticker

QueueTickerCreator is a function that provides a ticker

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL