scaler

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWindowsGracefulScaleInNotSupported = errors.New("graceful scale-in not supported on Windows")

ErrWindowsGracefulScaleInNotSupported is returned when attempting graceful scale-in on Windows instances. Windows instances don't support SIGTERM-based graceful shutdown; they rely on lifecycle hooks instead.

Functions

func LoadAWSConfig added in v1.12.0

func LoadAWSConfig(ctx context.Context) (aws.Config, error)

LoadAWSConfig loads the AWS SDK config with adaptive retry mode and 8 max attempts. The SDK default (3 attempts, no client-side rate limiting) gives up on throttling errors when many scaler Lambdas hit the same APIs at once.

Set AWS_RETRY_MODE or AWS_MAX_ATTEMPTS to override.

func RetrieveFromParameterStore

func RetrieveFromParameterStore(cfg aws.Config, key string) (string, error)

Types

type ASGDriver added in v1.2.0

type ASGDriver struct {
	Name                              string
	Cfg                               aws.Config
	MaxDescribeScalingActivitiesPages int
	ElasticCIMode                     bool
	MinimumInstanceUptime             time.Duration
	MaxDanglingInstancesToCheck       int           // Maximum number of instances to check for dangling instances (only used for dangling instance scanning, not for normal scale-in)
	DanglingInstancesCheckInterval    time.Duration // Interval between dangling-instance checks; used to rotate the check window. Defaults to 60s when 0.
	// contains filtered or unexported fields
}

func (*ASGDriver) CleanupDanglingInstances added in v1.9.3

func (a *ASGDriver) CleanupDanglingInstances(ctx context.Context, minimumInstanceUptime time.Duration, maxDanglingInstancesToCheck int) error

CleanupDanglingInstances finds and marks unhealthy any "zombie" instances where the buildkite-agent service has stopped running but the EC2 instance is still alive.

This is different from normal scale-in: - Normal scale-in: instances are healthy, jobs may be running -> uses SIGTERM for graceful shutdown - This function: agent service is stopped, no jobs can be running -> safe to mark as unhealthy

Marking instances unhealthy (via autoscaling:SetInstanceHealth) causes the ASG to terminate and replace them according to its configured policies.

func (*ASGDriver) Describe added in v1.2.0

func (a *ASGDriver) Describe(ctx context.Context) (AutoscaleGroupDetails, error)

func (*ASGDriver) GetAutoscalingActivities added in v1.2.0

func (a *ASGDriver) GetAutoscalingActivities(ctx context.Context, nextToken *string) (*autoscaling.DescribeScalingActivitiesOutput, error)

func (*ASGDriver) GetLastScalingInAndOutActivity added in v1.2.0

func (a *ASGDriver) GetLastScalingInAndOutActivity(ctx context.Context, findScaleOut, findScaleIn bool) (*types.Activity, *types.Activity, error)

func (*ASGDriver) SendSIGTERMToAgents added in v1.9.3

func (a *ASGDriver) SendSIGTERMToAgents(ctx context.Context, instanceID string) error

func (*ASGDriver) SetDesiredCapacity added in v1.2.0

func (a *ASGDriver) SetDesiredCapacity(ctx context.Context, count int64) error

type AutoscaleGroupDetails

type AutoscaleGroupDetails struct {
	Pending      int64
	DesiredCount int64
	MinSize      int64
	MaxSize      int64
	InstanceIDs  []string // Instance IDs in the ASG
	ActualCount  int64    // Actual number of running instances
}

type Params

type Params struct {
	AutoScalingGroupName           string
	AgentsPerInstance              int
	BuildkiteAgentToken            string
	BuildkiteQueue                 string
	UserAgent                      string
	PublishCloudWatchMetrics       bool
	DryRun                         bool
	IncludeWaiting                 bool
	ScaleInParams                  ScaleParams
	ScaleOutParams                 ScaleParams
	InstanceBuffer                 int
	ScaleOnlyAfterAllEvent         bool
	AvailabilityThreshold          float64       // Threshold for agent availability (default 50%, all modes)
	ASGActivityCooldown            time.Duration // How long to wait after an ASG activity before scaling again
	ElasticCIMode                  bool          // Special mode for Elastic CI Stack with additional safety checks
	MinimumInstanceUptime          time.Duration // How long instance should be online before being eligible for dangling instance check
	MaxDanglingInstancesToCheck    int           // Maximum number of instances to check for dangling instances (only used for dangling instance scanning, not for normal scale-in)
	MaxInstanceCap                 int           // Maximum instance count cap (0 means no cap)
	DanglingInstancesCheckInterval time.Duration // Interval between dangling-instance checks; used to rotate the check window. Defaults to 60s when 0.
}

type ScaleParams

type ScaleParams struct {
	Disable        bool
	CooldownPeriod time.Duration
	Factor         float64
	LastEvent      time.Time
}

type Scaler

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

func NewScaler

func NewScaler(client *buildkite.Client, cfg aws.Config, params Params) (*Scaler, error)

func (*Scaler) LastScaleIn

func (s *Scaler) LastScaleIn() time.Time

func (*Scaler) LastScaleOut

func (s *Scaler) LastScaleOut() time.Time

func (*Scaler) Run

func (s *Scaler) Run(ctx context.Context) (time.Duration, error)

type ScalingCalculator added in v1.1.0

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

func (*ScalingCalculator) DesiredCount added in v1.1.0

func (sc *ScalingCalculator) DesiredCount(metrics *buildkite.AgentMetrics, asg *AutoscaleGroupDetails) int64

Jump to

Keyboard shortcuts

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