Documentation
¶
Overview ¶
Package activator implements scale-to-zero (ADR-0016): an in-process data-path component backing a gateway route's upstream. For a request to a scaled-to-zero function it buffers the request, single-flights a wake (Scaler.ScaleTo(fn,1)), waits for a ready upstream to appear, then forwards the held request (or 503s on timeout); and it runs a periodic idle-reclaim pass that scales idle functions to zero. It emits a scale INTENT through two seams (Endpoints read / Scaler write); it does not provision workeres (that is the P-M Function reconciler) and it does not register a Function reconciler (one-reconciler-per-gvk, ADR-0015).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithFunction ¶
func WithFunction(r *http.Request, fn FunctionRef) *http.Request
WithFunction returns r carrying fn for ServeHTTP. The gateway route wiring (P-I) sets it from the matched route; tests set it directly.
Types ¶
type Activator ¶
type Activator struct {
// contains filtered or unexported fields
}
Activator is the scale-to-zero data path + idle-reclaim component.
func (*Activator) ReclaimIdle ¶
ReclaimIdle scales to zero every minReplicas==0 function whose last activity is older than its IdleTimeout. Functions with recent activity, MinReplicas != 0, or a zero IdleTimeout (reclaim disabled) are skipped. A function not yet seen is seeded at the current time (a full grace window) and reclaimed only on a later pass.
func (*Activator) ServeHTTP ¶
func (a *Activator) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves one request: warm → proxy now; cold → single-flight ScaleTo(1), wait for a ready upstream (bounded by ActivationTimeout), then forward. On activation timeout → 503 problem+json; a request with no FunctionRef in context → 500 problem+json.
func (*Activator) Wake ¶
Wake returns fn's ready upstream, single-flight-activating (ScaleTo(1) + poll, bounded by ActivationTimeout) if it is cold — the shared wake primitive (ADR-0033) used by both the data-plane cold path (ServeHTTP) and the eventing trigger path. It records activity (touch, feeding idle reclaim); an Endpoints error → fault.Unavailable; a ready function returns its upstream immediately; a not-ready one is woken via the existing per-fn singleflight.
type Deps ¶
type Deps struct {
Store store.Store // lists Functions for idle reclaim
Endpoints Endpoints // ready-upstream resolver (required)
Scaler Scaler // scale-intent writer (required)
Clock clock.Clock // default clock.System()
Logger *slog.Logger // default slog.Default()
ActivationTimeout time.Duration // cold-start hold bound; default 30s
PollInterval time.Duration // ready-poll cadence; default 25ms
ReclaimInterval time.Duration // idle-reclaim cadence for Run; default 30s
}
Deps configures the activator (internal component, ADR-0002 §1).
type Endpoints ¶
type Endpoints interface {
// Upstream returns the ready upstream base URL for fn and whether one exists.
Upstream(ctx context.Context, fn FunctionRef) (upstream string, ready bool, err error)
}
Endpoints resolves a function's currently-ready upstream. P-M/scheduler provide the production driver (from the provisioned replica set); tests inject a fake.
type FunctionRef ¶
type FunctionRef struct {
Namespace v1.NamespaceName
Name v1.ObjectName
}
FunctionRef identifies the function a request / scale-decision targets.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package storescaler is the V1 store-backed activator.Scaler driver (ADR-0016): it records a function's scale intent as its partitioned status Phase — the wake edge Idle→Deploying for replicas>=1, the reclaim edge *→Idle for replicas==0 — via store.Update.
|
Package storescaler is the V1 store-backed activator.Scaler driver (ADR-0016): it records a function's scale intent as its partitioned status Phase — the wake edge Idle→Deploying for replicas>=1, the reclaim edge *→Idle for replicas==0 — via store.Update. |