Repository navigation
fix(gcp/cloudsql): commitment price unit mismatch in getSQLPricing #1078
Description
Problem
getSQLPricing in providers/gcp/services/cloudsql/client.go has the same per-unit vs term-total mismatch that was fixed for Memorystore and Cloud Storage in PR #1047.
The extractSQLPricingFromSKUs / extractSQLPriceFromSKU functions return a raw per-hour SKU price, but the code passes it directly to calculateSQLSavingsPercentage(onDemandPrice, hoursInTerm, commitmentPrice) which compares it against the term total onDemandPrice * hoursInTerm. This produces a savings percentage close to 100% instead of a realistic ~30%.
Additionally, HourlyRate = commitmentPrice / hoursInTerm divides an already-per-hour price by hours, yielding a near-zero rate.
Affected block (lines ~347-356):
hoursInTerm := 8760.0 * float64(termYears)
savingsPercentage := calculateSQLSavingsPercentage(onDemandPrice, hoursInTerm, commitmentPrice)
return &SQLPricing{
HourlyRate: commitmentPrice / hoursInTerm, // wrong: per-hour / hours
CommitmentPrice: commitmentPrice, // wrong: per-hour, not term total
OnDemandPrice: onDemandPrice * hoursInTerm, // correct: term total
...
}Fix
Mirror the fix applied to Memorystore and Cloud Storage in PR #1047:
commitmentPriceTerm := commitmentPrice * hoursInTerm
savingsPercentage := calculateSQLSavingsPercentage(onDemandPrice, hoursInTerm, commitmentPriceTerm)
return &SQLPricing{
HourlyRate: commitmentPrice, // per-hour rate
CommitmentPrice: commitmentPriceTerm, // term total
OnDemandPrice: onDemandPrice * hoursInTerm,
...
}Include a regression test that fails pre-fix (SavingsPercentage is ~99.99%) and passes after.
Context
Identified during PR #1047 CR review. The Memorystore and Cloud Storage variants were fixed in #1047. CloudSQL was not flagged by CR but has the identical issue.
Activity
fix(gcp): address CR post-commit findings on payment option, term, an…
fix(gcp/cloudsql): correct savings unit, term propagation (closes #1078)
fix(gcp): wire Count/pricing into GCP converters; refuse fabricated p…