Documentation
¶
Overview ¶
Package gwbudget is the gateway's budget point (P3 of docs/subsystems/plugin-runtime.md): what holds a gateway key to the limits its owner set (#585). The gateway asks it before a key's request goes to any provider; plugins/budget serves internal/budget's limiter while it is on.
It fails closed: a request of a key held to a limit is not sent while no limiter serves it (ErrUnlimited). A request without a key, or of a key with no limit, never asks it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnlimited = errors.New("this gateway key is held to a limit, but magpie's Key limits built-in isn't serving it, so nothing was sent; turn it on in magpie's Plugins › Built-in")
ErrUnlimited is the error a key's request gets when the key is held to a limit and nothing can hold it.
Functions ¶
func ForgetRefreshForTest ¶
func ForgetRefreshForTest()
ForgetRefreshForTest lets the next Limiting refresh at once, as it would a second after the last one.
Types ¶
type Limiter ¶
type Limiter interface {
Reserve(who access.Identity, body int64, model string, now time.Time) (release func(), refused Refusal)
}
Limiter lets a key's request in, holding what it is expected to use until release, or refuses it. body is the request's size in bytes (-1 unknown) and model the model it named.
func Limiting ¶
Limiting is the limiter for who's request: nil, nil when who has no limit; ErrUnlimited when it has one and none serves. With none, one refresh is asked first (at most once a second, never from inside one), so a limit set a moment ago turns the plugin on for the request that needs it. Fail closed.
type Refusal ¶
type Refusal interface {
error
// RetryAfter is how long until the limit resets, in whole seconds.
RetryAfter(now time.Time) int
// ResetAt is when it resets.
ResetAt() time.Time
}
Refusal is why a key's request was turned away, as the client is told.