func calculateMonthlyPrice()

in cost-optimization/gke-shift-left-cost/api/resource_price.go [132:153]


func calculateMonthlyPrice(pi *billingpb.PricingInfo) (float32, error) {
	pe := pi.GetPricingExpression()
	pu := pe.GetTieredRates()[0].GetUnitPrice()

	unit := pe.GetUsageUnit()
	switch unit {
	case "h":
		// 1 vcpu core per hour rate
		hourlyPrice := float32(pu.GetUnits()) + float32(pu.GetNanos())/1000000000.0
		return hourlyPrice * float32(24) * float32(31), nil
	case "GiBy.h":
		// 1 Byte per hour pricing
		hourlyPrice := (float32(pu.GetUnits()) + float32(pu.GetNanos())/1000000000.0) / (1024 * 1024 * 1024)
		return hourlyPrice * float32(24) * float32(31), nil
	case "GiBy.mo":
		// 1 Byte per month pricing
		monthlyPrice := (float32(pu.GetUnits()) + float32(pu.GetNanos())/1000000000.0) / (1024 * 1024 * 1024)
		return monthlyPrice, nil
	default:
		return 0, fmt.Errorf("Price UsageUnit Not implemented: %s", unit)
	}
}