cloudscale

package
v0.31.5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: GPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cloudscale is the control node's autoscaling bridge to AWS. It turns the fleet's live state into the two signals an EC2 Auto Scaling group needs to run the worker tier on demand from zero:

  • UnservedDemand — the count of distinct previews whose placement found no worker (fleet.Registry.DrainDemand; deduplicated per interval, so retries of one preview read as demand 1). This is the scale-OUT-from-zero signal: LoadRatio can't distinguish "idle at zero" from "saturated" (both score 1), so capacity is added when a request arrives with nowhere to run.
  • FleetLoad — fleet utilization as a percentage (fleet.Registry.LoadSample), published ONLY when at least one worker is fresh. It drives scale-out under load and scale-in when idle. Suppressing it at zero workers keeps the scale-in alarm from seeing phantom data before the fleet exists.
  • IdleWorkers — fresh, non-draining workers serving nothing (fleet.Registry.IdleWorkers), published under the same guard. Its alarm reclaims an empty node during working hours, when the min-warm floor keeps FleetLoad above the scale-in threshold no matter how much spare capacity sits idle.

It also reconciles EC2 instance scale-in protection from the fleet's per-instance busy map, so an ASG scale-in drains an idle node instead of terminating one mid-preview.

This runs on the control node only. It needs exactly cloudwatch:PutMetricData and autoscaling:SetInstanceProtection on the instance role — busy-ness comes from the live fleet registry, never a Describe call, so don't widen the role with one. A node without those grants (or without an ASG name) simply doesn't start the publisher.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Region    string
	ASGName   string
	Namespace string        // CloudWatch namespace; defaults to "LocalPreview"
	Interval  time.Duration // publish cadence; defaults to 30s
}

Config parameterizes the publisher. ASGName is required (it is the CloudWatch dimension and the SetInstanceProtection target); an empty one means this node is not part of an autoscaled deployment and the caller should not start a publisher.

type Fleet

type Fleet interface {
	// DrainDemand returns the count of distinct previews that went unserved
	// since the last call and resets the set.
	DrainDemand() int64
	// LoadSample returns fleet utilization percent and the count of fresh
	// workers (0 workers => don't publish load).
	LoadSample() (loadPct float64, workers int)
	// BusyByInstance maps each fresh worker's instance-id to whether it is
	// serving a preview.
	BusyByInstance() map[string]bool
	// IdleWorkers counts fresh, non-draining autoscaled workers serving
	// nothing — nodes the ASG can reclaim without disturbing any preview.
	IdleWorkers() int
}

Fleet is the slice of the fleet registry the publisher reads. fleet.Registry satisfies it; a fake satisfies it in tests.

type Publisher

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

Publisher pushes fleet metrics to CloudWatch and reconciles scale-in protection on an interval.

func New

func New(ctx context.Context, fleet Fleet, cfg Config) (*Publisher, error)

New builds a Publisher with real AWS clients from the ambient credential chain (the instance role in production). ASGName must be non-empty.

func (*Publisher) Run

func (p *Publisher) Run(ctx context.Context)

Run publishes immediately and every Interval until ctx is cancelled. It never returns an error: a transient AWS failure is logged and retried next tick, so one bad call can't wedge the control node's scaling.

Jump to

Keyboard shortcuts

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