From a0c964a9c1de2bf0e03ee1d825354c8bbbbf6c03 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Fri, 5 May 2023 08:45:49 +0100 Subject: [PATCH 1/2] scale: fixed a bug where evals could be created with wrong type. The job scale RPC endpoint hard-coded the eval creation to use the type of service. This meant scaling events triggered on jobs of type batch would create evaluations with the wrong type, which does not seem to cause any problems, just confusion when correlating the two. --- nomad/job_endpoint.go | 2 +- nomad/job_endpoint_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index 664703941ecc..031a9df7408e 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -1152,7 +1152,7 @@ func (j *Job) Scale(args *structs.JobScaleRequest, reply *structs.JobRegisterRes ID: uuid.Generate(), Namespace: namespace, Priority: job.Priority, // Safe as nil check performed above. - Type: structs.JobTypeService, + Type: job.Type, TriggeredBy: structs.EvalTriggerScaling, JobID: args.JobID, JobModifyIndex: reply.JobModifyIndex, diff --git a/nomad/job_endpoint_test.go b/nomad/job_endpoint_test.go index 7ac5896e8501..e16b5f5e11d0 100644 --- a/nomad/job_endpoint_test.go +++ b/nomad/job_endpoint_test.go @@ -7868,6 +7868,44 @@ func TestJobEndpoint_Scale_SystemJob(t *testing.T) { `400,cannot scale jobs of type "system"`) } +func TestJobEndpoint_Scale_BatchJob(t *testing.T) { + ci.Parallel(t) + + testServer, testServerCleanup := TestServer(t, nil) + defer testServerCleanup() + codec := rpcClient(t, testServer) + testutil.WaitForLeader(t, testServer.RPC) + state := testServer.fsm.State() + + mockBatchJob := mock.BatchJob() + must.NoError(t, state.UpsertJob(structs.MsgTypeTestSetup, 10, nil, mockBatchJob)) + + scaleReq := &structs.JobScaleRequest{ + JobID: mockBatchJob.ID, + Target: map[string]string{ + structs.ScalingTargetGroup: mockBatchJob.TaskGroups[0].Name, + }, + Count: pointer.Of(int64(13)), + WriteRequest: structs.WriteRequest{ + Region: DefaultRegion, + Namespace: mockBatchJob.Namespace, + }, + } + var resp structs.JobRegisterResponse + must.NoError(t, msgpackrpc.CallWithCodec(codec, "Job.Scale", scaleReq, &resp)) + + // Pull the generated evaluation from state and ensure the detailed type + // matches the jobspec. + testFMSSnapshot, err := testServer.fsm.State().Snapshot() + must.NoError(t, err) + + scaleEval, err := testFMSSnapshot.EvalByID(nil, resp.EvalID) + must.NoError(t, err) + must.Eq(t, resp.EvalID, scaleEval.ID) + must.Eq(t, mockBatchJob.ID, scaleEval.JobID) + must.Eq(t, mockBatchJob.Type, scaleEval.Type) +} + func TestJobEndpoint_InvalidCount(t *testing.T) { ci.Parallel(t) require := require.New(t) From 983bd39a502c4ca54b3a06549f70c26f08b1b6a7 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Fri, 5 May 2023 08:57:54 +0100 Subject: [PATCH 2/2] changelog: add entry for #17092 --- .changelog/17092.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/17092.txt diff --git a/.changelog/17092.txt b/.changelog/17092.txt new file mode 100644 index 000000000000..0f4c4a770504 --- /dev/null +++ b/.changelog/17092.txt @@ -0,0 +1,3 @@ +```release-note:bug +scale: Fixed a bug where evals could be created with the wrong type +```