-
Notifications
You must be signed in to change notification settings - Fork 126
/
common.go
72 lines (67 loc) · 2.01 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package scheduler
import (
"fmt"
"golang.org/x/exp/maps"
"github.com/armadaproject/armada/internal/common/armadacontext"
armadamaps "github.com/armadaproject/armada/internal/common/maps"
armadaslices "github.com/armadaproject/armada/internal/common/slices"
schedulercontext "github.com/armadaproject/armada/internal/scheduler/context"
"github.com/armadaproject/armada/internal/scheduler/jobdb"
"github.com/armadaproject/armada/internal/scheduler/schedulerobjects"
)
// PrintJobSummary logs a summary of the job scheduling context
// It will log a high level summary at Info level, and a list of all queues + jobs affected at debug level
func PrintJobSummary(ctx *armadacontext.Context, prefix string, jctxs []*schedulercontext.JobSchedulingContext) {
if len(jctxs) == 0 {
return
}
jobsByQueue := armadaslices.MapAndGroupByFuncs(
jctxs,
func(jctx *schedulercontext.JobSchedulingContext) string {
return jctx.Job.Queue()
},
func(jctx *schedulercontext.JobSchedulingContext) *jobdb.Job {
return jctx.Job
},
)
resourcesByQueue := armadamaps.MapValues(
jobsByQueue,
func(jobs []*jobdb.Job) schedulerobjects.ResourceList {
rv := schedulerobjects.NewResourceListWithDefaultSize()
for _, job := range jobs {
rv.AddV1ResourceList(job.ResourceRequirements().Requests)
}
return rv
},
)
jobCountPerQueue := armadamaps.MapValues(
jobsByQueue,
func(jobs []*jobdb.Job) int {
return len(jobs)
},
)
jobIdsByQueue := armadamaps.MapValues(
jobsByQueue,
func(jobs []*jobdb.Job) []string {
rv := make([]string, len(jobs))
for i, job := range jobs {
rv[i] = job.Id()
}
return rv
},
)
summary := fmt.Sprintf(
"affected queues %v; resources %v; jobs per queue %v",
maps.Keys(jobsByQueue),
armadamaps.MapValues(
resourcesByQueue,
func(rl schedulerobjects.ResourceList) string {
return rl.CompactString()
},
),
jobCountPerQueue,
)
verbose := fmt.Sprintf("affected jobs %v", jobIdsByQueue)
ctx.Infof("%s %s", prefix, summary)
ctx.Debugf("%s %s", prefix, verbose)
}