in pkg/ec2pricing/ec2pricing.go [214:251]
func (p *EC2Pricing) HydrateSpotCache(days int) error {
newCache := make(map[string]map[string][]spotPricingEntry)
endTime := time.Now().UTC()
startTime := endTime.Add(time.Hour * time.Duration(24*-1*days))
spotPriceHistInput := ec2.DescribeSpotPriceHistoryInput{
ProductDescriptions: []*string{aws.String(productDescription)},
StartTime: &startTime,
EndTime: &endTime,
}
var processingErr error
errAPI := p.EC2Client.DescribeSpotPriceHistoryPages(&spotPriceHistInput, func(dspho *ec2.DescribeSpotPriceHistoryOutput, b bool) bool {
for _, history := range dspho.SpotPriceHistory {
spotPrice, errFloat := strconv.ParseFloat(*history.SpotPrice, 64)
if errFloat != nil {
processingErr = multierr.Append(processingErr, errFloat)
continue
}
instanceType := *history.InstanceType
zone := *history.AvailabilityZone
if _, ok := newCache[instanceType]; !ok {
newCache[instanceType] = make(map[string][]spotPricingEntry)
}
newCache[instanceType][zone] = append(newCache[instanceType][zone], spotPricingEntry{
Timestamp: *history.Timestamp,
SpotPrice: spotPrice,
})
}
return true
})
if errAPI != nil {
return errAPI
}
cTime := time.Now().UTC()
p.spotCache = newCache
p.lastSpotCacheUTC = &cTime
return processingErr
}