feat(cli): end-of-run summary of dropped recommendations (closes #361)#875
feat(cli): end-of-run summary of dropped recommendations (closes #361)#875cristim wants to merge 3 commits into
Conversation
Track and surface recommendations that were dropped during sizing, filtering, or family-NU partitioning so users see why an instance type didn't make it into the final plan instead of silently missing. DropSummary collects per-stage counts with optional reasons; printed at end-of-run when any drop occurred. applyFilters, applySizing, and ApplyFamilyNUSizingRDS now thread a *common.DropSummary through their signatures (nil-safe). Tests cover collection, formatting, and the no-drops/nil-summary fast paths.
|
Warning Review limit reached
More reviews will be available in 15 minutes and 6 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR adds infrastructure to track and report why recommendations are dropped during recommendation processing. A new ChangesDrop Tracking Feature
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
providers/aws/recommendations/family_nu.go (1)
256-260: 💤 Low valueConsider the semantic fit of
currentNU <= 0→AlreadyAtTarget.When
currentNU <= 0, it means the family's recommendations sum to zero NU (typically because instance types aren't in the NU map). Labeling this as "AlreadyAtTarget" is semantically imprecise—it's more "no scalable NU signal" than "target already met."However, if the drop-summary constants in layer 1 don't provide a distinct category (e.g.,
DropFamilyNoNUSignal), then grouping withAlreadyAtTargetmay be acceptable as "cannot scale to contribute toward target."Verify that this grouping aligns with the user-facing summary labels.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@providers/aws/recommendations/family_nu.go` around lines 256 - 260, The check currentNU <= 0 is being classified as drops.AlreadyAtTarget which is semantically misleading; change the drop categorization so the case where the family's recommendations sum to zero NU is recorded as a more accurate category (e.g., DropFamilyNoNUSignal) or, if that constant doesn't exist, add it and use it instead of AlreadyAtTarget; update any user-facing summary labels/enum in the layer-1 drop constants (and adjust any callers that consume drops.AlreadyAtTarget or the new DropFamilyNoNUSignal) to ensure the UI/summary reflects "no scalable NU signal" rather than "already at target" while keeping the early-return behavior (return nil, drops) and preserving indices counting.providers/aws/recommendations/family_nu_test.go (1)
127-363: ⚡ Quick winAdd test coverage for
FamilyDropCounts.All call sites now unpack three return values but discard the third (
drops) with_. The new drop-tracking feature is untested at this layer. Consider adding assertions to verify:
- Line 237 test case ("family at-or-above target"):
assert.Equal(t, 1, drops.AlreadyAtTarget)- A new test case where scaling produces
floor(0)for a rec:assert.Equal(t, 1, drops.SizedToZero)- Other test cases:
assert.Equal(t, 0, drops.AlreadyAtTarget + drops.SizedToZero)(no drops)This would catch regressions in drop accounting before it reaches the end-of-run summary layer.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@providers/aws/recommendations/family_nu_test.go` around lines 127 - 363, The test suite exercises ApplyFamilyNUSizingRDS but never asserts the new FamilyDropCounts return (the third return value, commonly named drops); update the existing tests that call ApplyFamilyNUSizingRDS to capture the third return and assert its fields: in the "family at-or-above target" case capture drops and assert drops.AlreadyAtTarget == 1; add a new test case where scaling results in floor(0) for a rec and assert drops.SizedToZero == 1; for the remaining positive/unchanged cases (e.g., "no coverage signal", "AWS rec under-recommends", "AWS rec over-recommends", "RecurringMonthlyCost scales", "non-RDS recs flow through", "ProjectedCoverage", "multiple sizes") capture drops and assert drops.AlreadyAtTarget + drops.SizedToZero == 0 so drop accounting is exercised consistently when calling ApplyFamilyNUSizingRDS.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/common/drop_summary.go`:
- Around line 35-40: DropSummary.Add can panic when called on a zero-value
receiver because d.counts may be nil; modify DropSummary.Add (pointer receiver
Add) to lazily initialize d.counts (e.g., if d.counts == nil { d.counts =
make(map[string]int) }) before performing d.counts[reason] += n, keeping the
existing nil receiver and zero n guards.
---
Nitpick comments:
In `@providers/aws/recommendations/family_nu_test.go`:
- Around line 127-363: The test suite exercises ApplyFamilyNUSizingRDS but never
asserts the new FamilyDropCounts return (the third return value, commonly named
drops); update the existing tests that call ApplyFamilyNUSizingRDS to capture
the third return and assert its fields: in the "family at-or-above target" case
capture drops and assert drops.AlreadyAtTarget == 1; add a new test case where
scaling results in floor(0) for a rec and assert drops.SizedToZero == 1; for the
remaining positive/unchanged cases (e.g., "no coverage signal", "AWS rec
under-recommends", "AWS rec over-recommends", "RecurringMonthlyCost scales",
"non-RDS recs flow through", "ProjectedCoverage", "multiple sizes") capture
drops and assert drops.AlreadyAtTarget + drops.SizedToZero == 0 so drop
accounting is exercised consistently when calling ApplyFamilyNUSizingRDS.
In `@providers/aws/recommendations/family_nu.go`:
- Around line 256-260: The check currentNU <= 0 is being classified as
drops.AlreadyAtTarget which is semantically misleading; change the drop
categorization so the case where the family's recommendations sum to zero NU is
recorded as a more accurate category (e.g., DropFamilyNoNUSignal) or, if that
constant doesn't exist, add it and use it instead of AlreadyAtTarget; update any
user-facing summary labels/enum in the layer-1 drop constants (and adjust any
callers that consume drops.AlreadyAtTarget or the new DropFamilyNoNUSignal) to
ensure the UI/summary reflects "no scalable NU signal" rather than "already at
target" while keeping the early-return behavior (return nil, drops) and
preserving indices counting.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0729b911-0b90-4841-9fbe-363017c50c32
📒 Files selected for processing (11)
cmd/helpers.gocmd/helpers_test.gocmd/multi_service.gocmd/multi_service_filters.gocmd/multi_service_filters_test.gocmd/multi_service_helpers.gocmd/multi_service_test.gopkg/common/drop_summary.gopkg/common/drop_summary_test.goproviders/aws/recommendations/family_nu.goproviders/aws/recommendations/family_nu_test.go
… on zero-value Calling Add on a zero-value DropSummary (var d DropSummary) would panic with "assignment to entry in nil map" because the counts map is only populated by NewDropSummary. Lazily initialise the map on first Add so both construction patterns are safe. Adds a regression test that exercises a zero-value DropSummary directly. Addresses CodeRabbit review on PR #875.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
…test coverage (#875 CR) - DropSummary.Add already had the lazy-init nil-map guard; add TestDropSummary_ZeroValue_Safe regression test to lock the behaviour - Add DropFamilyNoNUSignal ("family-nu-no-nu-signal") constant and FamilyDropCounts.NoNUSignal field for the case where AWS-rec NU sums to zero (unknown/unrecognised sizes) -- distinct from AlreadyAtTarget - Fix sizeRDSFamilyRecs: currentNU<=0 branch now sets NoNUSignal instead of incorrectly reusing AlreadyAtTarget - Propagate NoNUSignal in ApplyFamilyNUSizingRDS aggregation loop and in cmd/multi_service_helpers.go drops recording - Capture drops in all TestApplyFamilyNUSizingRDS subtests; assert AlreadyAtTarget==1 for the "at target" case, SizedToZero==1 for a new "floor(0)" test case, and zero total drops for passing-through cases
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Closes #361. Tracks recommendations dropped during sizing, filtering, and family-NU partitioning, then prints a per-stage end-of-run summary so users can see why an instance type didn't make the final plan instead of silently missing.
pkg/common/drop_summary.go+ tests —DropSummarycollects per-stage counts with optional reasons, formats a multi-line summary at end-of-run.applyFilters,applySizing, andApplyFamilyNUSizingRDSnow thread a*common.DropSummary(nil-safe — production callers can passnilto opt out).nil; existing assertions unchanged. Family-NU partition signature gained a 3rd return (dropped count) — both test cases adjusted.Test plan
go test github.com/LeanerCloud/CUDly/cmd/... github.com/LeanerCloud/CUDly/providers/aws/recommendations/... github.com/LeanerCloud/CUDly/pkg/common/...-> 1201 pass across 9 packagesSummary by CodeRabbit
Release Notes
New Features