Skip to content

Commit

Permalink
rpc: set the job scale eval priority to the job priority.
Browse files Browse the repository at this point in the history
Previously the eval priority was set to the default priority
rather than the priority configured within the target job. This
change fixes this bug, ensuring any eval created as a result of
scaling uses the job priority.
  • Loading branch information
jrasell committed Nov 2, 2021
1 parent 8ba1444 commit 3c55826
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ func (j *Job) Scale(args *structs.JobScaleRequest, reply *structs.JobRegisterRes
eval := &structs.Evaluation{
ID: uuid.Generate(),
Namespace: namespace,
Priority: structs.JobDefaultPriority,
Priority: job.Priority, // Safe as nil check performed above.
Type: structs.JobTypeService,
TriggeredBy: structs.EvalTriggerScaling,
JobID: args.JobID,
Expand Down
51 changes: 51 additions & 0 deletions nomad/job_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6985,6 +6985,57 @@ func TestJobEndpoint_Scale_NoEval(t *testing.T) {
require.Equal(int64(originalCount), events[groupName][0].PreviousCount)
}

func TestJobEndpoint_Scale_Priority(t *testing.T) {
t.Parallel()
requireAssertion := require.New(t)

s1, cleanupS1 := TestServer(t, nil)
defer cleanupS1()
codec := rpcClient(t, s1)
testutil.WaitForLeader(t, s1.RPC)
fsmState := s1.fsm.State()

// Create a job and alter the priority.
job := mock.Job()
job.Priority = 90
originalCount := job.TaskGroups[0].Count
err := fsmState.UpsertJob(structs.MsgTypeTestSetup, 1000, job)
requireAssertion.Nil(err)

groupName := job.TaskGroups[0].Name
scale := &structs.JobScaleRequest{
JobID: job.ID,
Target: map[string]string{
structs.ScalingTargetGroup: groupName,
},
Count: helper.Int64ToPtr(int64(originalCount + 1)),
Message: "scotty, we need more power",
PolicyOverride: false,
WriteRequest: structs.WriteRequest{
Region: "global",
Namespace: job.Namespace,
},
}
var resp structs.JobRegisterResponse
err = msgpackrpc.CallWithCodec(codec, "Job.Scale", scale, &resp)
requireAssertion.NoError(err)
requireAssertion.NotEmpty(resp.EvalID)
requireAssertion.Greater(resp.EvalCreateIndex, resp.JobModifyIndex)

// Check the evaluation priority matches the job priority.
eval, err := fsmState.EvalByID(nil, resp.EvalID)
requireAssertion.Nil(err)
requireAssertion.NotNil(eval)
requireAssertion.EqualValues(resp.EvalCreateIndex, eval.CreateIndex)
requireAssertion.Equal(job.Priority, eval.Priority)
requireAssertion.Equal(job.Type, eval.Type)
requireAssertion.Equal(structs.EvalTriggerScaling, eval.TriggeredBy)
requireAssertion.Equal(job.ID, eval.JobID)
requireAssertion.Equal(structs.EvalStatusPending, eval.Status)
requireAssertion.NotZero(eval.CreateTime)
requireAssertion.NotZero(eval.ModifyTime)
}

func TestJobEndpoint_InvalidCount(t *testing.T) {
t.Parallel()
require := require.New(t)
Expand Down

0 comments on commit 3c55826

Please sign in to comment.