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.