Skip to content

Commit

Permalink
AN-224 Fix vmCostPerHour being 10x what it should be (#7576)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgainerdewar authored Oct 28, 2024
1 parent c4093a0 commit 32685d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ object GcpCostCatalogService {
// In practice, from what I've seen, CPU cores and RAM don't have more than a single tier.
val costPerUnit: Money = pricingInfo.getPricingExpression.getTieredRates(0).getUnitPrice
val costPerCorePerHour: BigDecimal =
costPerUnit.getUnits + (costPerUnit.getNanos * 10e-9) // Same as above, but as a big decimal
costPerUnit.getUnits + (costPerUnit.getNanos * 10e-10) // Same as above, but as a big decimal
val result = costPerCorePerHour * coreCount
result.validNel
} else {
Expand All @@ -109,7 +109,7 @@ object GcpCostCatalogService {
if (usageUnit == "GiBy.h") {
val costPerUnit: Money = pricingInfo.getPricingExpression.getTieredRates(0).getUnitPrice
val costPerGbHour: BigDecimal =
costPerUnit.getUnits + (costPerUnit.getNanos * 10e-9) // Same as above, but as a big decimal
costPerUnit.getUnits + (costPerUnit.getNanos * 10e-10) // Same as above, but as a big decimal
val result = costPerGbHour * ramGbCount
result.validNel
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,18 @@ class GcpCostCatalogServiceSpec
// Create BigDecimals from strings to avoid inequality due to floating point shenanigans
val lookupRows = Table(
("instantiatedVmInfo", "costPerHour"),
(InstantiatedVmInfo("us-central1", "custom-4-4096", true), BigDecimal(".361")),
(InstantiatedVmInfo("us-central1", "n2-custom-4-4096", true), BigDecimal(".42544000000000004")),
(InstantiatedVmInfo("us-central1", "n2d-custom-4-4096", true), BigDecimal(".2371600000000000024")),
(InstantiatedVmInfo("us-central1", "custom-4-4096", false), BigDecimal("1.43392")),
(InstantiatedVmInfo("us-central1", "n2-custom-4-4096", false), BigDecimal("1.50561600000000012")),
(InstantiatedVmInfo("us-central1", "n2d-custom-4-4096", false), BigDecimal("1.309896")),
(InstantiatedVmInfo("europe-west9", "custom-4-4096", true), BigDecimal(".3501808")),
(InstantiatedVmInfo("europe-west9", "n2-custom-4-4096", true), BigDecimal("0.49532")),
(InstantiatedVmInfo("europe-west9", "n2d-custom-4-4096", true), BigDecimal("0.30608")),
(InstantiatedVmInfo("europe-west9", "custom-4-4096", false), BigDecimal("1.663347200000000016")),
(InstantiatedVmInfo("europe-west9", "n2-custom-4-4352", false), BigDecimal("1.75941630500000012")),
(InstantiatedVmInfo("europe-west9", "n2d-custom-4-4096", false), BigDecimal("1.51947952"))
(InstantiatedVmInfo("us-central1", "custom-4-4096", true), BigDecimal(".0361")),
(InstantiatedVmInfo("us-central1", "n2-custom-4-4096", true), BigDecimal(".04254400000000000480")),
(InstantiatedVmInfo("us-central1", "n2d-custom-4-4096", true), BigDecimal(".02371600000000000040")),
(InstantiatedVmInfo("us-central1", "custom-4-4096", false), BigDecimal(".143392")),
(InstantiatedVmInfo("us-central1", "n2-custom-4-4096", false), BigDecimal(".150561600")),
(InstantiatedVmInfo("us-central1", "n2d-custom-4-4096", false), BigDecimal(".130989600000000012")),
(InstantiatedVmInfo("europe-west9", "custom-4-4096", true), BigDecimal(".035018080000000004")),
(InstantiatedVmInfo("europe-west9", "n2-custom-4-4096", true), BigDecimal("0.049532000000000004")),
(InstantiatedVmInfo("europe-west9", "n2d-custom-4-4096", true), BigDecimal("0.030608000000000004")),
(InstantiatedVmInfo("europe-west9", "custom-4-4096", false), BigDecimal(".1663347200000000040")),
(InstantiatedVmInfo("europe-west9", "n2-custom-4-4352", false), BigDecimal(".17594163050")),
(InstantiatedVmInfo("europe-west9", "n2d-custom-4-4096", false), BigDecimal(".151947952"))
)

forAll(lookupRows) { case (instantiatedVmInfo: InstantiatedVmInfo, expectedCostPerHour: BigDecimal) =>
Expand Down

0 comments on commit 32685d1

Please sign in to comment.