-
Couldn't load subscription status.
- Fork 2k
Add priority flag to Dispatch CLI and API | NET-10171 #25622
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
Conversation
a30f3bd to
41e5099
Compare
d9a3db4 to
ad2f546
Compare
a3e732b to
c1a973c
Compare
c1a973c to
6a6bc2d
Compare
Add HTTP_JobDispatchPriority test
6dfed83 to
153873c
Compare
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.
Thanks for updating the docs.
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.
This is looking really good @tehut! I've left a bunch of comments around the tests and the use of the shoenig/test/must API. But once those are resolved I think we'll be in good shape to ship this.
|
|
||
| - `-ui`: Open the dispatched job in the browser. | ||
|
|
||
| - `-priority`: Optional integer between 50-100 that overrides any |
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.
Jobs have a minimum priority of 1, so I don't think we want to floor the dispatch priority to 50. But it also doesn't look like there's a code change here to enforce this floor, so this might just be a docs issue?
command/agent/job_endpoint_test.go
Outdated
| if err != nil { | ||
| t.Logf("err: %v", err) | ||
| } |
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.
If we have an unexpected error, must.NoError will report it, so we don't need this bit anymore.
| if err != nil { | |
| t.Logf("err: %v", err) | |
| } |
command/agent/job_endpoint_test.go
Outdated
| must.NoError(t, err) | ||
| if err != nil { | ||
| t.Fatalf("err: %v", err) | ||
| t.Logf("err: %v", err) |
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.
We don't need this block anymore either (I can't leave a suggestion because there's a deleted line in here).
command/agent/job_endpoint_test.go
Outdated
| obj, err := s.Server.JobSpecificRequest(respW, req2) | ||
| if err != nil { | ||
| t.Fatalf("err: %v", err) | ||
| t.Logf("err: %v", err) |
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.
This no longer exits on error so we've broken the assertion here. Looks like this block could be turned into must.NoError(t, err) instead.
command/agent/job_endpoint_test.go
Outdated
| dispatch := obj.(structs.JobDispatchResponse) | ||
| if dispatch.EvalID == "" { | ||
| t.Fatalf("bad: %v", dispatch) | ||
| t.Logf("bad: %v", dispatch) |
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.
We have must.NotEq(t, "", dispatch.EvalID) below, which will log if we fail the assertion, so we can remove this whole block. Same applies to the assertion after that.
nomad/job_endpoint_test.go
Outdated
| err: false, | ||
| priority: reqNoInputValidPriority.Priority, | ||
| }, | ||
| {name: "invalid priority", |
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.
Nitpick: keeping test case text align makes it easier to scan
| {name: "invalid priority", | |
| { | |
| name: "invalid priority", |
nomad/job_endpoint_test.go
Outdated
| var dispatchResp structs.JobDispatchResponse | ||
| dispatchErr := msgpackrpc.CallWithCodec(codec, "Job.Dispatch", tc.dispatchReq, &dispatchResp) | ||
| if dispatchErr != nil { | ||
| must.True(t, tc.err) |
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.
I realize this is existing code, but this is asserting the test case field. I'd probably refactor this test a little bit to combine tc.err and tc.errStr into a tc.expectError field (of type error), and then do something along the lines of:
if tc.expectError != nil {
must.ErrorContains(t, dispatchErr, tc.expectError.Error())
} else {
must.NoError(t, dispatchErr)
}I think you'll find that pattern gets used in a lot of our tests.
nomad/job_endpoint_test.go
Outdated
| // Check that we got an eval and job id back | ||
| switch dispatchResp.EvalID { | ||
| case "": | ||
| must.Eq(t, tc.noEval, true) |
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.
The existing test code has a similar issue to what I've pointed out above, where we're making an assertion on the test case field.
nomad/job_endpoint_test.go
Outdated
| if out.CreateIndex != dispatchResp.JobCreateIndex { | ||
| t.Logf("index mis-match") | ||
| } |
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.
We've already asserted this above, which will log. If they weren't equal, this block would be unreachable anyways.
| if out.CreateIndex != dispatchResp.JobCreateIndex { | |
| t.Logf("index mis-match") | |
| } |
Similar for other logs in this test.
nomad/job_endpoint_test.go
Outdated
| if tc.priority != 0 { | ||
| must.Eq(t, tc.priority, out.Priority) | ||
| } |
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.
I'd make sure that tc.priority is always set (ex. it could be tc.expectPriority), so that we can see it at a glance in the test case list and then there's no conditional here -- we just always call must.Eq.
308eaa0 to
c1fff15
Compare
…to set dispatch priority
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.
LGTM! Nice work!
Now that Nomad 1.10.0 has shipped, new features want to land in the 1.10.x branch (see this backport labels table). I've added the backport label for 1.10.x. Once you squash-merge this (give the squash commit a nice commit message too), a backport PR will be created for you to approve and squash-merge.
|
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
Description
This PR addresses #10803 by adding a
-priorityflag directly to thenomad job dispatchCLI command.To do so we:
jobs.goDispatchOptionsstruct with the new priority field as well as all the current Dispatch options.Dispatch()endpoint to a newDispatchOpts()HTTP API endpoint that takes theDispatchOptionsstuct and is used under the cover byDispatch()command/job_dispatch.goDispatch()with one toDispatchOpts()nomad/job_endpoint.goUpdated the
Dispatch()function to:args.Prioritywith the value in the parent job if it is set to 0/unsetvalidateDispatchRequest()(not used outside this file) to accept a *ConfigvalidateDispatchRequest()that replicates the min/max priority value check from jobValidator.Validate() and applies it toargs.Priority.nomad/structs/structs.gowebsite/..../dispatch.mdx- priorityto the list of dispatch optionsTesting & Reproduction steps
N/A
Links
GH Issue: #10803
Contributor Checklist
changelog entry using the
make clcommand.ensure regressions will be caught.
and job configuration, please update the Nomad website documentation to reflect this. Refer to
the website README for docs guidelines. Please also consider whether the
change requires notes within the upgrade guide.
Reviewer Checklist
backporting document.
in the majority of situations. The main exceptions are long-lived feature branches or merges where
history should be preserved.
within the public repository.