forked from evergreen-ci/evergreen
/
globals.go
463 lines (378 loc) · 12 KB
/
globals.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
package evergreen
import (
"os"
"time"
"github.com/mongodb/grip"
"github.com/pkg/errors"
)
const (
User = "mci"
GithubPatchUser = "github_pull_request"
HostRunning = "running"
HostTerminated = "terminated"
HostUninitialized = "initializing"
HostBuilding = "building"
HostStarting = "starting"
HostProvisioning = "provisioning"
HostProvisionFailed = "provision failed"
HostQuarantined = "quarantined"
HostDecommissioned = "decommissioned"
HostExternalUserName = "external"
HostStatusSuccess = "success"
HostStatusFailed = "failed"
// Task Statuses used in the database models
// TaskInactive is not assigned to any new tasks, but can be found
// in the database and is used in the UI.
TaskInactive = "inactive"
// TaskUnstarted is assigned to a display task after cleaning up one of
// its execution tasks. This indicates that the display task is
// pending a rerun
TaskUnstarted = "unstarted"
// TaskUndispatched indicates either
// 1. a task is not scheduled to run (when Task.Activated == false)
// 2. a task is scheduled to run (when Task.Activated == true)
TaskUndispatched = "undispatched"
// TaskStarted indicates a task is running on an agent
TaskStarted = "started"
// TaskDispatched indicates that an agent has received the task, but
// the agent has not yet told Evergreen that it's running the task
TaskDispatched = "dispatched"
// The task statuses below indicate that a task has finished.
TaskSucceeded = "success"
// These statuses indicate the types of failures that are stored in
// Task.Status field, build TaskCache and TaskEndDetails.
TaskFailed = "failed"
TaskSystemFailed = "system-failed"
TaskTestTimedOut = "test-timed-out"
TaskSetupFailed = "setup-failed"
TaskStatusBlocked = "blocked"
TaskStatusPending = "pending"
// Task Command Types
CommandTypeTest = "test"
CommandTypeSystem = "system"
CommandTypeSetup = "setup"
// Task Statuses that are currently used only by the UI, and in tests
// (these may be used in old tasks)
TaskSystemUnresponse = "system-unresponsive"
TaskSystemTimedOut = "system-timed-out"
TaskTimedOut = "task-timed-out"
// TaskConflict is used only in communication with the Agent
TaskConflict = "task-conflict"
TestFailedStatus = "fail"
TestSilentlyFailedStatus = "silentfail"
TestSkippedStatus = "skip"
TestSucceededStatus = "pass"
BuildStarted = "started"
BuildCreated = "created"
BuildFailed = "failed"
BuildSucceeded = "success"
VersionStarted = "started"
VersionCreated = "created"
VersionFailed = "failed"
VersionSucceeded = "success"
PatchCreated = "created"
PatchStarted = "started"
PatchSucceeded = "succeeded"
PatchFailed = "failed"
PushLogPushing = "pushing"
PushLogSuccess = "success"
HostTypeStatic = "static"
PushStage = "push"
MergeTestStarted = "started"
MergeTestSucceeded = "succeeded"
MergeTestFailed = "failed"
// maximum task (zero based) execution number
MaxTaskExecution = 3
// maximum task priority
MaxTaskPriority = 100
// LogMessage struct versions
LogmessageFormatTimestamp = 1
LogmessageCurrentVersion = LogmessageFormatTimestamp
EvergreenHome = "EVGHOME"
MongodbUrl = "MONGO_URL"
// Special logging output targets
LocalLoggingOverride = "LOCAL"
StandardOutputLoggingOverride = "STDOUT"
DefaultTaskActivator = ""
StepbackTaskActivator = "stepback"
APIServerTaskActivator = "apiserver"
// Restart Types
RestartVersions = "versions"
RestartTasks = "tasks"
RestRoutePrefix = "rest"
APIRoutePrefix = "api"
AgentAPIVersion = 2
APIRoutePrefixV2 = "/rest/v2"
AgentMonitorTag = "agent-monitor"
DegradedLoggingPercent = 10
SetupScriptName = "setup.sh"
TempSetupScriptName = "setup-temp.sh"
TeardownScriptName = "teardown.sh"
RoutePaginatorNextPageHeaderKey = "Link"
PlannerVersionLegacy = "legacy"
PlannerVersionRevised = "revised"
PlannerVersionTunable = "tunable"
// maximum turnaround we want to maintain for all hosts for a given distro
MaxDurationPerDistroHost = 30 * time.Minute
MaxDurationPerDistroHostWithContainers = 2 * time.Minute
FinderVersionLegacy = "legacy"
FinderVersionParallel = "parallel"
FinderVersionPipeline = "pipeline"
FinderVersionAlternate = "alternate"
HostAllocatorDuration = "duration"
HostAllocatorDeficit = "deficit"
HostAllocatorUtilization = "utilization"
TaskOrderingNotDeclared = ""
TaskOrderingInterleave = "interleave"
TaskOrderingMainlineFirst = "mainlinefirst"
TaskOrderingPatchFirst = "patchfirst"
CommitQueueAlias = "__commit_queue"
MergeTaskVariant = "commit-queue-merge"
MergeTaskName = "merge-patch"
MergeTaskGroup = "merge-task-group"
MaxTeardownGroupTimeoutSecs = 30 * 60
DefaultJasperPort = 2385
GlobalGitHubTokenExpansion = "global_github_oauth_token"
)
func IsFinishedTaskStatus(status string) bool {
if status == TaskSucceeded ||
IsFailedTaskStatus(status) {
return true
}
return false
}
func IsFailedTaskStatus(status string) bool {
return status == TaskFailed ||
status == TaskSystemFailed ||
status == TaskSystemTimedOut ||
status == TaskSystemUnresponse ||
status == TaskTestTimedOut ||
status == TaskSetupFailed
}
// evergreen package names
const (
UIPackage = "EVERGREEN_UI"
RESTV2Package = "EVERGREEN_REST_V2"
MonitorPackage = "EVERGREEN_MONITOR"
)
const (
AuthTokenCookie = "mci-token"
TaskHeader = "Task-Id"
TaskSecretHeader = "Task-Secret"
HostHeader = "Host-Id"
HostSecretHeader = "Host-Secret"
ContentTypeHeader = "Content-Type"
ContentTypeValue = "application/json"
ContentLengthHeader = "Content-Length"
APIUserHeader = "Api-User"
APIKeyHeader = "Api-Key"
)
// cloud provider related constants
const (
ProviderNameEc2Auto = "ec2-auto"
ProviderNameEc2OnDemand = "ec2-ondemand"
ProviderNameEc2Spot = "ec2-spot"
ProviderNameEc2Fleet = "ec2-fleet"
ProviderNameDocker = "docker"
ProviderNameDockerMock = "docker-mock"
ProviderNameGce = "gce"
ProviderNameStatic = "static"
ProviderNameOpenstack = "openstack"
ProviderNameVsphere = "vsphere"
ProviderNameMock = "mock"
// Default EC2 region where hosts should be spawned
DefaultEC2Region = "us-east-1"
)
var (
// Providers where hosts can be created and terminated automatically.
ProviderSpawnable = []string{
ProviderNameDocker,
ProviderNameEc2OnDemand,
ProviderNameEc2Spot,
ProviderNameEc2Auto,
ProviderNameEc2Fleet,
ProviderNameGce,
ProviderNameOpenstack,
ProviderNameVsphere,
ProviderNameMock,
}
ProviderContainer = []string{
ProviderNameDocker,
}
SystemVersionRequesterTypes = []string{
RepotrackerVersionRequester,
TriggerRequester,
}
)
const (
DefaultServiceConfigurationFileName = "/etc/mci_settings.yml"
DefaultDatabaseUrl = "mongodb://localhost:27017"
DefaultDatabaseName = "mci"
DefaultDatabaseWriteMode = "majority"
// database and config directory, set to the testing version by default for safety
NotificationsFile = "mci-notifications.yml"
ClientDirectory = "clients"
// version requester types
PatchVersionRequester = "patch_request"
GithubPRRequester = "github_pull_request"
RepotrackerVersionRequester = "gitter_request"
TriggerRequester = "trigger_request"
MergeTestRequester = "merge_test"
AdHocRequester = "ad_hoc"
)
const (
GenerateTasksCommandName = "generate.tasks"
CreateHostCommandName = "host.create"
)
type SenderKey int
const (
SenderGithubStatus = SenderKey(iota)
SenderEvergreenWebhook
SenderSlack
SenderJIRAIssue
SenderJIRAComment
SenderEmail
SenderGithubMerge
SenderCommitQueueDequeue
)
func (k SenderKey) Validate() error {
switch k {
case SenderGithubStatus, SenderEvergreenWebhook, SenderSlack, SenderJIRAComment, SenderJIRAIssue,
SenderEmail, SenderGithubMerge, SenderCommitQueueDequeue:
return nil
default:
return errors.New("invalid sender defined")
}
}
func (k SenderKey) String() string {
switch k {
case SenderGithubStatus:
return "github-status"
case SenderEmail:
return "email"
case SenderEvergreenWebhook:
return "webhook"
case SenderSlack:
return "slack"
case SenderJIRAComment:
return "jira-comment"
case SenderJIRAIssue:
return "jira-issue"
case SenderGithubMerge:
return "github-merge"
case SenderCommitQueueDequeue:
return "commit-queue-dequeue"
default:
return "<error:unkwown>"
}
}
const (
defaultLogBufferingDuration = 20
defaultAmboyPoolSize = 2
defaultAmboyLocalStorageSize = 1024
defaultAmboyQueueName = "evg.service"
defaultSingleAmboyQueueName = "evg.single"
defaultAmboyDBName = "amboy"
defaultGroupWorkers = 1
defaultGroupBackgroundCreateFrequencyMinutes = 10
defaultGroupPruneFrequencyMinutes = 10
defaultGroupTTLMinutes = 1
maxNotificationsPerSecond = 100
EnableAmboyRemoteReporting = false
)
// NameTimeFormat is the format in which to log times like instance start time.
const NameTimeFormat = "20060102150405"
var (
PatchRequesters = []string{
PatchVersionRequester,
GithubPRRequester,
MergeTestRequester,
}
// UpHostStatus is a list of all host statuses that are considered up.
UpHostStatus = []string{
HostRunning,
HostUninitialized,
HostBuilding,
HostStarting,
HostProvisioning,
HostProvisionFailed,
}
// DownHostStatus is a list of all host statuses that are considered down.
DownHostStatus = []string{
HostTerminated,
HostQuarantined,
HostDecommissioned,
}
// NotRunningStatus is a list of host statuses from before the host starts running.
NotRunningStatus = []string{
HostUninitialized,
HostBuilding,
HostProvisioning,
HostStarting,
}
// Hosts in "initializing" status aren't actually running yet:
// they're just intents, so this list omits that value.
ActiveStatus = []string{
HostRunning,
HostStarting,
HostProvisioning,
HostProvisionFailed,
}
// Set of host status values that can be user set via the API
ValidUserSetStatus = []string{
HostRunning,
HostTerminated,
HostQuarantined,
HostDecommissioned,
}
// Set of valid PlannerSettings.Version strings that can be user set via the API
ValidPlannerVersions = []string{
PlannerVersionLegacy,
PlannerVersionRevised,
PlannerVersionTunable,
}
// Set of valid FinderSettings.Version strings that can be user set via the API
ValidFinderVersions = []string{
FinderVersionLegacy,
FinderVersionAlternate,
FinderVersionParallel,
FinderVersionPipeline,
}
// Set of valid Host Allocators types
ValidHostAllocators = []string{
HostAllocatorDuration,
HostAllocatorDeficit,
HostAllocatorUtilization,
}
// Set of valid Task Ordering options that can be user set via the API
ValidTaskOrderings = []string{
TaskOrderingNotDeclared,
TaskOrderingInterleave,
TaskOrderingMainlineFirst,
TaskOrderingPatchFirst,
}
// constant arrays for db update logic
AbortableStatuses = []string{TaskStarted, TaskDispatched}
CompletedStatuses = []string{TaskSucceeded, TaskFailed}
ValidCommandTypes = []string{CommandTypeSetup, CommandTypeSystem, CommandTypeTest}
)
// FindEvergreenHome finds the directory of the EVGHOME environment variable.
func FindEvergreenHome() string {
// check if env var is set
root := os.Getenv(EvergreenHome)
if len(root) > 0 {
return root
}
grip.Errorf("%s is unset", EvergreenHome)
return ""
}
// IsSystemActivator returns true when the task activator is Evergreen.
func IsSystemActivator(caller string) bool {
return caller == DefaultTaskActivator || caller == APIServerTaskActivator
}
func IsPatchRequester(requester string) bool {
return requester == PatchVersionRequester || requester == GithubPRRequester || requester == MergeTestRequester
}
func IsGitHubPatchRequester(requester string) bool {
return requester == GithubPRRequester || requester == MergeTestRequester
}