Repository navigation
fix(cli): close the remaining #1613 findings #2280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
48ce128
fix(azure): make Enter skip the create-service-principal prompt
cristim 49ae590
fix(rds): cap and cancel DescribeDBInstances paging per region
cristim 4f649ab
fix(configure): select the exact-named secret, not the first prefix m…
cristim 0352e94
docs(azure): drop --client-secret from the configure-azure help example
cristim 75f5254
feat(azure): deprecate the configure-azure --client-secret flag
cristim f7d5ac0
fix(filters): exempt Savings Plans from --max-instances and --min-count
cristim 8f5b463
fix(filters): keep input order in applyMinCountFloor
cristim 4956e8e
refactor(filters): return only instance rows from the Savings Plan split
cristim d7f9502
build(deps): bump cloud-commitments-go to the scorer Savings Plan exe…
cristim ff86a2a
fix(filters): keep Savings Plans after the instance budget is spent
cristim 6e87c42
test(filters): assert exact output order for interleaved Savings Plans
cristim cfaa43b
docs(safety): note that --max-instances does not cap Savings Plans
cristim ae7f62b
test(rds): assert the expiry log line is absent when the deduction is 0
cristim fa1feaf
docs: describe the GCP provider bump and drop the stale recommender note
cristim 16472b9
Merge branch 'main' into fix/1613-small-findings
cristim 1175bd2
fix(cap): ignore Savings Plans in requireRankingSignal
cristim 76a456b
fix(secrets): paginate ListSecrets in AWSSecretsStore
cristim 161295d
fix(secrets): fail configure when the secret listing fails
cristim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/LeanerCloud/cloud-commitments-go/pkg/common" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func mkRI(resourceType string, count int) common.Recommendation { | ||
| return common.Recommendation{ | ||
| Service: common.ServiceRDS, Region: "eu-west-1", ResourceType: resourceType, | ||
| Count: count, CommitmentType: common.CommitmentReservedInstance, EstimatedSavings: 100, | ||
| } | ||
| } | ||
|
|
||
| func mkSP() common.Recommendation { | ||
| return common.Recommendation{ | ||
| Service: common.ServiceCompute, Region: "eu-west-1", ResourceType: "Compute", | ||
| Count: 1, CommitmentType: common.CommitmentSavingsPlan, EstimatedSavings: 100, | ||
| } | ||
| } | ||
|
|
||
| func TestApplyInstanceLimit_SavingsPlanExempt(t *testing.T) { | ||
| got := ApplyInstanceLimit([]common.Recommendation{mkRI("db.r5.large", 3), mkSP(), mkRI("db.r5.xlarge", 2)}, 1) | ||
|
|
||
| require.Len(t, got, 2) | ||
| assert.Equal(t, 1, got[0].Count) | ||
| assert.Equal(t, common.CommitmentSavingsPlan, got[1].CommitmentType) | ||
| assert.Equal(t, 1, got[1].Count) | ||
| } | ||
|
|
||
| func TestApplyGlobalInstanceLimit_SavingsPlanExempt(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| cfg Config | ||
| recs []common.Recommendation | ||
| wantRIs []int | ||
| wantSP bool | ||
| wantSize int | ||
| }{ | ||
| {"cap binds on RIs only", Config{MaxInstances: 1}, []common.Recommendation{mkRI("a", 3), mkSP(), mkRI("b", 2)}, []int{1}, true, 2}, | ||
| {"SP alone does not bind the cap", Config{MaxInstances: 1}, []common.Recommendation{mkRI("a", 1), mkSP()}, []int{1}, true, 2}, | ||
| {"SP survives cap with min-count above 1", Config{MaxInstances: 1, MinCount: 2}, []common.Recommendation{mkRI("a", 3), mkSP()}, nil, true, 1}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := applyGlobalInstanceLimit(tt.recs, tt.cfg, rankBySavingsPercentage, nil) | ||
|
|
||
| var ris []int | ||
| sp := false | ||
| for _, r := range got { | ||
| if isSavingsPlan(r) { | ||
| sp = true | ||
| assert.Equal(t, 1, r.Count) | ||
| } else { | ||
| ris = append(ris, r.Count) | ||
| } | ||
| } | ||
| assert.Equal(t, tt.wantRIs, ris) | ||
| assertSameRelativeOrder(t, tt.recs, got) | ||
| assert.Equal(t, tt.wantSP, sp) | ||
| assert.Len(t, got, tt.wantSize) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestApplyMinCountFloor_SavingsPlanExempt(t *testing.T) { | ||
| got := applyMinCountFloor([]common.Recommendation{mkRI("a", 1), mkSP(), mkRI("b", 5)}, 3) | ||
|
|
||
| require.Len(t, got, 2) | ||
| assert.Equal(t, []string{"Compute", "b"}, []string{got[0].ResourceType, got[1].ResourceType}, "input order kept") | ||
| var sps, ris int | ||
| for _, r := range got { | ||
| if isSavingsPlan(r) { | ||
| sps++ | ||
| } else { | ||
| ris++ | ||
| assert.Equal(t, 5, r.Count) | ||
| } | ||
| } | ||
| assert.Equal(t, 1, sps) | ||
| assert.Equal(t, 1, ris) | ||
| } | ||
|
|
||
| // assertSameRelativeOrder checks got is a subsequence of in by ResourceType. | ||
| func assertSameRelativeOrder(t *testing.T, in, got []common.Recommendation) { | ||
| t.Helper() | ||
| i := 0 | ||
| for _, g := range got { | ||
| for i < len(in) && in[i].ResourceType != g.ResourceType { | ||
| i++ | ||
| } | ||
| require.Less(t, i, len(in), "output order differs from input order") | ||
| i++ | ||
| } | ||
| } | ||
|
|
||
| // scoreLimitAndDisplay hands MinCount to scorer.Score, which must exempt | ||
| // Savings Plans (Count 1 is a placeholder) at the pinned library version. | ||
| func TestScoreLimitAndDisplay_MinCountKeepsSavingsPlan(t *testing.T) { | ||
| result := scoreLimitAndDisplay([]common.Recommendation{mkSP(), mkRI("a", 3)}, Config{MinCount: 2}, nil) | ||
|
|
||
| types := make([]common.CommitmentType, 0, len(result.Passed)) | ||
| for _, r := range result.Passed { | ||
| types = append(types, r.CommitmentType) | ||
| } | ||
| assert.ElementsMatch(t, []common.CommitmentType{common.CommitmentSavingsPlan, common.CommitmentReservedInstance}, types) | ||
| } | ||
|
|
||
| func TestApplyInstanceLimit_SavingsPlanAfterBudgetSpent(t *testing.T) { | ||
| got := ApplyInstanceLimit([]common.Recommendation{mkRI("a", 3), mkRI("b", 2), mkSP()}, 3) | ||
|
|
||
| require.Len(t, got, 2) | ||
| assert.Equal(t, "a", got[0].ResourceType) | ||
| assert.True(t, isSavingsPlan(got[1])) | ||
| } | ||
|
|
||
| func mkNamedSP(name string) common.Recommendation { | ||
| r := mkSP() | ||
| r.ResourceType = name | ||
| return r | ||
| } | ||
|
|
||
| // mixedOrderInput interleaves Savings Plans with instance rows. | ||
| func mixedOrderInput() []common.Recommendation { | ||
| return []common.Recommendation{ | ||
| mkNamedSP("S1"), mkRI("a", 3), mkNamedSP("S2"), mkRI("b", 2), | ||
| mkNamedSP("S3"), mkRI("c", 5), mkNamedSP("S4"), | ||
| } | ||
| } | ||
|
|
||
| func resourceTypes(recs []common.Recommendation) []string { | ||
| out := make([]string, 0, len(recs)) | ||
| for _, r := range recs { | ||
| out = append(out, r.ResourceType) | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| func TestMixedSavingsPlanOrder_Exact(t *testing.T) { | ||
| t.Run("cap 4", func(t *testing.T) { | ||
| got := applyGlobalInstanceLimit(mixedOrderInput(), Config{MaxInstances: 4}, rankBySavingsPercentage, nil) | ||
| assert.Equal(t, []string{"S1", "a", "S2", "b", "S3", "S4"}, resourceTypes(got)) | ||
| }) | ||
| t.Run("cap 4 min-count 2", func(t *testing.T) { | ||
| got := applyGlobalInstanceLimit(mixedOrderInput(), Config{MaxInstances: 4, MinCount: 2}, rankBySavingsPercentage, nil) | ||
| assert.Equal(t, []string{"S1", "a", "S2", "S3", "S4"}, resourceTypes(got)) | ||
| }) | ||
| t.Run("min-count floor 3", func(t *testing.T) { | ||
| got := applyMinCountFloor(mixedOrderInput(), 3) | ||
| assert.Equal(t, []string{"S1", "a", "S2", "S3", "c", "S4"}, resourceTypes(got)) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.