-
Notifications
You must be signed in to change notification settings - Fork 126
/
root.go
134 lines (121 loc) · 3.53 KB
/
root.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package cmd
import (
"fmt"
"github.com/armadaproject/armada/internal/common/armadacontext"
"github.com/armadaproject/armada/internal/scheduler/simulator"
"github.com/armadaproject/armada/pkg/armadaevents"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
log2 "log"
"os"
"strings"
)
func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "Simulate",
Short: "Simulate the scheduling of jobs on Armada",
RunE: runSimulations,
}
cmd.Flags().BoolP("verbose", "v", false, "Logs detailed output to console when specified")
cmd.Flags().String("clusters", "", "Pattern specifying cluster configurations to simulate on")
cmd.Flags().String("workloads", "", "Pattern specifying workloads to simulate")
cmd.Flags().String("configs", "", "Pattern specifying scheduler configurations to use for simulation")
return cmd
}
func runSimulations(cmd *cobra.Command, args []string) error {
clusterPattern, err := cmd.Flags().GetString("clusters")
if err != nil {
return err
}
workloadPattern, err := cmd.Flags().GetString("workloads")
if err != nil {
return err
}
configPattern, err := cmd.Flags().GetString("configs")
if err != nil {
return err
}
verbose, err := cmd.Flags().GetBool("verbose")
if err != nil {
return err
}
ctx := armadacontext.Background()
if !verbose {
logger := logrus.New()
logger.SetLevel(logrus.ErrorLevel)
ctx = armadacontext.New(ctx, logrus.NewEntry(logger))
}
clusterSpecs, err := simulator.ClusterSpecsFromPattern(clusterPattern)
if err != nil {
return err
}
workloadSpecs, err := simulator.WorkloadFromPattern(workloadPattern)
if err != nil {
return err
}
schedulingConfigsByFilePath, err := simulator.SchedulingConfigsByFilePathFromPattern(configPattern)
if err != nil {
return err
}
simulators := make([]*simulator.Simulator, 0)
metricsCollectors := make([]*simulator.MetricsCollector, 0)
eventSequenceChannels := make([]<-chan *armadaevents.EventSequence, 0)
filePaths := make([]string, 0)
for _, clusterSpec := range clusterSpecs {
for _, workloadSpec := range workloadSpecs {
for filePath, schedulingConfig := range schedulingConfigsByFilePath {
if s, err := simulator.NewSimulator(clusterSpec, workloadSpec, schedulingConfig); err != nil {
return err
} else {
simulators = append(simulators, s)
metricsCollectors = append(metricsCollectors, simulator.NewMetricsCollector(s.Output()))
filePaths = append(filePaths, filePath)
eventSequenceChannels = append(eventSequenceChannels, s.Output())
}
}
}
}
threadSafeLogger := log2.New(os.Stdout, "", 0)
g, ctx := armadacontext.ErrGroup(ctx)
for _, s := range simulators {
s := s
g.Go(func() error {
return s.Run(ctx)
})
}
for _, c := range eventSequenceChannels {
c := c
g.Go(func() error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case eventSequence, ok := <-c:
if !ok {
return nil
}
ctx.Info(*eventSequence.Events[0].Created, simulator.EventSequenceSummary(eventSequence))
}
}
})
}
for i, mc := range metricsCollectors {
mc := mc
s := simulators[i]
fp := filePaths[i]
g.Go(func() error {
if err := mc.Run(ctx); err != nil {
return err
}
var sb strings.Builder
sb.WriteString(fmt.Sprintf("\nRunning Simulation of workload %s on cluster %s with configuration %s\n", s.WorkloadSpec.Name, s.ClusterSpec.Name, fp))
sb.WriteString(fmt.Sprint("Simulation Result: ", mc.String(), "\n"))
threadSafeLogger.Print(sb.String())
return nil
})
}
if err := g.Wait(); err != nil {
return err
}
return nil
}