Documentation
¶
Overview ¶
Package limit is the ingress protection of the data plane (ADR-0112, F75): it refuses abusive traffic before the activator can wake a scaled-to-zero sandbox. Chain is the net/http middleware placed before dataplane.Handler: a token-bucket rate limit keyed by client IP (429), a Content-Length body-size cap (413) and an in-flight concurrency ceiling (503), all RFC 9457 problem+json. Under key: function the rate step leaves Chain for TargetLimiter, which dataplane.serveFunction calls once the target Function is resolved (ADR-0164), so every host, path and invoke form of one Function shares one bucket.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
RatePerMin int // token-bucket refill (requests per minute); 0 ⇒ rate limit off
Burst int // bucket depth; 0 ⇒ = RatePerMin
Key Key // clientIP (default) | function
MaxBodyBytes int64 // 413 over this (Content-Length, or a chunked body unless the upstream already answered); 0 ⇒ size cap off
MaxInFlight int // 503 over this many concurrent; 0 ⇒ concurrency cap off
MaxKeys int // buckets kept (ADR-0164 eviction); ≤ 0 ⇒ 4096
}
Config configures the three limiters. A zero Config is a pass-through.
type TargetLimiter ¶ added in v0.4.0
type TargetLimiter struct {
// contains filtered or unexported fields
}
TargetLimiter is the key: function rate step (ADR-0164). dataplane.serveFunction calls it for an external call once the Function is found, so a request for an unknown name creates no bucket.
func NewTargetLimiter ¶ added in v0.4.0
func NewTargetLimiter(cfg Config) *TargetLimiter
NewTargetLimiter returns nil unless RatePerMin > 0 and Key == KeyFunction.
func (*TargetLimiter) Throttle ¶ added in v0.4.0
func (l *TargetLimiter) Throttle(w http.ResponseWriter, ns v1.NamespaceName, name v1.ObjectName) bool
Throttle takes one token from the ns/name bucket. When the bucket is drained, or the key is new and the table is full of buckets that have not refilled, it writes the 429 and returns true. A nil receiver returns false.