Documentation
¶
Overview ¶
Package limits enforces the stack.yaml `limits:` block: token-bucket rate limits scoped to one client, server, or tool. It implements the gateway's CallGate seam for pre-call checks. Enforcement is entirely in-memory; a bucket's state does not survive a daemon restart.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultBurst ¶
DefaultBurst returns the bucket capacity for a rate limit that does not set one: a few seconds of the sustained rate, never below five.
Types ¶
type EntryStatus ¶
type EntryStatus struct {
Kind string `json:"kind"`
// Scope is "client", "server", or "tool"; Key is the configured value.
Scope string `json:"scope"`
Key string `json:"key"`
// State is "ok" or "exceeded" (the bucket is currently empty).
State string `json:"state"`
Rate *RateStatus `json:"rate,omitempty"`
}
EntryStatus is one limit's snapshot, shared by GET /api/limits and `gridctl limits`. Kind is always "rate"; it stays on the wire so consumers written against the mixed budget/rate era keep parsing.
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy is the compiled, enforcement-ready form of a config.LimitsConfig. A nil *Policy means no limits block was configured; every method is nil-safe and permissive. Entries are immutable after compile.
func NewPolicy ¶
func NewPolicy(cfg *config.LimitsConfig, logger *slog.Logger) *Policy
NewPolicy compiles the limits block. A nil or empty config returns a nil policy (no limits, byte-identical legacy behavior).
func (*Policy) CarryOver ¶
CarryOver adopts state from a retiring policy so a hot reload never resets enforcement: rate limiters are reused for entries whose scope, key, rate, and burst are unchanged (an unrelated stack edit must not refill a drained bucket).
func (*Policy) Status ¶
func (p *Policy) Status() StatusReport
Status snapshots every configured limit. A nil policy reports Configured: false with an empty (non-nil) entry list.
type RateStatus ¶
RateStatus is one rate limit's configuration snapshot.
type StatusReport ¶
type StatusReport struct {
Configured bool `json:"configured"`
Entries []EntryStatus `json:"entries"`
}
StatusReport is the full limits status payload.