Skip to content

Commit

Permalink
Adding Node, Cluster and ExitCode to Jobs (#3442)
Browse files Browse the repository at this point in the history
* Adding Node, Cluster and ExitCode to Jobs (#80)

* Adding Node, Cluster and ExitCode to Jobs

* Wip fixing tests

* Fixing tests

* Linting

* Linting

* Add unit tests

* Update exit code

* Go Linting

---------

Co-authored-by: Mia Mijovic <Mia.Mijovic@gresearch.co.uk>
  • Loading branch information
mijovicmia and Mia Mijovic authored Mar 4, 2024
1 parent e5a0ce5 commit d76d5ad
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/lookout/ui/src/models/lookoutV2Models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export type Job = {
lastActiveRunId?: string
lastTransitionTime: string
cancelReason?: string
node?: string
cluster?: string
exitCode?: number
}

export type JobKey = keyof Job
Expand Down
27 changes: 27 additions & 0 deletions internal/lookout/ui/src/utils/jobsTableColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export enum StandardColumnId {
SelectorCol = "selectorCol",

Count = "jobCount",
Node = "node",
Cluster = "cluster",
ExitCode = "exitCode",
}

export const ANNOTATION_COLUMN_PREFIX = "annotation_"
Expand Down Expand Up @@ -394,6 +397,30 @@ export const JOB_COLUMNS: JobTableColumn[] = [
enableSorting: true,
},
}),
accessorColumn({
id: StandardColumnId.Node,
accessor: "node",
displayName: "Node",
additionalOptions: {
size: 200,
},
}),
accessorColumn({
id: StandardColumnId.Cluster,
accessor: "cluster",
displayName: "Cluster",
additionalOptions: {
size: 200,
},
}),
accessorColumn({
id: StandardColumnId.ExitCode,
accessor: "exitCode",
displayName: "Exit Code",
additionalOptions: {
size: 100,
},
}),
]

export const DEFAULT_COLUMNS_TO_DISPLAY: Set<ColumnId> = new Set([
Expand Down
3 changes: 3 additions & 0 deletions internal/lookoutv2/conversions/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func ToSwaggerJob(job *model.Job) *models.Job {
State: job.State,
Submitted: strfmt.DateTime(job.Submitted),
CancelReason: job.CancelReason,
Node: job.Node,
Cluster: job.Cluster,
ExitCode: job.ExitCode,
}
}

Expand Down
12 changes: 12 additions & 0 deletions internal/lookoutv2/gen/models/job.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/lookoutv2/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type Job struct {
State string
Submitted time.Time
CancelReason *string
Node *string
Cluster string
ExitCode *int32
}

// PostgreSQLTime is a wrapper around time.Time that converts to UTC when
Expand Down
16 changes: 15 additions & 1 deletion internal/lookoutv2/repository/getjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (r *SqlGetJobsRepository) getJobs(ctx *armadacontext.Context, filters []*mo
log.WithError(err).Error("failed getting run rows")
return err
}

annotationRows, err = makeAnnotationRows(ctx, tx, tempTableName)
if err != nil {
log.WithError(err).Error("failed getting annotation rows")
Expand All @@ -135,7 +136,6 @@ func (r *SqlGetJobsRepository) getJobs(ctx *armadacontext.Context, filters []*mo
if err != nil {
return nil, err
}

jobs, err := rowsToJobs(jobRows, runRows, annotationRows)
if err != nil {
return nil, err
Expand Down Expand Up @@ -201,6 +201,13 @@ func (r *SqlGetJobsRepository) getJobsJsonb(ctx *armadacontext.Context, filters
return err
}
}
if len(job.Runs) > 0 {
lastRun := job.Runs[len(job.Runs)-1] // Get the last run
job.Node = lastRun.Node
job.Cluster = lastRun.Cluster
job.ExitCode = lastRun.ExitCode

}
jobs = append(jobs, job)
}
return nil
Expand Down Expand Up @@ -251,6 +258,13 @@ func rowsToJobs(jobRows []*jobRow, runRows []*runRow, annotationRows []*annotati
for i, jobId := range orderedJobIds {
job := jobMap[jobId]
sortRuns(job.Runs)
if len(job.Runs) > 0 {
lastRun := job.Runs[len(job.Runs)-1] // Get the last run
job.Node = lastRun.Node
job.Cluster = lastRun.Cluster
job.ExitCode = lastRun.ExitCode

}
jobs[i] = job
}

Expand Down
66 changes: 66 additions & 0 deletions internal/lookoutv2/repository/getjobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1997,3 +1997,69 @@ func TestGetJobsActiveJobSet(t *testing.T) {
})
require.NoError(t, err)
}

func TestGetJobsWithLatestRunDetails(t *testing.T) {
err := withGetJobsSetup(func(converter *instructions.InstructionConverter, store *lookoutdb.LookoutDb, repo *SqlGetJobsRepository) error {
runIdLatest := uuid.NewString()
// Simulate job submission and multiple runs, with the latest run being successful
NewJobSimulator(converter, store).
Submit(queue, jobSet, owner, namespace, baseTime, basicJobOpts).
Pending(uuid.NewString(), "first-cluster", baseTime).
Running(uuid.NewString(), "first-node", baseTime.Add(time.Minute)).
Pending(runIdLatest, "latest-cluster", baseTime.Add(2*time.Minute)).
Running(runIdLatest, "latest-node", baseTime.Add(3*time.Minute)).
RunSucceeded(runIdLatest, baseTime.Add(4*time.Minute)).
Build().
Job()

result, err := repo.GetJobs(armadacontext.TODO(), []*model.Filter{}, false, &model.Order{}, 0, 10)
require.NoError(t, err)
require.Len(t, result.Jobs, 1)

// Adjusting assertions to dereference pointer fields
if assert.NotNil(t, result.Jobs[0].Node) {
assert.Equal(t, "latest-node", *result.Jobs[0].Node)
}
if assert.NotNil(t, result.Jobs[0].ExitCode) {
assert.Equal(t, int32(0), *result.Jobs[0].ExitCode)
}
if assert.NotNil(t, result.Jobs[0].Cluster) {
assert.Equal(t, "latest-cluster", result.Jobs[0].Cluster)
}

return nil
})
require.NoError(t, err)
}

func TestGetJobsWithSpecificRunDetails(t *testing.T) {
err := withGetJobsSetup(func(converter *instructions.InstructionConverter, store *lookoutdb.LookoutDb, repo *SqlGetJobsRepository) error {
runIdSpecific := uuid.NewString()
// Simulate job submission and a specific failed run
NewJobSimulator(converter, store).
Submit(queue, jobSet, owner, namespace, baseTime, basicJobOpts).
Pending(runIdSpecific, "specific-cluster", baseTime).
Running(runIdSpecific, "specific-node", baseTime.Add(time.Minute)).
RunFailed(runIdSpecific, "specific-node", 2, "Specific failure message", baseTime.Add(2*time.Minute)).
Build().
Job()

result, err := repo.GetJobs(armadacontext.TODO(), []*model.Filter{}, false, &model.Order{}, 0, 10)
require.NoError(t, err)
require.Len(t, result.Jobs, 1)

// Adjusting assertions to dereference pointer fields
if assert.NotNil(t, result.Jobs[0].Node) {
assert.Equal(t, "specific-node", *result.Jobs[0].Node)
}
if assert.NotNil(t, result.Jobs[0].ExitCode) {
assert.Equal(t, int32(2), *result.Jobs[0].ExitCode)
}
if assert.NotNil(t, result.Jobs[0].Cluster) {
assert.Equal(t, "specific-cluster", result.Jobs[0].Cluster)
}

return nil
})
require.NoError(t, err)
}
5 changes: 5 additions & 0 deletions internal/lookoutv2/repository/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (js *JobSimulator) Pending(runId string, cluster string, timestamp time.Tim
js.job.LastActiveRunId = &runId
js.job.LastTransitionTime = ts
js.job.State = string(lookout.JobPending)
js.job.Cluster = cluster
rp := &runPatch{
runId: runId,
cluster: &cluster,
Expand Down Expand Up @@ -264,6 +265,7 @@ func (js *JobSimulator) Running(runId string, node string, timestamp time.Time)
js.job.LastActiveRunId = &runId
js.job.LastTransitionTime = ts
js.job.State = string(lookout.JobRunning)
js.job.Node = &node
updateRun(js.job, &runPatch{
runId: runId,
jobRunState: lookout.JobRunRunning,
Expand Down Expand Up @@ -613,6 +615,9 @@ func timestampOrNow(timestamp time.Time) time.Time {
}

func updateRun(job *model.Job, patch *runPatch) {
if patch.exitCode != nil {
job.ExitCode = patch.exitCode
}
for _, run := range job.Runs {
if run.RunId == patch.runId {
patchRun(run, patch)
Expand Down

0 comments on commit d76d5ad

Please sign in to comment.