scaletozero

package
v0.0.0-...-70d2dba Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveResponseCloseMonitors

func ActiveResponseCloseMonitors() int64

func ActiveResponseHolds

func ActiveResponseHolds() int64

func FailClosedResponseHolds

func FailClosedResponseHolds() int64

func Middleware

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

Middleware holds scale-to-zero disabled until each non-loopback HTTP response is finalized and its TCP send queue drains or the connection terminates.

func ResponseCloseMonitorRejections

func ResponseCloseMonitorRejections() uint64

func ResponseDrainOutcomeCounts

func ResponseDrainOutcomeCounts() map[string]uint64

ResponseDrainOutcomeCounts returns process-lifetime response drain counters.

func Serve

func Serve(server *http.Server, listener net.Listener) error

Serve adds TCP response tracking to server before serving listener.

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