Repository navigation
fix(azure): drop Advisor recommendations with absent or unparsable savings - #217
Conversation
…vings extFloat returned 0 for a missing annualSavingsAmount key, a nil value and a ParseFloat failure alike, so a recommendation whose savings Azure did not report (or reported as "1,234.00") shipped with EstimatedSavings = 0 and was ranked as worthless with no log. extFloat now returns an error for both cases. convertAdvisorRecommendation logs a warning and drops the recommendation instead, while an explicit "0" is still kept as a real zero saving. Refs #62
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour. 📝 WalkthroughWalkthroughAzure Advisor recommendation conversion now rejects recommendations with missing or invalid annual savings data. Tests cover valid savings amounts, including zero, and missing or invalid values. ChangesAzure recommendation conversion
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The change distinguishes absent or unparsable savings from explicit zero savings. No new merge-blocking risk is established; merge after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai full review |
|
What
extFloatinproviders/azure/recommendations.gonow returns(float64, error). A missingannualSavingsAmountkey, a nil value, a nilExtendedPropertiesmap, an empty string, a non-numeric value (for example"1,234.00"), a non-finite value (NaN,Inf,-Inf) and a negative value are errors.convertAdvisorRecommendationlogs a warning and drops that Advisor recommendation. An explicit"0"is still kept withEstimatedSavings = 0.Why
Before this change a missing key, nil value, nil map, empty string or unparsable value shipped a recommendation with a fabricated
EstimatedSavings = 0. It was ranked below everything else and hidden by any savings threshold, and nothing was logged. NaN, Inf and negative inputs shipped as themselves rather than as 0, which is equally wrong for a savings figure. This is the first acceptance item of #62.Behavior change: an Advisor recommendation with no
ExtendedPropertiesat all was previously kept with zero savings. It is now dropped with a warning, because its savings are absent.Not in this PR (remaining for #62)
pkg/configDryRun/AutoApprove: already fixed by fix(config): keep the dry-run default when YAML omits dry_run #202.providers/azure/internal/recommendations/converter.goamountValuevsamountValuePtr: reviewed, left unchanged.amountValuefeedsOnDemandCost,CommitmentCostandEstimatedSavings, which are valuefloat64fields onExtractedFieldsandcommon.Recommendation. The Legacy path collapses absent to 0 for those same fields. Fixing it means making those shared fields pointers, which is a cross-module API change for its own PR.RecurringMonthlyCostalready usesamountValuePtrcorrectly.pkg/scorer/scorer.go> 0threshold guards: changingscorer.Configto distinguish configured 0 from unset is a breaking API change acrosspkg/configandpkg/reporter, so it goes in a separate PR.How verified
TestConvertAdvisorRecommendation_ZeroVersusAbsentSavingsfeeds a real"0", a populated value, and ten absent, unparsable, non-finite or negative subtests (key absent, nil value, nil map, thousands separator, empty string, NaN, nan, Inf, -Inf, negative) throughconvertAdvisorRecommendation.recommendations.go(from2c38426^) all ten subtests fail (for exampleExpected nil, but got: &common.Recommendation{... EstimatedSavings:0 ...}). With the fix all pass.providers/azure:go vet ./...,go test ./...andgolangci-lint run(repo config) pass, withGOWORK=off GOTOOLCHAIN=go1.26.6.Refs #62
Summary by CodeRabbit