Repository navigation
chore(deps): bump cloud-commitments-go to 88b95b6 and keep GCP recommendations when some are skipped #1490
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
chore(deps): bump cloud-commitments-go to 88b95b6 and keep GCP recommendations when some are skipped #1490
Changes from all commits
Commits
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
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,91 @@ | ||
| package scheduler | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/LeanerCloud/cloud-commitments-platform/internal/config" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // skipErr stands in for the GCP provider's unexported partial-result error: | ||
| // the scheduler must match the Partial() method, not the type (issue #1472). | ||
| type skipErr struct { | ||
| msg string | ||
| partial bool | ||
| } | ||
|
|
||
| func (e *skipErr) Error() string { return e.msg } | ||
| func (e *skipErr) Partial() bool { return e.partial } | ||
|
|
||
| const skipMsg = "gcp recommendations: 3 recommendation(s) skipped: computeengine us-east1: non-USD; cloudsql us-east1: bad plan" | ||
|
|
||
| func gcpAmbient(s *Scheduler) ([]config.RecommendationRecord, []string, *sweepGap, error) { | ||
| return s.collectGCPRecommendations(context.Background(), &config.GlobalConfig{}) | ||
| } | ||
|
|
||
| func TestGCPPartialResult_KeepsRecsAndRecordsSkips(t *testing.T) { | ||
| t.Setenv("GCP_PROJECT_ID", "proj-a") | ||
| s, _ := newPartialSweepScheduler(t, "gcp", fmt.Errorf("collect: %w", &skipErr{msg: skipMsg, partial: true})) | ||
|
|
||
| recs, roster, gap, err := gcpAmbient(s) | ||
|
|
||
| require.NoError(t, err, "a partial GCP result must not fail the collection run") | ||
| assert.NotEmpty(t, recs, "the recommendations that converted must be kept") | ||
| require.NotNil(t, gap, "the skip must be recorded for the user") | ||
| assert.Equal(t, 3, gap.skippedRecommendations) | ||
| assert.Equal(t, 3, gap.toProviderSweep("gcp").SkippedRecommendations) | ||
| assert.NotEmpty(t, roster, | ||
| "skipped recommendations are invalid, so the account stays eviction-eligible and their stale rows go") | ||
| assert.Zero(t, gap.forAccount().incompleteAccounts, "a skip is not an incomplete account") | ||
| } | ||
|
|
||
| func TestGCPPartialResult_NonPartialErrorsStayHard(t *testing.T) { | ||
| for name, err := range map[string]error{ | ||
| "plain error": errors.New("boom"), | ||
| "Partial() == false": &skipErr{msg: skipMsg, partial: false}, | ||
| } { | ||
| t.Run(name, func(t *testing.T) { | ||
| t.Setenv("GCP_PROJECT_ID", "proj-a") | ||
| s, _ := newPartialSweepScheduler(t, "gcp", err) | ||
|
|
||
| recs, roster, gap, gotErr := gcpAmbient(s) | ||
|
|
||
| require.Error(t, gotErr, "a non-partial error must fail the run") | ||
| assert.Empty(t, recs) | ||
| assert.Empty(t, roster) | ||
| assert.Nil(t, gap) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGCPPartialResult_FanOutKeepsAccountEvictable(t *testing.T) { | ||
| accounts := []config.CloudAccount{{ID: "a1", Name: "a1", ExternalID: "p1"}, {ID: "a2", Name: "a2", ExternalID: "p2"}} | ||
| fn := func(_ context.Context, acct config.CloudAccount) ([]config.RecommendationRecord, *sweepGap, error) { | ||
| gap, err := tolerateIncompleteSweep("gcp", &skipErr{msg: skipMsg, partial: true}) | ||
| if acct.ID == "a2" { | ||
| // A lost project in the same account hold back eviction as before. | ||
| gap = mergeSweepGaps(gap, gapFromPartialSubscriptions(partialSweepErr("p-x"))) | ||
| } | ||
| return []config.RecommendationRecord{{ID: acct.ID}}, gap, err | ||
| } | ||
|
|
||
| recs, outcome := fanOutPerAccount(context.Background(), "GCP", accounts, fn) | ||
|
|
||
| assert.Len(t, recs, 2) | ||
| assert.Equal(t, []string{"a1"}, outcome.SucceededAccountIDs) | ||
| assert.Equal(t, []string{"a2"}, outcome.IncompleteAccountIDs) | ||
| require.NotNil(t, outcome.Gap) | ||
| assert.Equal(t, 6, outcome.Gap.skippedRecommendations) | ||
| assert.Equal(t, 1, outcome.Gap.incompleteAccounts) | ||
| } | ||
|
|
||
| func TestGCPPartialResult_UnparsableCountStillRecorded(t *testing.T) { | ||
| gap, err := tolerateIncompleteSweep("gcp", &skipErr{msg: "something skipped", partial: true}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, gap) | ||
| assert.Zero(t, gap.skippedRecommendations) | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔎 Supported by static analysis
Script executed:
Repository: LeanerCloud/cloud-commitments-platform
Length of output: 9029
Script executed:
Repository: LeanerCloud/cloud-commitments-platform
Length of output: 10503
Script executed:
Repository: LeanerCloud/cloud-commitments-platform
Length of output: 4594
Show the skipped warning after an explicit refresh.
When the initial freshness response has no skipped recommendations,
triggerAutoRefreshIfStalesetsautoRefreshAttemptedand shows no warning. The Refresh button startsstartRecommendationsRefresh(loadRecommendations), which reloads the recommendations after completion but does not displaydescribeSkippedRecommendationsor fetch freshness on the normal completion path. The reload cannot trigger the warning becauseautoRefreshAttemptedblocks the freshness check.Display the warning from the refresh-completion path, or separate the warning check from the one-time auto-refresh guard.