limit

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

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

func Chain

func Chain(cfg Config) func(http.Handler) http.Handler

Chain returns a single middleware composing rate → size → concurrency (cheapest reject first). Its rate step runs only when cfg.Key is not KeyFunction. A zero Config is a pass-through.

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 Key

type Key string

Key selects the rate-limit bucket dimension.

const (
	// KeyClientIP buckets per client IP: the RemoteAddr host; checked by Chain.
	KeyClientIP Key = "clientIP"
	// KeyFunction buckets per resolved (namespace, function); checked by TargetLimiter (ADR-0164).
	KeyFunction Key = "function"
)

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

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.

Jump to

Keyboard shortcuts

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