rate_limiter

package
v5.6.0-rc.21 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// todo should these be more unique to avoid clash
	RateLimiterScopeConnection = "connection"
	RateLimiterScopeTable      = "table"
)

Variables

This section is empty.

Functions

func FormatStringMap

func FormatStringMap(stringMap map[string]string) string

FormatStringMap orders the map keys and returns a string containing all map keys and values

func GetMaxConcurrentRows

func GetMaxConcurrentRows() int

func MergeScopeValues

func MergeScopeValues(values []map[string]string) map[string]string

MergeScopeValues combines a set of scope values in order of precedence NOT: it adds the given values to the resulting map WITHOUT OVERWRITING existing values i.e. follow the precedence order

func ScopeValuesString

func ScopeValuesString(sv map[string]string) string

Types

type Definition

type Definition struct {
	// the limiter name
	Name string
	// the actual limiter config
	FillRate   rate.Limit
	BucketSize int64

	MaxConcurrency int64
	// the scope properties which identify this limiter instance
	// one limiter instance will be created for each combination of these properties which is encountered
	Scope []string

	// filter used to target the limiter
	Where string
	// contains filtered or unexported fields
}

func DefinitionFromProto

func DefinitionFromProto(p *proto.RateLimiterDefinition) (*Definition, error)

DefinitionFromProto converts the proto format RateLimiterDefinition into a Defintion

func (*Definition) Initialise

func (d *Definition) Initialise() error

func (*Definition) SatisfiesFilters

func (d *Definition) SatisfiesFilters(scopeValues map[string]string) bool

SatisfiesFilters returns whether the given values satisfy ANY of our filters

func (*Definition) String

func (d *Definition) String() string

func (*Definition) Validate

func (d *Definition) Validate() []string

type Limiter

type Limiter struct {
	*rate.Limiter
	Name string
	// contains filtered or unexported fields
}

type LimiterMap

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

LimiterMap is a struct encapsulating a map of rate limiters map key is built from the limiter tag values, e.g. tags: {"connection": "aws1", "region": "us-east-1"} key: hash("{\"connection\": \"aws1\", \"region\": \"us-east-1\"})

func NewLimiterMap

func NewLimiterMap() *LimiterMap

func (*LimiterMap) Clear

func (m *LimiterMap) Clear()

func (*LimiterMap) GetOrCreate

func (m *LimiterMap) GetOrCreate(def *Definition, scopeValues map[string]string) (*Limiter, error)

GetOrCreate checks the map for a limiter with the specified key values - if none exists it creates it

type MultiLimiter

type MultiLimiter struct {
	Limiters    []*Limiter
	ScopeValues map[string]string
}

func NewMultiLimiter

func NewMultiLimiter(limiters []*Limiter, scopeValues map[string]string) *MultiLimiter

func (*MultiLimiter) LimiterNames

func (m *MultiLimiter) LimiterNames() []string

func (*MultiLimiter) ReleaseSemaphore

func (m *MultiLimiter) ReleaseSemaphore()

func (*MultiLimiter) String

func (m *MultiLimiter) String() string

func (*MultiLimiter) TryToAcquireSemaphore

func (m *MultiLimiter) TryToAcquireSemaphore() bool

func (*MultiLimiter) Wait

func (m *MultiLimiter) Wait(ctx context.Context, cost int) time.Duration

Jump to

Keyboard shortcuts

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