Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/multi_service_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,20 @@ func fetchRecommendationsForRegion(
}
params := common.RecommendationParams{
Service: service,
Region: region,
PaymentOption: cfg.PaymentOption,
Term: termStr,
LookbackPeriod: lookback,
// Savings Plans specific filters
IncludeSPTypes: cfg.IncludeSPTypes,
ExcludeSPTypes: cfg.ExcludeSPTypes,
}
// For Savings Plans, region is only the endpoint the account-level call is
// signed in (spAPIRegion), not a filter. The provider folds params.Region
// into its include-region set, which would drop every EC2 Instance plan
// recommended outside that endpoint region.
if !common.IsSavingsPlan(service) {
params.Region = region
}

recs, err := recClient.GetRecommendations(ctx, &params)
var incomplete *recommendations.IncompleteRecommendationsError
Expand Down
24 changes: 24 additions & 0 deletions cmd/savings_plan_purchase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/LeanerCloud/cloud-commitments-go/pkg/common"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -401,3 +402,26 @@ func TestProcessCSVRegionPurchases_SavingsPlanRowFromWrittenCSV(t *testing.T) {
assert.NotContains(t, results[0].Error.Error(), "Details", "details must reach the client")
assert.Contains(t, stub.paths(), "/DescribeSavingsPlansOfferings")
}

func TestFetchRecommendationsForRegion_SavingsPlanDoesNotFilterOnEndpointRegion(t *testing.T) {
captureAppLog(t)
for _, tc := range []struct {
service common.ServiceType
wantRegion string
}{
{common.ServiceSavingsPlansEC2Instance, ""},
{common.ServiceSavingsPlansCompute, ""},
{common.ServiceRDS, spAPIRegion},
} {
client := &MockRecommendationsClient{}
var got *common.RecommendationParams
client.On("GetRecommendations", mock.Anything, mock.Anything).
Run(func(args mock.Arguments) { got = args.Get(1).(*common.RecommendationParams) }).
Return([]common.Recommendation{}, nil)

fetchRecommendationsForRegion(context.Background(), client, tc.service, spAPIRegion, Config{TermYears: 1})

require.NotNil(t, got, tc.service)
assert.Equal(t, tc.wantRegion, got.Region, tc.service)
}
}
Loading