ec2pricing

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ODCacheFileName = "on-demand-pricing-cache.json"
)
View Source
const (
	SpotCacheFileName = "spot-pricing-cache.gob"
)

Variables

View Source
var (
	DefaultSpotDaysBack = 30
)

Functions

This section is empty.

Types

type EC2Pricing

type EC2Pricing struct {
	ODPricing   *OnDemandPricing
	SpotPricing *SpotPricing
	// contains filtered or unexported fields
}

EC2Pricing is the public struct to interface with AWS pricing APIs

func New

func New(ctx context.Context, cfg aws.Config) (*EC2Pricing, error)

New creates an instance of instance-selector EC2Pricing

func NewWithCache

func NewWithCache(ctx context.Context, cfg aws.Config, ttl time.Duration, cacheDir string) (*EC2Pricing, error)

func (*EC2Pricing) GetOnDemandInstanceTypeCost

func (p *EC2Pricing) GetOnDemandInstanceTypeCost(ctx context.Context, instanceType ec2types.InstanceType) (float64, error)

GetOnDemandInstanceTypeCost retrieves the on-demand hourly cost for the specified instance type

func (*EC2Pricing) GetSpotInstanceTypeNDayAvgCost

func (p *EC2Pricing) GetSpotInstanceTypeNDayAvgCost(ctx context.Context, instanceType ec2types.InstanceType, availabilityZones []string, days int) (float64, error)

GetSpotInstanceTypeNDayAvgCost retrieves the spot price history for a given AZ from the past N days and averages the price Passing an empty list for availabilityZones will retrieve avg cost for all AZs in the current AWSSession's region

func (*EC2Pricing) OnDemandCacheCount

func (p *EC2Pricing) OnDemandCacheCount() int

OnDemandCacheCount returns the number of items in the OD cache

func (*EC2Pricing) RefreshOnDemandCache

func (p *EC2Pricing) RefreshOnDemandCache(ctx context.Context) error

RefreshOnDemandCache makes a bulk request to the pricing api to retrieve all instance type pricing and stores them in a local cache

func (*EC2Pricing) RefreshSpotCache

func (p *EC2Pricing) RefreshSpotCache(ctx context.Context, days int) error

RefreshSpotCache makes a bulk request to the ec2 api to retrieve all spot instance type pricing and stores them in a local cache

func (*EC2Pricing) Save

func (p *EC2Pricing) Save() error

func (*EC2Pricing) SetLogger

func (p *EC2Pricing) SetLogger(logger *log.Logger)

func (*EC2Pricing) SpotCacheCount

func (p *EC2Pricing) SpotCacheCount() int

SpotCacheCount returns the number of items in the spot cache

type EC2PricingIface

type EC2PricingIface interface {
	GetOnDemandInstanceTypeCost(ctx context.Context, instanceType ec2types.InstanceType) (float64, error)
	GetSpotInstanceTypeNDayAvgCost(ctx context.Context, instanceType ec2types.InstanceType, availabilityZones []string, days int) (float64, error)
	RefreshOnDemandCache(ctx context.Context) error
	RefreshSpotCache(ctx context.Context, days int) error
	OnDemandCacheCount() int
	SpotCacheCount() int
	Save() error
	SetLogger(*log.Logger)
}

EC2PricingIface is the EC2Pricing interface mainly used to mock out ec2pricing during testing

type OnDemandPricing

type OnDemandPricing struct {
	Region         string
	FullRefreshTTL time.Duration
	DirectoryPath  string

	sync.RWMutex
	// contains filtered or unexported fields
}

func LoadODCacheOrNew

func LoadODCacheOrNew(ctx context.Context, pricingClient pricing.GetProductsAPIClient, region string, fullRefreshTTL time.Duration, directoryPath string) *OnDemandPricing

func (*OnDemandPricing) Clear

func (c *OnDemandPricing) Clear() error

func (*OnDemandPricing) Count

func (c *OnDemandPricing) Count() int

Count of items in the cache

func (*OnDemandPricing) Get

func (c *OnDemandPricing) Get(ctx context.Context, instanceType ec2types.InstanceType) (float64, error)

func (*OnDemandPricing) Refresh

func (c *OnDemandPricing) Refresh(ctx context.Context) error

func (*OnDemandPricing) Save

func (c *OnDemandPricing) Save() error

func (*OnDemandPricing) SetLogger

func (c *OnDemandPricing) SetLogger(logger *log.Logger)

func (*OnDemandPricing) StringMe

func (c *OnDemandPricing) StringMe(i interface{}) *string

StringMe takes an interface and returns a pointer to a string value If the underlying interface kind is not string or *string then nil is returned

type PriceDimensionInfo

type PriceDimensionInfo struct {
	Unit         string            `json:"unit"`
	EndRange     string            `json:"endRange"`
	Description  string            `json:"description"`
	AppliesTo    []string          `json:"appliesTo"`
	RateCode     string            `json:"rateCode"`
	BeginRange   string            `json:"beginRange"`
	PricePerUnit map[string]string `json:"pricePerUnit"`
}

type PricingList

type PricingList struct {
	Product         PricingListProduct `json:"product"`
	ServiceCode     string             `json:"serviceCode"`
	Terms           ProductTerms       `json:"terms"`
	Version         string             `json:"version"`
	PublicationDate string             `json:"publicationDate"`
}

type PricingListProduct

type PricingListProduct struct {
	ProductFamily     string            `json:"productFamily"`
	ProductAttributes map[string]string `json:"attributes"`
	SKU               string            `json:"sku"`
}

type ProductPricingInfo

type ProductPricingInfo struct {
	PriceDimensions map[string]PriceDimensionInfo `json:"priceDimensions"`
	SKU             string                        `json:"sku"`
	EffectiveDate   string                        `json:"effectiveDate"`
	OfferTermCode   string                        `json:"offerTermCode"`
	TermAttributes  map[string]string             `json:"termAttributes"`
}

type ProductTerms

type ProductTerms struct {
	OnDemand map[string]ProductPricingInfo `json:"OnDemand"`
	Reserved map[string]ProductPricingInfo `json:"Reserved"`
}

type SpotPricing

type SpotPricing struct {
	Region         string
	FullRefreshTTL time.Duration
	DirectoryPath  string

	sync.RWMutex
	// contains filtered or unexported fields
}

func LoadSpotCacheOrNew

func LoadSpotCacheOrNew(ctx context.Context, ec2Client ec2.DescribeSpotPriceHistoryAPIClient, region string, fullRefreshTTL time.Duration, directoryPath string, days int) *SpotPricing

func (*SpotPricing) Clear

func (c *SpotPricing) Clear() error

func (*SpotPricing) Count

func (c *SpotPricing) Count() int

Count of items in the cache

func (*SpotPricing) Get

func (c *SpotPricing) Get(ctx context.Context, instanceType ec2types.InstanceType, zone string, days int) (float64, error)

func (*SpotPricing) Refresh

func (c *SpotPricing) Refresh(ctx context.Context, days int) error

func (*SpotPricing) Save

func (c *SpotPricing) Save() error

func (*SpotPricing) SetLogger

func (c *SpotPricing) SetLogger(logger *log.Logger)

Jump to

Keyboard shortcuts

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