Documentation
¶
Overview ¶
Package controller contains main business logic of the cost service.
Index ¶
- func BurnoutRateLinearPenalty(costPerHour float64, annualBurnoutRate float64, amortizationTimeYears float64) (float64, error)
- func CalculateCostForOsResource(ctx context.Context, ic ufsAPI.FleetClient, ...) (*fleetcostpb.CostResult, error)
- func PersistToBigquery(ctx context.Context, projectName string, bqClient bqwrapper.BQIf, ...) error
- func ReadValidCachedCostResult(ctx context.Context, hostname string) (*entities.CachedCostResultEntity, error)
- func StoreCachedCostResult(ctx context.Context, hostname string, result *models.CostResult) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BurnoutRateLinearPenalty ¶
func BurnoutRateLinearPenalty(costPerHour float64, annualBurnoutRate float64, amortizationTimeYears float64) (float64, error)
BurnoutRateLinearPenalty divides the annual burnout rate by the number of hours in a year and uses that to compute additional cost.
This is the simplest burnout model that can possibly work. Other alternatives include an exponential model.
TODO(gregorynisbet): investigate exponential models for burnout rate. TODO(gregorynisbet): extend the RPC interface to make the burnout penalty its own line item.
Basically, we assume that if the burnout rate is 0.2, then that 0.2 will be spread out evenly per every hour of the year. This is not a realistic assumption, but it is an understandable one.
Next we assume that *if* the device burns out, then we are metaphorically hit with the cost of acquiring it again. We get the cost of acquiring the device again by multiplying the hourly cost by the amortization period. This isn't ideal.
TODO(gregorynisbet): Look into giving EVERY cost indicator a separate reacquisition cost (for dealing with burnout)
func CalculateCostForOsResource ¶
func CalculateCostForOsResource(ctx context.Context, ic ufsAPI.FleetClient, deviceDataRes *ufsAPI.GetDeviceDataResponse, req *fleetcostAPI.GetCostResultRequest) (*fleetcostpb.CostResult, error)
CalculateCostForOsResource calculates the cost for an OS resource.
So far, only ChromeOS devices are supported.
ic -- The fleet client. Allowed to be nil precisely when UFS is not used. deviceDataRes -- The device data for the DUT in question. Allowed to be nil precisely when UFS is not used. req -- The underlying GetCostResultRequest associated with the GetCostResult RPC as a whole.
TODO(b/366067524): Refactor to not use a request object. TODO(b/366033984): Refactor to not pass the FleetClient in as deeply and instead calculate just the information that we need earlier.
func PersistToBigquery ¶
func PersistToBigquery(ctx context.Context, projectName string, bqClient bqwrapper.BQIf, readonly bool) error
PersistToBigquery persists everything to BigQuery.
func ReadValidCachedCostResult ¶
func ReadValidCachedCostResult(ctx context.Context, hostname string) (*entities.CachedCostResultEntity, error)
ReadValidCachedCostResult reads a cached cost result if it's before the deadline.
func StoreCachedCostResult ¶
StoreCachedCostResult stores a cached cost result.
Types ¶
This section is empty.