limithandler

package
v16.11.6 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitConcurrencyByRepo

func LimitConcurrencyByRepo(ctx context.Context) string

LimitConcurrencyByRepo implements GetLockKey by using the repository path as lock.

Types

type GetLockKey

type GetLockKey func(context.Context) string

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

type LimiterMiddleware

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

LimiterMiddleware contains rate limiter state

func New

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

New creates a new middleware that limits requests. SetupFunc sets up the middleware with a specific kind of limiter.

func (*LimiterMiddleware) Collect

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

Collect is used to collect Prometheus metrics.

func (*LimiterMiddleware) Describe

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 SetupFunc

type SetupFunc func(cfg config.Cfg, middleware *LimiterMiddleware)

SetupFunc set up a middleware to limiting requests

func WithConcurrencyLimiters

func WithConcurrencyLimiters(cfg config.Cfg) (map[string]*limiter.AdaptiveLimit, SetupFunc)

WithConcurrencyLimiters sets up middleware to limit the concurrency of requests based on RPC and repository

func WithRateLimiters

func WithRateLimiters(ctx context.Context) SetupFunc

WithRateLimiters sets up a middleware with limiters that limit requests based on its rate per second per RPC

Jump to

Keyboard shortcuts

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