test(coverage): assert CE lookback window width + add --rec-lookback-period flag (refs #360) - #992
Conversation
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 43 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe CLI now accepts validated reservation-recommendation lookback periods of 7, 30, or 60 days. The value flows through multi-service execution and AWS adapters into Cost Explorer requests, with tests covering request periods and coverage-window calculations. ChangesConfigurable reservation recommendation lookback
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant runToolMultiService
participant RecommendationsClientAdapter
participant recommendations.Client
participant CostExplorer
CLI->>runToolMultiService: RecLookbackPeriod
runToolMultiService->>RecommendationsClientAdapter: SetRecLookbackPeriod(period)
RecommendationsClientAdapter->>recommendations.Client: SetRecLookbackPeriod(period)
runToolMultiService->>recommendations.Client: GetRecommendationsForService
recommendations.Client->>CostExplorer: GetReservationPurchaseRecommendation with LookbackPeriodInDays
CostExplorer-->>recommendations.Client: Recommendation response
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
0fb3a1d to
7019fcf
Compare
|
Rebased on feat/multicloud-web-frontend. Resolved conflict in providers/aws/recommendations/client.go (additive merge: kept both ec2API/instanceTypePagerFactory/skuCatalog fields from base and recLookbackPeriod field from this PR; same for SetInstanceTypePagerFactory/instanceTypeLookup and SetRecLookbackPeriod methods). CR BILLING_BLOCKED; no re-trigger sent. |
7019fcf to
9d4f5ad
Compare
9d4f5ad to
d528e1f
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
…riod constant The "7d" default was hardcoded in three places after PR #992 added --rec-lookback-period (cmd flag default, cmd-side fallback in fetchRecommendationsForRegion, client-side fallback in fetchSingleComboRecs). Per feedback_no_hardcoded_magic_values.md, centralise it into recommendations.DefaultRecLookbackPeriod so the cmd flag default, the cmd-side fallback, and the client-side fallback all reference one source of truth, and a future change to the default only needs to flip one value. No behavioural change: same "7d" value, same call sites. refs #360
Adversarial review (PR #992)Reviewed against the brief's risk surfaces. The window-width test and Verified
Fix pushed (
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Tip For best results, initiate chat on the files or code changes.
This all sounds solid to me: the discriminating test coverage for both the CE window width and I also agree the remaining points are reasonable to leave out of scope for this PR:
Given your verification and the pushed constant cleanup, this looks non-blocking from my side. |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
|
@coderabbitai review |
✅ Action performedReview finished.
|
…riod constant The "7d" default was hardcoded in three places after PR #992 added --rec-lookback-period (cmd flag default, cmd-side fallback in fetchRecommendationsForRegion, client-side fallback in fetchSingleComboRecs). Per feedback_no_hardcoded_magic_values.md, centralise it into recommendations.DefaultRecLookbackPeriod so the cmd flag default, the cmd-side fallback, and the client-side fallback all reference one source of truth, and a future change to the default only needs to flip one value. No behavioural change: same "7d" value, same call sites. refs #360
aa555f5 to
7ac4490
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
…riod constant The "7d" default was hardcoded in three places after PR #992 added --rec-lookback-period (cmd flag default, cmd-side fallback in fetchRecommendationsForRegion, client-side fallback in fetchSingleComboRecs). Per feedback_no_hardcoded_magic_values.md, centralise it into recommendations.DefaultRecLookbackPeriod so the cmd flag default, the cmd-side fallback, and the client-side fallback all reference one source of truth, and a future change to the default only needs to flip one value. No behavioural change: same "7d" value, same call sites. refs #360
7ac4490 to
8c0e7fd
Compare
|
Rebased onto origin/main (132 commits behind). Two struct-comment conflicts in cmd/main.go resolved by keeping main's Config layout and adding the PR's new RecLookbackPeriod field on top; all other files auto-merged cleanly. Gates (root module + providers/aws module):
Branch force-pushed: fix/360-coverage-window-tests-and-rec-lookback @coderabbitai review |
|
✅ Action performedReview finished.
|
…period flag (refs #360) Gap 1: extend mockCoverageCE to capture the last CE TimePeriod and add TestGetRICoverageMap_LookbackWindowWidth, which parses Start/End YYYY-MM-DD strings and asserts end-start == lookbackDays. Test fails if the window math regresses to a hardcoded value. Gap 2: replace the tautological "custom lookback stored in Config" subcase in TestFetchExistingCoverage_LookbackDays (which asserted a struct field equals what was just assigned) with a comment pointing to the new discriminating test. Gap 3: implement the second flag from issue #360: --rec-lookback-period (7d/30d/60d, default 7d) controls LookbackPeriodInDays in GetReservationPurchaseRecommendation. Wired via Config.RecLookbackPeriod through fetchRecommendationsForRegion (CLI path) and Client.SetRecLookbackPeriod (discovery/UI path). Validated in validateFlags. TestSetRecLookbackPeriod_ReachesGetReservationPurchaseRecommendation asserts all three enum values reach the actual CE input. TestValidateRecLookbackPeriod guards the validation logic.
Extract fetchSingleComboRecs from GetRecommendationsForService (complexity 11->8) and runPurchaseAndReport from runToolMultiService (complexity 12->9) to satisfy the pre-commit cyclomatic-complexity hook (limit 10). Also rebase onto origin/feat/multicloud-web-frontend resolving the client_test.go conflict by keeping both tests added by each side. No behaviour change.
…ect function After extracting fetchSingleComboRecs from GetRecommendationsForService, the docstring for GetRecommendationsForService was left attached to the extracted helper rather than to the function it describes. Move the docstring back to GetRecommendationsForService and give fetchSingleComboRecs its own focused comment.
…riod constant The "7d" default was hardcoded in three places after PR #992 added --rec-lookback-period (cmd flag default, cmd-side fallback in fetchRecommendationsForRegion, client-side fallback in fetchSingleComboRecs). Per feedback_no_hardcoded_magic_values.md, centralise it into recommendations.DefaultRecLookbackPeriod so the cmd flag default, the cmd-side fallback, and the client-side fallback all reference one source of truth, and a future change to the default only needs to flip one value. No behavioural change: same "7d" value, same call sites. refs #360
8c0e7fd to
bee2aa5
Compare
|
Re-rebased onto origin/main post-#1208 merge (ed288c4). DefaultRecLookbackPeriod const is confirmed defined in providers/aws/recommendations/client.go:33 and referenced in cmd/main.go:156 and cmd/multi_service_helpers.go:428. Both modules compile and test clean. @coderabbitai review |
|
✅ Action performedReview finished.
|
|
Merged to main (rebased onto current main, CLEAN + all CI green). Adds CE lookback-window width assertions + rec-lookback coverage tests; DefaultRecLookbackPeriod constant confirmed defined. Test-only. |
…riod constant The "7d" default was hardcoded in three places after PR #992 added --rec-lookback-period (cmd flag default, cmd-side fallback in fetchRecommendationsForRegion, client-side fallback in fetchSingleComboRecs). Per feedback_no_hardcoded_magic_values.md, centralise it into recommendations.DefaultRecLookbackPeriod so the cmd flag default, the cmd-side fallback, and the client-side fallback all reference one source of truth, and a future change to the default only needs to flip one value. No behavioural change: same "7d" value, same call sites. refs #360
…s-and-rec-lookback test(coverage): assert CE lookback window width + add --rec-lookback-period flag (refs #360)
Summary
Completes the follow-up gaps left after #794 (merged), which implemented
--coverage-lookback-daysbut left test coverage gaps and the second flag from issue #360 unimplemented.mockCoverageCE.GetReservationCoveragenow captures the lastTimePeriodfrom the input.TestGetRICoverageMap_LookbackWindowWidthcallsGetRICoverageMapwith 14 and 60 days, parses the YYYY-MM-DD Start/End strings, and assertsend-start == N days. This test fails if the window math regresses to a hardcoded value (e.g. reverting to 30).TestFetchExistingCoverage_LookbackDays"custom lookback stored in Config" subcase, which only assertedcfg.CoverageLookbackDays == 60(trivially true), is replaced by a comment pointing to the new discriminating test above.--rec-lookback-period(values:7d/30d/60d, default7d) controllingLookbackPeriodInDaysinGetReservationPurchaseRecommendation. Wired throughConfig.RecLookbackPeriod->fetchRecommendationsForRegion(CLI path) andClient.SetRecLookbackPeriod(discovery/UI path). Validated invalidateFlags.TestSetRecLookbackPeriod_ReachesGetReservationPurchaseRecommendationasserts all three enum values reach the actual CE input.TestValidateRecLookbackPeriodguards the validator.References #794. refs #360 (already closed).
Test plan
go build ./...passes from root and fromproviders/aws/cd providers/aws && go test ./recommendations/- 296 tests pass (includes new window-width and rec-lookback-period tests)go test ./cmd/...- 758 tests pass (includes new validator test)GetRICoverageMapused a hardcoded 30 instead oflookbackDays, calling with 14 would producespanDays=30 != 14and the test would failSummary by CodeRabbit
New Features
--rec-lookback-periodoption, defaulting to 7 days.Bug Fixes