Documentation
¶
Index ¶
Constants ¶
const ( // MaxBuckets is the maximum number of rate limit buckets kept in memory. // When exceeded, stale buckets (fully refilled and older than their window) are evicted. MaxBuckets = 10000 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BucketSnapshot ¶ added in v0.9.0
type BucketSnapshot struct {
Key string
Tokens int
Max int
Window time.Duration
LastRefill time.Time
}
BucketSnapshot is a point-in-time copy of one bucket's state, used by the persistence syncer for write-behind and boot restore. It carries the limiter's opaque key ("scope:tenant:agent"); the syncer parses the tenant out of it.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter implements a token-bucket rate limiter keyed by scope and agent.
func (*Limiter) Allow ¶
Allow checks whether a request identified by key is within the rate limit. maxRequests is the maximum number of requests allowed in the given window. Returns nil if allowed, or an error describing the limit.
func (*Limiter) BucketCount ¶ added in v0.5.0
BucketCount returns the current number of tracked buckets (for testing).
func (*Limiter) Restore ¶ added in v0.9.0
func (l *Limiter) Restore(snaps []BucketSnapshot)
Restore loads buckets from a prior Snapshot (boot hydration). Entries with a matching key are overwritten. Intended to run once, before serving traffic.
func (*Limiter) Snapshot ¶ added in v0.9.0
func (l *Limiter) Snapshot() []BucketSnapshot
Snapshot returns a copy of every live bucket. It holds the limiter lock only for the (O(n) struct-copy) duration and is intended for the background persistence syncer — it is never called on the request path, so it cannot affect the proxy's latency budget.