Skip to content

fix(sp): stop filtering Savings Plan recommendations on the endpoint region - #2182

Merged
cristim merged 1 commit into
mainfrom
fix/2176-sp-region-filter
Oct 13, 2026
Merged

cristim merged 1 commit into
mainfrom
fix/2176-sp-region-filter

Conversation

@cristim

@cristim cristim commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Closes #2176

Root cause

fetchRecommendationsForRegion (cmd/multi_service_helpers.go) set params.Region = region. For Savings Plans the only "region" is spAPIRegion (us-east-1), the endpoint the account-level call is signed in. The provider adapter (applyRecommendationFilters, go providers/aws/service_client.go) folds params.Region into its include-region set, and EC2 Instance SP recs are region-scoped (EffectiveRegion = Details.Region), so everything outside us-east-1 was dropped. Cost Explorer's SP recommendation call is not region-scoped. The fix leaves Region unset for Savings Plans; explicit --include-regions/--exclude-regions still apply through the existing filters.

Evidence

Regression test TestFetchRecommendationsForRegion_SavingsPlanDoesNotFilterOnEndpointRegion (cmd/savings_plan_purchase_test.go).

  • Before the fix (source change stashed): FAIL, expected: "" actual: "us-east-1".
  • After: PASS. Full go test ./... passes; go vet clean. (make lint could not run locally: golangci-lint is built with an older Go than go.mod requires; CI is authoritative.)

Real data, dry run only, no --regions, account via management account, --services savingsplans --include-sp-types EC2Instance --term 1 --payment no-upfront --rec-lookback-period 30d --coverage 100:

  • origin/main build: [1/1] Region: us-east-1 / "No recommendations found" for all four types.
  • this branch: Found 3 recommendations, savings $342.39/mo (eu-west-2 m5 $226.84, eu-central-2 m5 $77.77, eu-west-2 m5a $37.77), matching aws ce get-savings-plans-purchase-recommendation for the same parameters.

No library change needed. No purchase flags were used.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Corrected region handling for Savings Plan recommendations. EC2 Instance and Compute recommendation requests no longer include a region filter, while RDS requests continue to use the configured API region. This allows the recommendation endpoint and the provider-applied region filter to operate independently where applicable.

…region

fetchRecommendationsForRegion passed the SP API endpoint region (us-east-1)
as RecommendationParams.Region. The provider folds that into its
include-region set, so every EC2 Instance Savings Plan recommended in
another region was dropped. Region is no longer set for Savings Plans.

Closes #2176

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cristim cristim added triaged Item has been triaged priority/p1 Next up; this sprint severity/high Significant harm urgency/this-sprint Within the current sprint impact/many Affects most users effort/xs Trivial / one-liner type/bug Defect labels Oct 13, 2026
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-cli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: d8a283ee-3706-4c10-9739-9053c55c453f
📥 Commits

Reviewing files that changed from the base of the PR and between 00d82c3 and 323d81e.

📒 Files selected for processing (2)
  • cmd/multi_service_helpers.go
  • cmd/savings_plan_purchase_test.go

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 1 review per hour.

📝 Walkthrough

Savings Plans recommendation requests no longer use the API endpoint region as a recommendation filter. A test verifies that Savings Plans requests omit the region parameter and RDS requests retain it.

Changes: Savings Plans recommendation region handling

Layer / File(s) Summary
Set and verify the recommendation region parameter
cmd/multi_service_helpers.go, cmd/savings_plan_purchase_test.go
The fetcher sets params.Region only for non-Savings-Plan services. The test checks that EC2 Instance and Compute requests use an empty region, while RDS uses spAPIRegion.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 323d8

Savings Plans recommendations should no longer be limited by the API endpoint region. No issue identified here prevents merging after normal checks.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing Savings Plan recommendations from being filtered by the endpoint region.
Linked Issues check Passed Issue #2176 requires Savings Plan requests to avoid using the Cost Explorer endpoint region as a recommendation filter. fetchRecommendationsForRegion now leaves RecommendationParams.Region empty f…
Out of Scope Changes check Passed The changes are limited to the Savings Plan region-parameter fix and its regression test. The test also confirms that non-Savings Plan behavior remains unchanged. No unrelated source, library, purchas…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@cristim

cristim commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

Gate verdict: APPROVE at 323d81e

Independent gate review (Opus), base main 00d82c3 (head is up to date, CLEAN, all CI green, CodeRabbit: no actionable comments).

Root cause confirmed against the pinned module (providers/aws@v0.0.0-20261005004231-945a4045d11f): applyRecommendationFilters (service_client.go:100) appends params.Region to the include set (service_client.go:105-108); filterByIncludedRegions (:256-266) matches EC2 Instance SP recs on EffectiveRegion = Details.Region (:156-164). With params.Region = spAPIRegion every EC2 Instance SP outside us-east-1 was dropped. The recommendations client itself never reads params.Region for SP (collection_sp.go:15-53 builds the CE input without it), so leaving it unset changes nothing else.

Call-site reproduction (gate-only test, not committed): real RecommendationsClientAdapter (NewRecommendationsClientDirect) behind a local-only transport serving a CE GetSavingsPlansPurchaseRecommendation fixture (EC2 Instance SP in us-east-1, eu-west-2, eu-central-1, us-west-2 across 2 accounts, plus a Compute SP), then fetchRecommendationsForRegion(..., spAPIRegion, cfg) + the CLI's applyFilters:

  • main: no flags -> [compute, ec2instance@us-east-1]; --include-regions eu-west-2,us-west-2 -> [compute] only; --exclude-regions eu-west-2,us-east-1 -> [compute] only. FAIL.
  • head: no flags -> all 4 EC2 Instance regions + compute; include -> [compute, eu-west-2, us-west-2]; exclude -> [compute, eu-central-1, us-west-2]. PASS.

Regression surface checked

  • Callers of fetchRecommendationsForRegion: multi_service_helpers.go:450 and :782; both then filter with currentRegion, which already exempts SP (multi_service_filters.go:59). Non-SP services still get params.Region (PR test asserts ServiceRDS -> us-east-1; mutating the fix to drop Region for all services fails it).
  • --include-regions/--exclude-regions for SP are enforced CLI-side via shouldIncludeRecommendationRegion (EffectiveRegion/IsRegionAgnostic); account filters are CLI-side (shouldIncludeAccount) and params.AccountFilter is not set on this path, so unchanged.
  • Purchase region: SP clients are always built in spAPIRegion (clientRegionFor, savings_plan_purchase.go:63-69) and the offering is picked by Details.Region (go savingsplans/client.go:339-367, :489-493 strict family+region lookup); validateSavingsPlanPreconditions rejects an EC2 Instance SP without Details.Region. SP is still queried once (determineRegionsForService:266-268), so no duplicate purchases. No purchase-region regression.

Tests / mutations

  • PR test on main: FAIL (expected "" actual "us-east-1" for both SP types); on head PASS.
  • Mutant "set Region for SP again": PR test + all 3 gate tests FAIL. Mutant "ignore include/exclude for SP": gate include/exclude tests + existing TestApplyFilters_SavingsPlansRegionFilters FAIL. Mutant "drop Region for every service": PR test FAILs.
  • git archive of the exact head, GOTOOLCHAIN=go1.26.9: go test ./... -count=1 ok, go vet ./... clean, golangci-lint v2.11.4 (built with go1.26.9) 0 issues, git-secrets --register-aws on the changed files clean with BSD and GNU grep. Size 31+/1-, labels mirror fix(sp): region auto-discovery run returns no EC2 Instance Savings Plan recommendations #2176.

Non-blocking follow-up (OWNER decision): --regions never narrows Savings Plans (SP is queried once in spAPIRegion; only --include-regions filters on Details.Region, despite the comment at multi_service_helpers.go:262-264). Before this PR --regions eu-west-2 surfaced us-east-1 EC2 Instance SPs only; now it surfaces all regions. Not a regression in kind, but worth deciding whether --regions should imply an include filter for EC2 Instance SPs.

Local evidence is fixture-based (local HTTP stub), not a live AWS call; the author's dry-run against a real account is in the PR body.

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

Labels

effort/xs Trivial / one-liner impact/many Affects most users priority/p1 Next up; this sprint severity/high Significant harm triaged Item has been triaged type/bug Defect urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sp): region auto-discovery run returns no EC2 Instance Savings Plan recommendations

1 participant