fix(recs): stop double-subtracting amortized upfront in server pct#1206
Conversation
recEffectiveSavingsPct subtracted amortized upfront from rec.Savings, but all three providers (AWS, Azure, GCP) report savings as already-net monthly savings, so the server-side min_savings_pct floor filtered on an understated (for high-upfront RIs negative) percentage while the UI displayed the correct one. Recommendations whose true effective savings exceeded the floor were silently dropped from API results. Realign the backend with the frontend's displaySavingsPct / effectiveSavingsPct (issues #1103/#1104, #323): - numerator is rec.Savings directly; amortized upfront stays only in the on-demand denominator reconstruction - prefer the provider-authoritative rec.SavingsPercentage when non-nil and finite - AWS rows without an explicit on-demand baseline return (0, false) instead of a reconstructed value that diverges from Cost Explorer's true baseline Update the unit tests that entrenched the double-subtract formula and add regression tests covering the high-upfront negative-pct shape, the savings_percentage preference, and the AWS no-baseline guard; all fail against the pre-fix code. Closes #1148
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR fixes server-side effective savings percentage computation in ChangesEffective Savings Percentage Computation and Tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
PR #1206 split RecommendationFilter.MinSavings into MinSavingsUSD and MinSavingsPct but only updated the unit test file. The integration-tagged store_postgres_recommendations_test.go still referenced the removed MinSavings field, breaking golangci-lint typecheck on main.
Problem
Closes #1148 (review finding COR-01, P1).
recEffectiveSavingsPctininternal/config/store_postgres_recommendations.gocomputed the server-side effective savings percentage as(savings - amortized_upfront) / on_demand, but all three providers (AWS, Azure, GCP) reportsavingsas already-net monthly savings, with amortized upfront factored in. The frontend was fixed for this in #1103/#1104, but the backend mirror diverged: themin_savings_pctquery-param floor inListStoredRecommendationsfiltered on an understated, and for high-upfront RIs negative, percentage while the UI displayed the correct one. Recommendations whose true effective savings exceeded the floor were silently dropped from API results, penalizing all-upfront and partial-upfront RIs hardest.Fix
Realign the backend with the frontend's
displaySavingsPct/effectiveSavingsPct:rec.Savingsdirectly; amortized upfront remains only in the on-demand denominator reconstruction (monthly_cost + savings + amortized).rec.SavingsPercentagewhen non-nil and finite, mirroringdisplaySavingsPct.(0, false)instead of a reconstructed value that diverges from Cost Explorer's true baseline (the frontend's fix(frontend/recs): return null from effectiveSavingsPct on AWS reconstruction fallback (followup to #321) #323 guard). Uncomputable rows pass through the floor unchanged, as before.A local
providerAWSconstant is used becauseinternal/configmust not importpkg/common(documented dependency direction).Also fixed the unit tests in
store_postgres_savings_filter_test.gothat entrenched the double-subtract formula, and added regression tests for the high-upfront negative-pct shape, thesavings_percentagepreference, and the AWS no-baseline guard.Test evidence
go build ./...passes.go test ./internal/config/...: 585 tests pass.high-upfront RI is not driven negative (#1148 regression)where the old formula yields -25% for a 3yr all-upfront RI whose true effective savings are +25% (silently dropped by any positivemin_savings_pctfloor).go vet ./internal/config/: clean.Summary by CodeRabbit
Bug Fixes