scaletozero

package
v0.0.0-...-11e1b04 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(ctrl Controller) func(http.Handler) http.Handler

Middleware returns a standard net/http middleware that disables scale-to-zero at the start of each request and re-enables it after the handler completes. Connections from loopback addresses are ignored and do not affect the scale-to-zero state.

Types

type Controller

type Controller interface {
	// Disable turns scale-to-zero off.
	Disable(ctx context.Context) error
	// Enable re-enables scale-to-zero after it has previously been disabled.
	Enable(ctx context.Context) error
}

func NewUnikraftCloudController

func NewUnikraftCloudController() Controller

type DebouncedController

type DebouncedController struct {
	// contains filtered or unexported fields
}

func NewDebouncedController

func NewDebouncedController(ctrl Controller) *DebouncedController

NewDebouncedController creates a DebouncedController with no re-enable cooldown.

func NewDebouncedControllerWithCooldown

func NewDebouncedControllerWithCooldown(ctrl Controller, cooldown time.Duration) *DebouncedController

NewDebouncedControllerWithCooldown creates a DebouncedController that delays re-enabling scale-to-zero by the given cooldown after the last active holder releases. A new Disable call during the cooldown cancels the pending re-enable, avoiding rapid toggling from sequential requests.

func (*DebouncedController) Disable

func (c *DebouncedController) Disable(ctx context.Context) error

func (*DebouncedController) Enable

func (c *DebouncedController) Enable(ctx context.Context) error

func (*DebouncedController) Pin

Pin sets the out-of-band pin and ensures scale-to-zero is disabled. Idempotent: re-pinning while already pinned is a no-op. Cancels any pending cooldown timer.

func (*DebouncedController) Unpin

func (c *DebouncedController) Unpin(ctx context.Context) error

Unpin releases the pin. If no request-driven holders remain, scale-to-zero is re-enabled (honoring any configured cooldown). Idempotent: calling when no pin is held is a no-op.

type NoopController

type NoopController struct{}

func NewNoopController

func NewNoopController() *NoopController

func (NoopController) Disable

func (NoopController) Enable

func (NoopController) Pin

func (NoopController) Unpin

type Oncer

type Oncer struct {
	// contains filtered or unexported fields
}

Oncer wraps a Controller and ensures that Disable and Enable are called at most once.

func NewOncer

func NewOncer(c Controller) *Oncer

func (*Oncer) Disable

func (o *Oncer) Disable(ctx context.Context) error

func (*Oncer) Enable

func (o *Oncer) Enable(ctx context.Context) error

type PinnedController

type PinnedController interface {
	Controller
	// Pin holds scale-to-zero disabled until Unpin is called. The pin is a
	// boolean, not a counter: repeated calls are idempotent.
	Pin(ctx context.Context) error
	// Unpin releases the pin. If no request-driven holders remain,
	// scale-to-zero is re-enabled (honoring any configured cooldown).
	Unpin(ctx context.Context) error
}

PinnedController extends Controller with an out-of-band "pin" that holds scale-to-zero disabled independently of the request-driven refcount used by the HTTP middleware. While the pin is held, request-driven Enable calls do not re-enable scale-to-zero; only Unpin can release it.

This is intended for explicit lifecycle control (e.g. a control-plane API reserving a VM in a hot pool) where the holder is not tied to an inflight HTTP request.

Jump to

Keyboard shortcuts

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