spotadvisor

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 5 Imported by: 2

README

spotadvisor

This package provides an interface for fetching and utilizing AWS Spot Advisor data.

The data is sourced from: https://spot-bid-advisor.s3.amazonaws.com/spot-advisor-data.json

The available data are:

  1. Interrupt rate data, described as:

    Frequency of interruption represents the rate at which Spot has reclaimed capacity during the trailing month. They are in ranges of < 5%, 5-10%, 10-15%, 15-20% and >20%.

  2. Savings data, described as:

    Savings compared to On-Demand are calculated over the last 30 days. Please note that price history data is averaged across Availability Zones and may be delayed. To view current Spot prices, visit the Spot Price History in the AWS Management Console for up to date pricing information for each Availability Zone.

See godoc for usage.

Documentation

Overview

Package spotadvisor provides an interface for utilizing spot instance interrupt rate data and savings data from AWS.

Index

Constants

View Source
const (
	Linux   = OsType("Linux")
	Windows = OsType("Windows")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AwsRegion

type AwsRegion string

AwsRegion is an AWS region name like "us-west-2".

type InstanceType

type InstanceType string

InstanceType is an EC2 instance type name like "r5a.large".

type InterruptProbability

type InterruptProbability int

InterruptProbability is an upper bound used to indicate multiple interrupt ranges; it should only be used via the pre-defined constants in this package.

const (
	LessThanFivePct InterruptProbability = iota
	LessThanTenPct
	LessThanFifteenPct
	LessThanTwentyPct
	Any
)

These need to be in their own const block to ensure iota starts at 0.

func (InterruptProbability) String

func (ir InterruptProbability) String() string

type InterruptRange

type InterruptRange int

InterruptRange is the AWS defined interrupt range for an instance type; it should only be used via the pre-defined constants in this package.

const (
	ZeroToFivePct InterruptRange = iota
	FiveToTenPct
	TenToFifteenPct
	FifteenToTwentyPct
	GreaterThanTwentyPct
)

These need to be in their own const block to ensure iota starts at 0.

func (InterruptRange) String

func (ir InterruptRange) String() string

type OsType

type OsType string

OsType should only be used via the pre-defined constants in this package.

type SimpleLogger

type SimpleLogger interface {
	Printf(string, ...interface{})
}

SimpleLogger is a bare-bones logger interface which allows many logger implementations to be used with SpotAdvisor. The default Go log.Logger and grailbio/base/log.Logger implement this interface.

type SpotAdvisor

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

SpotAdvisor provides an interface for utilizing spot instance interrupt rate data and savings data from AWS.

func NewSpotAdvisor

func NewSpotAdvisor(log SimpleLogger, done <-chan struct{}) (*SpotAdvisor, error)

NewSpotAdvisor initializes and returns a SpotAdvisor instance. If initialization fails, a nil SpotAdvisor is returned with an error. The underlying data is asynchronously updated, until the done channel is closed. Errors during updates are non-fatal and will not prevent future updates.

func (*SpotAdvisor) FilterByMaxInterruptProbability

func (sa *SpotAdvisor) FilterByMaxInterruptProbability(ot OsType, ar AwsRegion, candidates []string, ip InterruptProbability) (filtered []string, err error)

FilterByMaxInterruptProbability returns a subset of the input candidates by removing instance types which have a probability of interruption greater than ip.

func (*SpotAdvisor) GetInstancesWithMaxInterruptProbability

func (sa *SpotAdvisor) GetInstancesWithMaxInterruptProbability(ot OsType, region AwsRegion, ip InterruptProbability) (map[string]bool, error)

GetInstancesWithMaxInterruptProbability returns the set of spot instance types with an interrupt probability less than or equal to ip, with the given OS and region.

func (*SpotAdvisor) GetInterruptRange

func (sa *SpotAdvisor) GetInterruptRange(ot OsType, ar AwsRegion, it InstanceType) (InterruptRange, error)

GetInterruptRange returns the interrupt range for the instance type with the given OS and region.

func (*SpotAdvisor) GetMaxInterruptProbability

func (sa *SpotAdvisor) GetMaxInterruptProbability(ot OsType, ar AwsRegion, it InstanceType) (InterruptProbability, error)

GetMaxInterruptProbability is a helper method to easily get the max interrupt probability of an instance type (i.e. the upper bound of the interrupt range for that instance type).

Jump to

Keyboard shortcuts

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