Documentation

Index

Constants

View Source
const (

	// OnDemandPercentageTag is the name of a tag that can be defined on a
	// per-group level for overriding maintained on-demand capacity given as a
	// percentage of the group's running instances.
	OnDemandPercentageTag = "autospotting_min_on_demand_percentage"

	// OnDemandNumberLong is the name of a tag that can be defined on a
	// per-group level for overriding maintained on-demand capacity given as an
	// absolute number.
	OnDemandNumberLong = "autospotting_min_on_demand_number"

	// OnDemandPriceMultiplierTag is the name of a tag that can be defined on a
	// per-group level for overriding multiplier for the on-demand price.
	OnDemandPriceMultiplierTag = "autospotting_on_demand_price_multiplier"

	// BiddingPolicyTag stores the bidding policy for the spot instance
	BiddingPolicyTag = "autospotting_bidding_policy"

	// SpotPriceBufferPercentageTag stores percentage value above the
	// current spot price to place the bid
	SpotPriceBufferPercentageTag = "autospotting_spot_price_buffer_percentage"

	// AllowedInstanceTypesTag is the name of a tag that can indicate which
	// instance types are allowed in the current group
	AllowedInstanceTypesTag = "autospotting_allowed_instance_types"

	// DisallowedInstanceTypesTag is the name of a tag that can indicate which
	// instance types are not allowed in the current group
	DisallowedInstanceTypesTag = "autospotting_disallowed_instance_types"

	// DefaultSpotProductDescription stores the default operating system
	// to use when looking up spot price history in the market.
	DefaultSpotProductDescription = "Linux/UNIX (Amazon VPC)"

	// DefaultSpotProductPremium stores the default value to add to the
	// on demand price for premium instance types.
	DefaultSpotProductPremium = 0.0

	// DefaultMinOnDemandValue stores the default on-demand capacity to be kept
	// running in a group managed by autospotting.
	DefaultMinOnDemandValue = 0

	// DefaultSpotPriceBufferPercentage stores the default percentage value
	// above the current spot price to place a bid
	DefaultSpotPriceBufferPercentage = 10.0

	// DefaultBiddingPolicy stores the default bidding policy for
	// the spot bid on a per-group level
	DefaultBiddingPolicy = "normal"

	// DefaultOnDemandPriceMultiplier stores the default OnDemand price multiplier
	// on a per-group level
	DefaultOnDemandPriceMultiplier = 1.0

	// DefaultInstanceTerminationMethod is the default value for the instance termination
	// method configuration option
	DefaultInstanceTerminationMethod = AutoScalingTerminationMethod

	// ScheduleTag is the name of the tag set on the AutoScaling Group that
	// can override the global value of the Schedule parameter
	ScheduleTag = "autospotting_cron_schedule"

	// TimezoneTag is the name of the tag set on the AutoScaling Group that
	// can override the global value of the Timezone parameter
	TimezoneTag = "autospotting_cron_timezone"

	// CronScheduleStateOn controls whether to run or not to run during the time interval
	// specified in the Schedule variable or its per-group tag overrides. It
	// accepts "on|off" as valid values
	CronScheduleStateOn = "on"

	// CronScheduleStateTag is the name of the tag set on the AutoScaling Group that
	// can override the global value of the CronScheduleState parameter
	CronScheduleStateTag = "autospotting_cron_schedule_state"

	// EnableInstanceLaunchEventHandlingTag is the name of the tag set on the
	// AutoScaling Group that enables the event-based instance replacement logic
	// for this group. It is set automatically once the legacy cron-based
	// replacement logic is done replacing in stances in any given group.
	EnableInstanceLaunchEventHandlingTag = "autospotting_enable_instance_launch_event_handling"

	// PatchBeanstalkUserdataTag is the name of the tag set on the AutoScaling Group that
	// can override the global value of the PatchBeanstalkUserdata parameter
	PatchBeanstalkUserdataTag = "patch_beanstalk_userdata"
)
View Source
const (
	// AutoScalingTerminationMethod uses the TerminateInstanceInAutoScalingGroup
	// API method to terminate instances.  This method is recommended because it
	// will require termination Lifecycle Hooks that have been configured on the
	// Auto Scaling Group to be invoked before terminating the instance.  It's
	// also safe even if there are no such hooks configured.
	AutoScalingTerminationMethod = "autoscaling"

	// DetachTerminationMethod detaches the instance from the Auto Scaling Group
	// and then terminates it.  This method exists for historical reasons and is
	// no longer recommended.
	DetachTerminationMethod = "detach"

	// TerminateTerminationNotificationAction terminate the spot instance, which will be terminated
	// by AWS in 2 minutes, without reducing the ASG capacity, so that a new instance will
	// be launched. LifeCycle Hooks are triggered.
	TerminateTerminationNotificationAction = "terminate"

	// DetachTerminationNotificationAction detach the spot instance, which will be terminated
	// by AWS in 2 minutes, without reducing the ASG capacity, so that a new instance will
	// be launched. LifeCycle Hooks are not triggered.
	DetachTerminationNotificationAction = "detach"

	// AutoTerminationNotificationAction if ASG has a LifeCycleHook with LifecycleTransition = EC2_INSTANCE_TERMINATING
	// terminate the spot instance (as TerminateTerminationNotificationAction), if not detach it.
	AutoTerminationNotificationAction = "auto"

	// DefaultCronSchedule is the default value for the execution schedule in
	// simplified Cron-style definition the cron format only accepts the hour and
	// day of week fields, for example "9-18 1-5" would define the working week
	// hours. AutoSpotting will only run inside this time interval. The action can
	// also be reverted using the CronScheduleState parameter, so in order to run
	// outside this interval set the CronScheduleState to "off" either globally or
	// on a per-group override.
	DefaultCronSchedule = "* *"
)
View Source
const (
	// DefaultTerminationNotificationAction is the default value for the termination notification
	// action configuration option
	DefaultTerminationNotificationAction = AutoTerminationNotificationAction
)

Variables

This section is empty.

Functions

func ParseConfig

func ParseConfig(conf *Config)

    ParseConfig loads configuration from command line flags, environments variables, and config files.

    Types

    type AutoScalingConfig

    type AutoScalingConfig struct {
    	MinOnDemandNumber       int64
    	MinOnDemandPercentage   float64
    	AllowedInstanceTypes    string
    	DisallowedInstanceTypes string
    
    	OnDemandPriceMultiplier   float64
    	SpotPriceBufferPercentage float64
    
    	SpotProductDescription string
    	SpotProductPremium     float64
    
    	BiddingPolicy string
    
    	TerminationMethod string
    
    	// Instance termination method
    	InstanceTerminationMethod string
    
    	// Termination Notification action
    	TerminationNotificationAction string
    
    	CronSchedule      string
    	CronTimezone      string
    	CronScheduleState string // "on" or "off", dictate whether to run inside the CronSchedule or not
    
    	PatchBeanstalkUserdata string
    }

      AutoScalingConfig stores some group-specific configurations that can override their corresponding global values

      type AutoSpotting

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

        AutoSpotting hosts global configuration and has as methods all the public entrypoints of this library

        func (*AutoSpotting) EventHandler

        func (a *AutoSpotting) EventHandler(event *json.RawMessage)

          EventHandler implements the event handling logic and is the main entrypoint of AutoSpotting

          func (*AutoSpotting) Init

          func (a *AutoSpotting) Init(cfg *Config)

            Init initializes some data structures reusable across multiple event runs

            func (*AutoSpotting) ProcessCronEvent

            func (a *AutoSpotting) ProcessCronEvent()

              ProcessCronEvent starts processing all AWS regions looking for AutoScaling groups enabled and taking action by replacing more pricy on-demand instances with compatible and cheaper spot instances.

              type CloudTrailEvent

              type CloudTrailEvent struct {
              	EventName         string            `json:"eventName"`
              	AwsRegion         string            `json:"awsRegion"`
              	ErrorCode         string            `json:"errorCode"`
              	ErrorMessage      string            `json:"errorMessage"`
              	RequestParameters RequestParameters `json:"requestParameters"`
              }

                CloudTrailEvent s used to unmarshal a CloudTrail Event from the Detail field of a CloudWatch event

                type Config

                type Config struct {
                	AutoScalingConfig
                
                	// Static data fetched from ec2instances.info
                	InstanceData *ec2instancesinfo.InstanceData
                
                	// Logging
                	LogFile io.Writer
                	LogFlag int
                
                	// The regions where it should be running, given as a single CSV-string
                	Regions string
                
                	// The region where the Lambda function is deployed
                	MainRegion string
                
                	// This is only here for tests, where we want to be able to somehow mock
                	// time.Sleep without actually sleeping. While testing it defaults to 0 (which won't sleep at all), in
                	// real-world usage it's expected to be set to 1
                	SleepMultiplier time.Duration
                
                	// Filter on ASG tags
                	// for example: spot-enabled=true,environment=dev,team=interactive
                	FilterByTags string
                	// Controls how are the tags used to filter the groups.
                	// Available options: 'opt-in' and 'opt-out', default: 'opt-in'
                	TagFilteringMode string
                
                	// The AutoSpotting version
                	Version string
                
                	// The license of this AutoSpotting build - obsolete
                	LicenseType string
                
                	// Controls whether AutoSpotting patches Elastic Beanstalk UserData scripts to use
                	// the instance role when calling CloudFormation helpers instead of the standard CloudFormation
                	// authentication method
                	PatchBeanstalkUserdata string
                
                	// Lambda to use for Managing ASG
                	LambdaManageASG string
                
                	// JSON file containing event data used for locally simulating execution from Lambda.
                	EventFile string
                
                	// Final Recap String Array to show actions taken by ScheduleRun on ASGs
                	FinalRecap map[string][]string
                }

                  Config extends the AutoScalingConfig struct and in addition contains a number of global flags.

                  type RequestParameters

                  type RequestParameters struct {
                  	LifecycleHookName     string `json:"lifecycleHookName"`
                  	InstanceID            string `json:"instanceId"`
                  	LifecycleActionResult string `json:"lifecycleActionResult"`
                  	AutoScalingGroupName  string `json:"autoScalingGroupName"`
                  }

                    RequestParameters is used to unmarshal the parameters of a CloudTrail event

                    type SpotTermination

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

                      SpotTermination is used to detach an instance, used when a spot instance is due for termination

                      func (*SpotTermination) IsInAutoSpottingASG

                      func (s *SpotTermination) IsInAutoSpottingASG(instanceID *string, tagFilteringMode string, filterByTags string) bool

                        IsInAutoSpottingASG checks to see whether an instance is in an AutoSpotting ASG as defined by its tags. If the ASG does not have the required tags, it is not an AutoSpotting ASG and should be left alone.

                        type Tag

                        type Tag struct {
                        	Key   string
                        	Value string
                        }

                          Tag represents an Asg Tag: Key, Value