Documentation
¶
Index ¶
- Constants
- Variables
- type EC2Pricing
- func (p *EC2Pricing) GetOnDemandInstanceTypeCost(ctx context.Context, instanceType ec2types.InstanceType) (float64, error)
- func (p *EC2Pricing) GetSpotInstanceTypeNDayAvgCost(ctx context.Context, instanceType ec2types.InstanceType, ...) (float64, error)
- func (p *EC2Pricing) OnDemandCacheCount() int
- func (p *EC2Pricing) RefreshOnDemandCache(ctx context.Context) error
- func (p *EC2Pricing) RefreshSpotCache(ctx context.Context, days int) error
- func (p *EC2Pricing) Save() error
- func (p *EC2Pricing) SetLogger(logger *log.Logger)
- func (p *EC2Pricing) SpotCacheCount() int
- type EC2PricingIface
- type OnDemandPricing
- func (c *OnDemandPricing) Clear() error
- func (c *OnDemandPricing) Count() int
- func (c *OnDemandPricing) Get(ctx context.Context, instanceType ec2types.InstanceType) (float64, error)
- func (c *OnDemandPricing) Refresh(ctx context.Context) error
- func (c *OnDemandPricing) Save() error
- func (c *OnDemandPricing) SetLogger(logger *log.Logger)
- func (c *OnDemandPricing) StringMe(i interface{}) *string
- type PriceDimensionInfo
- type PricingList
- type PricingListProduct
- type ProductPricingInfo
- type ProductTerms
- type SpotPricing
- func (c *SpotPricing) Clear() error
- func (c *SpotPricing) Count() int
- func (c *SpotPricing) Get(ctx context.Context, instanceType ec2types.InstanceType, zone string, days int) (float64, error)
- func (c *SpotPricing) Refresh(ctx context.Context, days int) error
- func (c *SpotPricing) Save() error
- func (c *SpotPricing) SetLogger(logger *log.Logger)
Constants ¶
const (
ODCacheFileName = "on-demand-pricing-cache.json"
)
const (
SpotCacheFileName = "spot-pricing-cache.gob"
)
Variables ¶
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 NewWithCache ¶
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, error)
func (*OnDemandPricing) Clear ¶
func (c *OnDemandPricing) Clear() error
func (*OnDemandPricing) Get ¶
func (c *OnDemandPricing) Get(ctx context.Context, instanceType ec2types.InstanceType) (float64, 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 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 ProductPricingInfo ¶
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 (*SpotPricing) Clear ¶
func (c *SpotPricing) Clear() error
func (*SpotPricing) Get ¶
func (c *SpotPricing) Get(ctx context.Context, instanceType ec2types.InstanceType, zone string, days int) (float64, error)
func (*SpotPricing) Save ¶
func (c *SpotPricing) Save() error
func (*SpotPricing) SetLogger ¶
func (c *SpotPricing) SetLogger(logger *log.Logger)