kubecost / kubectl-cost

CLI for determining the cost of Kubernetes workloads
Apache License 2.0
913 stars 60 forks source link

Stop using /aggregatedCostModel #90

Closed michaelmdresser closed 3 years ago

michaelmdresser commented 3 years ago

Kubectl cost uses the Aggregated cost model API for monthly rate queries, i.e. non --historical queries. That API is old and we want to switch everything to use the Allocation API which kubectl cost already uses for --historical queries.

We should be able to cut out /aggregatedCostModel queries by hitting /allocation and then transforming the cost numbers to a monthly rate based on the coverage of the resulting data. Special care will have to be taken due to the time-based quirks of the Allocation API. Instead of doing something like cost * (month / query window) we should do cost * (month / duration of resulting data coverage).

nikovacevic commented 3 years ago

Each allocation comes with a mintues field, so it should be possible to scale to monthly rate based on active time or window time. (There are still caveats, like CronJob-based allocations, allocated by controller and accumulated over a long window, where the mintues field will count as the time between the start of the first run and the end of the last run.)

michaelmdresser commented 3 years ago

Resolved by #93