Skip to content

fix(gcp/cloudsql): commitment price unit mismatch in getSQLPricing #1078

Description

@cristim

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.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/sHoursimpact/manyAffects most userspr-createdA PR has been opened for this issue (dedup guard for the auto-PR loop)pr-mergedThe PR for this issue has been mergedpriority/p2Backlog-worthyseverity/mediumModerate harmtriagedItem has been triagedtype/bugDefecturgency/this-quarterWithin the quarter

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions