Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AutoScalingAPIClient ¶
type AutoScalingAPIClient interface { DescribeAutoScalingInstances(context.Context, *autoscaling.DescribeAutoScalingInstancesInput, ...func(*autoscaling.Options)) (*autoscaling.DescribeAutoScalingInstancesOutput, error) SetInstanceProtection(context.Context, *autoscaling.SetInstanceProtectionInput, ...func(*autoscaling.Options)) (*autoscaling.SetInstanceProtectionOutput, error) }
AutoScalingAPIClient extracts the subset of autoscaling.Client APIs that ScaleInProtector uses.
type ScaleInProtector ¶
type ScaleInProtector struct { // InstanceId is the instance Id to enable or disable scale-in protection. // // If not specified, an imds.Client created from the default aws.Config (config.LoadDefaultConfig) will be used to // detect the instance Id of the host. If one cannot be detected, StartMonitoring will return a non-nil error. InstanceId string // AutoScalingGroupName is the name of the Auto Scaling group that contains the instance specified by InstanceId. // // If not specified, the given AutoScaling will be used to find the Auto Scaling group that contains the instance // specified by InstanceId. If one cannot be found, StartMonitoring will return a non-nil error. If both InstanceId // and AutoScalingGroupName are given but the Auto Scaling group does not contain the instance, an error is also // returned (you cannot have the monitor effects an instance different from the one it's running on for safety). If // you want an option to disable this check, send a PR. AutoScalingGroupName string // AutoScaling is the client that will be used to make Auto Scaling service calls. // // If not given, an autoscaling.Client created from the default aws.Config (config.LoadDefaultConfig) will be used. AutoScaling AutoScalingAPIClient // IdleAtLeast specifies the amount of time all workers must have been idle before scale-in protection may be // disabled. // // The delay starts from when the last worker becomes idle. If you want to measure from the moment the first worker // becomes idle, send a PR (trailing vs. leading delay). IdleAtLeast time.Duration // Logger is used to log whenever the scale-in protection changes. // // Defaults to log.Default. Logger *log.Logger // contains filtered or unexported fields }
ScaleInProtector monitors active statuses of several workers to enable or disable scale-in protection accordingly.
The zero value ScaleInProtector is ready for use. StartMonitoring should be called in a separate goroutine to start the monitoring loop. Each worker then calls either SignalActive or SignalIdle at the appropriate time, passing the worker identifier as the sole argument.
func (*ScaleInProtector) IsProtectedFromScaleIn ¶
func (s *ScaleInProtector) IsProtectedFromScaleIn() bool
IsProtectedFromScaleIn returns the internal flag reflecting whether scale-in protection is enabled or not.
It is entirely possible for the monitor to think it has scale-in protection enabled while an external action may have disabled it and vice versa.
func (*ScaleInProtector) SignalActive ¶
func (s *ScaleInProtector) SignalActive(id string)
SignalActive should be called by a worker passing its identifier when it has an active job.
It is safe to call this method even if StartMonitoring hasn't been called. The method may block if there are concurrent calls to either SignalActive and SignalIdle. Once StartMonitoring has been called, the method may also block until the scale-in protection change has been effected.
func (*ScaleInProtector) SignalIdle ¶
func (s *ScaleInProtector) SignalIdle(id string)
SignalIdle should be called by a worker passing its identifier when it has become idle.
It is safe to call this method even if StartMonitoring hasn't been called. The method may block if there are concurrent calls to either SignalActive and SignalIdle. Once StartMonitoring has been called, the method may also block until the scale-in protection change has been effected.
func (*ScaleInProtector) StartMonitoring ¶
func (s *ScaleInProtector) StartMonitoring(ctx context.Context) (err error)
StartMonitoring starts the monitoring loop.
The method should be called in a separate goroutine because it will not return until the given context is cancelled; context.Context.Err is always returned in this case. Errors from making Auto Scaling service calls also cause the loop to terminate.
Panics if StartMonitoring has been called more than once.