-
Notifications
You must be signed in to change notification settings - Fork 126
/
config_scheduler.go
174 lines (146 loc) · 7.83 KB
/
config_scheduler.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package evergreen
import (
"context"
"github.com/evergreen-ci/utility"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson"
)
// SchedulerConfig holds relevant settings for the scheduler process.
type SchedulerConfig struct {
TaskFinder string `bson:"task_finder" json:"task_finder" yaml:"task_finder"`
HostAllocator string `bson:"host_allocator" json:"host_allocator" yaml:"host_allocator"`
HostAllocatorRoundingRule string `bson:"host_allocator_rounding_rule" json:"host_allocator_rounding_rule" mapstructure:"host_allocator_rounding_rule"`
HostAllocatorFeedbackRule string `bson:"host_allocator_feedback_rule" json:"host_allocator_feedback_rule" mapstructure:"host_allocator_feedback_rule"`
HostsOverallocatedRule string `bson:"hosts_overallocated_rule" json:"hosts_overallocated_rule" mapstructure:"hosts_overallocated_rule"`
FutureHostFraction float64 `bson:"free_host_fraction" json:"free_host_fraction" yaml:"free_host_fraction"`
CacheDurationSeconds int `bson:"cache_duration_seconds" json:"cache_duration_seconds" yaml:"cache_duration_seconds"`
Planner string `bson:"planner" json:"planner" mapstructure:"planner"`
TargetTimeSeconds int `bson:"target_time_seconds" json:"target_time_seconds" mapstructure:"target_time_seconds"`
AcceptableHostIdleTimeSeconds int `bson:"acceptable_host_idle_time_seconds" json:"acceptable_host_idle_time_seconds" mapstructure:"acceptable_host_idle_time_seconds"`
GroupVersions bool `bson:"group_versions" json:"group_versions" mapstructure:"group_versions"`
PatchFactor int64 `bson:"patch_zipper_factor" json:"patch_factor" mapstructure:"patch_zipper"`
PatchTimeInQueueFactor int64 `bson:"patch_time_in_queue_factor" json:"patch_time_in_queue_factor" mapstructure:"patch_time_in_queue_factor"`
CommitQueueFactor int64 `bson:"commit_queue_factor" json:"commit_queue_factor" mapstructure:"commit_queue_factor"`
MainlineTimeInQueueFactor int64 `bson:"mainline_time_in_queue_factor" json:"mainline_time_in_queue_factor" mapstructure:"mainline_time_in_queue_factor"`
ExpectedRuntimeFactor int64 `bson:"expected_runtime_factor" json:"expected_runtime_factor" mapstructure:"expected_runtime_factor"`
GenerateTaskFactor int64 `bson:"generate_task_factor" json:"generate_task_factor" mapstructure:"generate_task_factor"`
NumDependentsFactor float64 `bson:"num_dependents_factor" json:"num_dependents_factor" mapstructure:"num_dependents_factor"`
StepbackTaskFactor int64 `bson:"stepback_task_factor" json:"stepback_task_factor" mapstructure:"stepback_task_factor"`
}
func (c *SchedulerConfig) SectionId() string { return "scheduler" }
func (c *SchedulerConfig) Get(ctx context.Context) error {
return getConfigSection(ctx, c)
}
func (c *SchedulerConfig) Set(ctx context.Context) error {
return errors.Wrapf(setConfigSection(ctx, c.SectionId(), bson.M{
"$set": bson.M{
"task_finder": c.TaskFinder,
"host_allocator": c.HostAllocator,
"host_allocator_rounding_rule": c.HostAllocatorRoundingRule,
"host_allocator_feedback_rule": c.HostAllocatorFeedbackRule,
"hosts_overallocated_rule": c.HostsOverallocatedRule,
"free_host_fraction": c.FutureHostFraction,
"cache_duration_seconds": c.CacheDurationSeconds,
"planner": c.Planner,
"target_time_seconds": c.TargetTimeSeconds,
"acceptable_host_idle_time_seconds": c.AcceptableHostIdleTimeSeconds,
"group_versions": c.GroupVersions,
"patch_zipper_factor": c.PatchFactor,
"patch_time_in_queue_factor": c.PatchTimeInQueueFactor,
"commit_queue_factor": c.CommitQueueFactor,
"mainline_time_in_queue_factor": c.MainlineTimeInQueueFactor,
"expected_runtime_factor": c.ExpectedRuntimeFactor,
"generate_task_factor": c.GenerateTaskFactor,
"num_dependents_factor": c.NumDependentsFactor,
"stepback_task_factor": c.StepbackTaskFactor,
}}), "updating config section '%s'", c.SectionId(),
)
}
func (c *SchedulerConfig) ValidateAndDefault() error {
if c.TaskFinder == "" {
// default to legacy
c.TaskFinder = FinderVersionLegacy
}
if !utility.StringSliceContains(ValidTaskFinderVersions, c.TaskFinder) {
return errors.Errorf("supported task finders are %s; %s is not supported",
ValidTaskFinderVersions, c.TaskFinder)
}
if c.HostAllocator == "" {
// default to "utilization"
c.HostAllocator = HostAllocatorUtilization
}
if !utility.StringSliceContains(ValidHostAllocators, c.HostAllocator) {
return errors.Errorf("supported host allocators are %s; %s is not supported",
ValidHostAllocators, c.HostAllocator)
}
if c.HostAllocatorRoundingRule == "" {
c.HostAllocatorRoundingRule = HostAllocatorRoundDown
}
if !utility.StringSliceContains(ValidDefaultHostAllocatorRoundingRules, c.HostAllocatorRoundingRule) {
return errors.Errorf("supported host allocator rounding rules are %s; %s is not supported",
ValidDefaultHostAllocatorRoundingRules, c.HostAllocatorRoundingRule)
}
if c.HostAllocatorFeedbackRule == "" {
c.HostAllocatorFeedbackRule = HostAllocatorNoFeedback
}
if !utility.StringSliceContains(ValidDefaultHostAllocatorFeedbackRules, c.HostAllocatorFeedbackRule) {
return errors.Errorf("supported host allocator feedback rules are %s; %s is not supported",
ValidDefaultHostAllocatorFeedbackRules, c.HostAllocatorFeedbackRule)
}
if c.HostsOverallocatedRule == "" {
c.HostsOverallocatedRule = HostsOverallocatedIgnore
}
if !utility.StringSliceContains(ValidDefaultHostsOverallocatedRules, c.HostsOverallocatedRule) {
return errors.Errorf("supported hosts overallocation handling rules are %s; %s is not supported",
ValidDefaultHostsOverallocatedRules, c.HostsOverallocatedRule)
}
if c.FutureHostFraction < 0 || c.FutureHostFraction > 1 {
// traditional default
c.FutureHostFraction = .4
}
if c.CacheDurationSeconds > 600 {
return errors.New("cache duration seconds cannot be greater that 600 seconds (10 minutes)")
}
if c.CacheDurationSeconds <= 0 {
c.CacheDurationSeconds = 20
}
if c.Planner == "" {
// default to 'legacy'
c.Planner = PlannerVersionLegacy
}
if !utility.StringSliceContains(ValidTaskPlannerVersions, c.Planner) {
return errors.Errorf("supported planners are %s; %s is not supported",
ValidTaskPlannerVersions, c.Planner)
}
if c.TargetTimeSeconds < 0 {
return errors.New("target time seconds cannot be a negative value")
}
if c.AcceptableHostIdleTimeSeconds < 0 {
return errors.New("acceptable host idle time seconds cannot be a negative value")
}
if c.PatchFactor < 0 || c.PatchFactor > 100 {
return errors.New("patch factor must be between 0 and 100")
}
if c.PatchTimeInQueueFactor < 0 || c.PatchTimeInQueueFactor > 100 {
return errors.New("patch time in queue factor must be between 0 and 100")
}
if c.CommitQueueFactor < 0 || c.CommitQueueFactor > 100 {
return errors.New("commit queue factor must be between 0 and 100")
}
if c.MainlineTimeInQueueFactor < 0 || c.MainlineTimeInQueueFactor > 100 {
return errors.New("mainline time in queue factor must be between 0 and 100")
}
if c.ExpectedRuntimeFactor < 0 || c.ExpectedRuntimeFactor > 100 {
return errors.New("expected runtime factor must be between 0 and 100")
}
if c.GenerateTaskFactor < 0 || c.GenerateTaskFactor > 100 {
return errors.New("generate task factor must be between 0 and 100")
}
if c.NumDependentsFactor < 0 || c.NumDependentsFactor > 100 {
return errors.New("num dependents factor must be between 0 and 100")
}
if c.StepbackTaskFactor < 0 || c.StepbackTaskFactor > 100 {
return errors.New("stepback task factor must be between 0 and 100")
}
return nil
}