limits

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

func DefaultBurst(callsPerMinute int) int

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

func (p *Policy) CarryOver(old *Policy)

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) Gates

func (p *Policy) Gates() []mcp.CallGate

Gates returns the policy's pre-call gates. A nil policy returns nil.

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

type RateStatus struct {
	CallsPerMinute int `json:"calls_per_minute"`
	Burst          int `json:"burst"`
}

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.

Jump to

Keyboard shortcuts

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