-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Scaling API changes #7409
Merged
Merged
Scaling API changes #7409
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
ee1b091
WIP: adding ScalingPolicy to api/structs and state store
cgbaker 0762386
wip: upsert/delete scaling policies on job upsert/delete
cgbaker e6d75ca
wip: was incorrectly parsing ScalingPolicy
cgbaker 7ba9b94
wip: test for scaling policy parsing
cgbaker a715eb7
wip: added policy get endpoint, added UUID to policy
cgbaker 8102849
wip: working on job group scaling endpoint
cgbaker 1c9bac9
wip: added job.scale rpc endpoint, needs explicit test (tested via ht…
cgbaker ef7cb0e
wip: add job scale endpoint in client
lgfa29 4406668
wip: add GET endpoint for job group scaling target
cgbaker 94381c0
wip: added tests for client methods around group scaling
cgbaker 16472c0
wip: remove PolicyOverride from scaling request
cgbaker 6b9c004
wip: added Enabled to ScalingPolicyListStub, removed JobID from body …
cgbaker 7544aaa
wip: add scaling policies methods to the client
lgfa29 836acc1
wip: add tests for job scale method
lgfa29 9756c64
wip: use testify in job scaling tests
lgfa29 c095f41
wip: removed some commented junk from scaling poc
cgbaker 3b4a1ae
finished refactoring state store, schema, etc
cgbaker 66bf8dd
wip: some tests still failing
cgbaker 9243718
scaling: ensure min and max int64s are in toplevel of block.
jrasell 03eb96a
wip: scaling status return, almost done
cgbaker 4759bc3
finished Job.ScaleStatus RPC, need to work on http endpoint
cgbaker 2d88d57
fixed http endpoints for job.register and job.scalestatus
cgbaker 4156009
scaling api: put api.* objects in agreement with structs.* objects
cgbaker 9292e88
changes to Canonicalize, Validate, and api->struct conversion so that…
cgbaker f704a49
added new ACL capabilities related to autoscaling:
cgbaker ac5a166
wip: ACL checking for RPC Job.ScaleStatus
cgbaker d4f967c
made count optional during job scaling actions
cgbaker ff652bf
add acl validation to Scaling.ListPolicies and Scaling.GetPolicy
cgbaker e831ec3
added new int64ToPtr method to api/util to avoid pulling in other pac…
cgbaker 4330fe8
bad conversion between api.ScalingPolicy and structs.ScalingPolicy meant
cgbaker 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 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 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 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 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 |
---|---|---|
|
@@ -909,6 +909,46 @@ func TestJobs_Info(t *testing.T) { | |
} | ||
} | ||
|
||
func TestJobs_ScaleInvalidAction(t *testing.T) { | ||
t.Parallel() | ||
require := require.New(t) | ||
|
||
c, s := makeClient(t, nil, nil) | ||
defer s.Stop() | ||
jobs := c.Jobs() | ||
|
||
// Check if invalid inputs fail | ||
tests := []struct { | ||
jobID string | ||
group string | ||
value int | ||
want string | ||
}{ | ||
{"", "", 1, "404"}, | ||
{"i-dont-exist", "", 1, "400"}, | ||
{"", "i-dont-exist", 1, "404"}, | ||
{"i-dont-exist", "me-neither", 1, "404"}, | ||
} | ||
for _, test := range tests { | ||
_, _, err := jobs.Scale(test.jobID, test.group, &test.value, stringToPtr("reason"), nil, nil, nil) | ||
require.Errorf(err, "expected jobs.Scale(%s, %s) to fail", test.jobID, test.group) | ||
require.Containsf(err.Error(), test.want, "jobs.Scale(%s, %s) error doesn't contain %s, got: %s", test.jobID, test.group, test.want, err) | ||
} | ||
|
||
// Register test job | ||
job := testJob() | ||
job.ID = stringToPtr("TestJobs_Scale") | ||
_, wm, err := jobs.Register(job, nil) | ||
require.NoError(err) | ||
assertWriteMeta(t, wm) | ||
|
||
// Perform a scaling action with bad group name, verify error | ||
_, _, err = jobs.Scale(*job.ID, "incorrect-group-name", intToPtr(2), | ||
stringToPtr("because"), nil, nil, nil) | ||
require.Error(err) | ||
require.Contains(err.Error(), "does not exist") | ||
} | ||
|
||
func TestJobs_Versions(t *testing.T) { | ||
t.Parallel() | ||
c, s := makeClient(t, nil, nil) | ||
|
@@ -1533,3 +1573,82 @@ func TestJobs_AddSpread(t *testing.T) { | |
t.Fatalf("expect: %#v, got: %#v", expect, job.Spreads) | ||
} | ||
} | ||
|
||
// TestJobs_ScaleAction tests the scale target for task group count | ||
func TestJobs_ScaleAction(t *testing.T) { | ||
t.Parallel() | ||
require := require.New(t) | ||
|
||
c, s := makeClient(t, nil, nil) | ||
defer s.Stop() | ||
jobs := c.Jobs() | ||
|
||
id := "job-id/with\\troublesome:characters\n?&字\000" | ||
job := testJobWithScalingPolicy() | ||
job.ID = &id | ||
groupName := *job.TaskGroups[0].Name | ||
groupCount := *job.TaskGroups[0].Count | ||
|
||
// Trying to scale against a target before it exists returns an error | ||
_, _, err := jobs.Scale(id, "missing", intToPtr(groupCount+1), stringToPtr("this won't work"), nil, nil, nil) | ||
require.Error(err) | ||
require.Contains(err.Error(), "not found") | ||
|
||
// Register the job | ||
_, wm, err := jobs.Register(job, nil) | ||
require.NoError(err) | ||
assertWriteMeta(t, wm) | ||
|
||
// Perform scaling action | ||
newCount := groupCount + 1 | ||
resp1, wm, err := jobs.Scale(id, groupName, | ||
intToPtr(newCount), stringToPtr("need more instances"), nil, nil, nil) | ||
|
||
require.NoError(err) | ||
require.NotNil(resp1) | ||
require.NotEmpty(resp1.EvalID) | ||
assertWriteMeta(t, wm) | ||
|
||
// Query the job again | ||
resp, _, err := jobs.Info(*job.ID, nil) | ||
require.NoError(err) | ||
require.Equal(*resp.TaskGroups[0].Count, newCount) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a test for |
||
// TODO: check if reason is stored | ||
} | ||
|
||
// TestJobs_ScaleStatus tests the /scale status endpoint for task group count | ||
func TestJobs_ScaleStatus(t *testing.T) { | ||
t.Parallel() | ||
|
||
require := require.New(t) | ||
|
||
c, s := makeClient(t, nil, nil) | ||
defer s.Stop() | ||
jobs := c.Jobs() | ||
|
||
// Trying to retrieve a status before it exists returns an error | ||
id := "job-id/with\\troublesome:characters\n?&字\000" | ||
_, _, err := jobs.ScaleStatus(id, nil) | ||
require.Error(err) | ||
require.Contains(err.Error(), "not found") | ||
|
||
// Register the job | ||
job := testJobWithScalingPolicy() | ||
job.ID = &id | ||
groupName := *job.TaskGroups[0].Name | ||
groupCount := *job.TaskGroups[0].Count | ||
_, wm, err := jobs.Register(job, nil) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
assertWriteMeta(t, wm) | ||
|
||
// Query the scaling endpoint and verify success | ||
result, qm, err := jobs.ScaleStatus(id, nil) | ||
require.NoError(err) | ||
assertQueryMeta(t, qm) | ||
|
||
// Check that the result is what we expect | ||
require.Equal(groupCount, result.TaskGroups[groupName].Desired) | ||
} |
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.
A bit of bikeshedding here, but the other policies are named as verbs, so should this be
?