func()

in pkg/ec2pricing/odpricing.go [215:247]


func (c *OnDemandPricing) fetchOnDemandPricing(ctx context.Context, instanceType ec2types.InstanceType) (map[string]float64, error) {
	start := time.Now()
	calls := 0
	defer func() {
		c.logger.Printf("Took %s and %d calls to collect OD pricing", time.Since(start), calls)
	}()
	odPricing := map[string]float64{}
	productInput := pricing.GetProductsInput{
		ServiceCode: c.StringMe(serviceCode),
		Filters:     c.getProductsInputFilters(instanceType),
	}
	var processingErr error

	p := pricing.NewGetProductsPaginator(c.pricingClient, &productInput)

	for p.HasMorePages() {
		calls++
		pricingOutput, err := p.NextPage(ctx)
		if err != nil {
			return nil, fmt.Errorf("failed to get next OD pricing page, %w", err)
		}

		for _, priceDoc := range pricingOutput.PriceList {
			instanceTypeName, price, errParse := c.parseOndemandUnitPrice(priceDoc)
			if errParse != nil {
				processingErr = multierr.Append(processingErr, errParse)
				continue
			}
			odPricing[instanceTypeName] = price
		}
	}
	return odPricing, processingErr
}