activator

package
v0.1.3 Latest Latest
Warning

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

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

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 New

func New(d Deps) (*Activator, error)

New builds the activator. Endpoints and Scaler are required.

func (*Activator) ReclaimIdle

func (a *Activator) ReclaimIdle(ctx context.Context) error

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

func (a *Activator) Run(ctx context.Context) error

Run calls ReclaimIdle every ReclaimInterval until ctx is cancelled.

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

func (a *Activator) Wake(ctx context.Context, fn FunctionRef) (string, error)

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.

type Scaler

type Scaler interface {
	ScaleTo(ctx context.Context, fn FunctionRef, replicas int) error
}

Scaler drives a function toward a target replica count (V1 uses only 0 and 1).

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.

Jump to

Keyboard shortcuts

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