-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathorchestrator.go
636 lines (588 loc) · 20.6 KB
/
orchestrator.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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"
"github.com/akamensky/argparse"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
cwtypes "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
"github.com/aws/aws-sdk-go-v2/service/ec2"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/aws-sdk-go-v2/service/eventbridge"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/gorilla/mux"
"github.com/lzap/cloudwatchwriter2"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog/pkgerrors"
"github.com/spf13/viper"
)
const (
MaxRetryAttempts = 5
RebootTimerDuration = 5 * time.Minute
CheckCountTimerDuration = 15 * time.Second
RefreshInstanceDataTimerDuration = 5 * time.Minute
CollectMetricsTimerDuration = time.Second
ReportMetricsTimerDuration = time.Minute
NotifierRuleNameSetting = "notifier_rule_name"
CountParameterNameSetting = "%s_count_parameter_name"
LaunchTemplateIdSetting = "%s_launch_template_id"
QueueNotEmptyAlarmNameSetting = "%s_queue_not_empty_alarm_name"
CloudwatchMetricsNamespace = "CaseHarvester"
CloudwatchLogGroupName = "caseharvester_orchestrator"
)
type Component string
const (
SpiderComponent Component = "spider"
ScraperComponent Component = "scraper"
)
var AllComponents []Component = []Component{SpiderComponent, ScraperComponent}
type Orchestrator struct {
environment string
ec2Client *ec2.Client
ebClient *eventbridge.Client
ssmClient *ssm.Client
cwClient *cloudwatch.Client
}
type InstanceState struct {
instanceId string
component Component
state ec2types.InstanceStateName
rebootTimer *time.Timer
}
type InstanceUpdate struct {
instanceId string
state ec2types.InstanceStateName
}
type QueueUpdate struct {
component Component
queueHasItems bool
}
type Metric struct {
component Component
timestamp time.Time
counts map[ec2types.InstanceStateName]int
}
func NewOrchestrator(cfg aws.Config, environment string) *Orchestrator {
return &Orchestrator{
environment: environment,
ec2Client: ec2.NewFromConfig(cfg),
ebClient: eventbridge.NewFromConfig(cfg),
ssmClient: ssm.NewFromConfig(cfg),
cwClient: cloudwatch.NewFromConfig(cfg),
}
}
func (orchestrator *Orchestrator) Start(done chan bool) {
// State variables
instances := make(map[string]*InstanceState)
instanceIds := make(map[Component][]string)
queueHasItems := make(map[Component]bool)
metrics := make(map[Component][]Metric)
updatesChan := make(chan []InstanceUpdate, 1000)
queueUpdateChan := make(chan QueueUpdate)
server := orchestrator.setupHttpHandlers(updatesChan, queueUpdateChan)
// Recover from panics: log error and cleanup
defer func() {
if r := recover(); r != nil {
log.Error().Err(fmt.Errorf("%v", r)).Msg("Caught panic")
orchestrator.cleanup(instances, server)
}
}()
// Check queue_not_empty_alarm states
log.Info().Msg("Checking current alarm states")
for _, component := range AllComponents {
alarmName := viper.GetString(fmt.Sprintf(QueueNotEmptyAlarmNameSetting, component))
response, err := orchestrator.cwClient.DescribeAlarms(context.TODO(), &cloudwatch.DescribeAlarmsInput{
AlarmNames: []string{alarmName},
})
if err != nil {
log.Fatal().Err(err).Msgf("Failed to get alarm state for %s", alarmName)
}
alarm := response.MetricAlarms[0]
if alarm.StateValue == cwtypes.StateValueAlarm {
queueHasItems[component] = true
}
}
// Start HTTP server
log.Info().Msg("Starting HTTP update handlers")
go server.ListenAndServe()
// Enable queue_not_empty_alarm actions and instance state change notification rule
go orchestrator.enableTriggers()
// Do initial check of desired instance counts so we can spin them up
log.Info().Msg("Checking initial count parameters")
newInstancesChan := make(chan []*InstanceState, 2)
rebootChan := make(chan string)
go orchestrator.checkCountParams(instanceIds, instances, newInstancesChan, rebootChan)
// Set tickers
collectTicker := time.NewTicker(CollectMetricsTimerDuration)
reportTicker := time.NewTicker(ReportMetricsTimerDuration)
checkCountTicker := time.NewTicker(CheckCountTimerDuration)
refreshTicker := time.NewTicker(RefreshInstanceDataTimerDuration)
// Main event loop
metricsChan := make(chan []Metric)
for {
select {
case update := <-queueUpdateChan:
if update.queueHasItems {
log.Info().Msgf("%s queue has items available", strings.Title(string(update.component)))
} else {
log.Info().Msgf("%s queue is empty", strings.Title(string(update.component)))
}
queueHasItems[update.component] = update.queueHasItems
case newInstances := <-newInstancesChan:
for _, instance := range newInstances {
instances[instance.instanceId] = instance
instanceIds[instance.component] = append(instanceIds[instance.component], instance.instanceId)
}
case instanceId := <-rebootChan:
instance := instances[instanceId]
if instance.state == ec2types.InstanceStateNamePending || instance.state == ec2types.InstanceStateNameRunning {
log.Info().Str("instanceId", instanceId).Msg("Reboot timer triggered, stopping instance")
go orchestrator.stopInstance(instanceId)
}
case updates := <-updatesChan:
for _, update := range updates {
instance, present := instances[update.instanceId]
if present {
instance.state = update.state
log.Debug().Str("instanceId", instance.instanceId).Str("state", string(update.state)).Send()
// Start instance if stopped and queue not empty
if update.state == ec2types.InstanceStateNameStopped && queueHasItems[instance.component] {
log.Info().Str("instanceId", instance.instanceId).Msg("Starting instance")
go orchestrator.startInstance(instance.instanceId)
// Set new reboot timer
instance.rebootTimer.Stop()
instance.rebootTimer = time.AfterFunc(RebootTimerDuration, func() {
rebootChan <- instance.instanceId
})
} else if update.state == ec2types.InstanceStateNameTerminated {
// Remove terminated instances
log.Info().Str("instanceId", instance.instanceId).Msg("Removing terminated instance")
for i, instanceId := range instanceIds[instance.component] {
if instanceId == instance.instanceId {
instanceIds[instance.component] = append(
instanceIds[instance.component][:i],
instanceIds[instance.component][i+1:]...,
)
}
}
instance.rebootTimer.Stop()
delete(instances, instance.instanceId)
}
}
}
case newMetrics := <-metricsChan:
for _, metric := range newMetrics {
metrics[metric.component] = append(metrics[metric.component], metric)
}
case <-checkCountTicker.C:
// log.Debug().Msg("Checking orchestrator count parameters")
go orchestrator.checkCountParams(instanceIds, instances, newInstancesChan, rebootChan)
case <-refreshTicker.C:
log.Debug().Msg("Refreshing instance data")
go orchestrator.refreshInstanceData(instances, updatesChan)
case <-collectTicker.C:
go orchestrator.collectMetrics(instanceIds, instances, metricsChan)
case <-reportTicker.C:
log.Debug().Msgf("Reporting %d metrics", len(metrics[SpiderComponent])+len(metrics[ScraperComponent]))
go orchestrator.reportMetrics(metrics)
metrics = make(map[Component][]Metric)
case <-done:
log.Info().Msg("Received signal to shut down orchestrator")
orchestrator.cleanup(instances, server)
done <- true
return
}
}
}
func (orchestrator *Orchestrator) reportMetrics(metrics map[Component][]Metric) {
var dat []cwtypes.MetricDatum
for component, metrics := range metrics {
dimensions := []cwtypes.Dimension{
{
Name: aws.String("Environment"),
Value: aws.String(orchestrator.environment),
},
{
Name: aws.String("Component"),
Value: aws.String(string(component)),
},
}
for _, metric := range metrics {
for _, state := range []ec2types.InstanceStateName{
ec2types.InstanceStateNamePending,
ec2types.InstanceStateNameRunning,
ec2types.InstanceStateNameStopping,
ec2types.InstanceStateNameStopped,
ec2types.InstanceStateNameShuttingDown,
ec2types.InstanceStateNameTerminated,
} {
dat = append(dat, cwtypes.MetricDatum{
MetricName: aws.String(fmt.Sprintf("%sInstances", strings.Title(string(state)))),
Dimensions: dimensions,
Timestamp: aws.Time(metric.timestamp),
Value: aws.Float64(float64(metric.counts[state])),
StorageResolution: aws.Int32(1),
})
}
}
}
_, err := orchestrator.cwClient.PutMetricData(context.TODO(), &cloudwatch.PutMetricDataInput{
MetricData: dat,
Namespace: aws.String(CloudwatchMetricsNamespace),
})
if err != nil {
log.Error().Err(err).Msg("Failed to report metrics")
}
}
func (orchestrator *Orchestrator) collectMetrics(
instanceIds map[Component][]string,
instances map[string]*InstanceState,
metricsChan chan<- []Metric,
) {
// Round to the nearest second
metricTime := time.Now().Round(time.Second)
var metrics []Metric
for _, component := range AllComponents {
metric := Metric{
component: component,
timestamp: metricTime,
counts: make(map[ec2types.InstanceStateName]int),
}
for _, instanceId := range instanceIds[component] {
metric.counts[instances[instanceId].state] += 1
}
metrics = append(metrics, metric)
}
metricsChan <- metrics
}
func (orchestrator *Orchestrator) enableTriggers() {
// Enable queue_not_empty_alarm actions to notify us whether queue has items or not
for _, component := range AllComponents {
alarmName := viper.GetString(fmt.Sprintf(QueueNotEmptyAlarmNameSetting, component))
log.Info().Msgf("Enabling alarm actions for %s", alarmName)
_, err := orchestrator.cwClient.EnableAlarmActions(context.TODO(), &cloudwatch.EnableAlarmActionsInput{
AlarmNames: []string{alarmName},
})
if err != nil {
log.Fatal().Err(err).Msgf("Failed to enable alarm actions for %s", alarmName)
}
}
// Enable eventbridge rule to notify us of EC2 instance state changes
ruleName := viper.GetString(NotifierRuleNameSetting)
if ruleName == "" {
log.Fatal().Msgf("Cannot find setting %s", NotifierRuleNameSetting)
}
log.Info().Msgf("Enabling EventBridge rule %s", ruleName)
_, err := orchestrator.ebClient.EnableRule(context.TODO(), &eventbridge.EnableRuleInput{
Name: aws.String(ruleName),
})
if err != nil {
log.Fatal().Err(err).Msg("Failed to enable EventBridge rule")
}
}
func (orchestrator *Orchestrator) cleanup(instances map[string]*InstanceState, server *http.Server) {
var instanceIds []string
for instanceId := range instances {
instanceIds = append(instanceIds, instanceId)
}
// Terminate all instances
log.Info().Msgf("Terminating %d instances", len(instanceIds))
_, err := orchestrator.ec2Client.TerminateInstances(context.TODO(), &ec2.TerminateInstancesInput{
InstanceIds: instanceIds,
})
if err != nil {
log.Error().Err(err).Msg("Error terminating instances")
}
// Disable eventbridge rule
ruleName := viper.GetString(NotifierRuleNameSetting)
log.Info().Msgf("Disabling EventBridge rule %s", ruleName)
_, err = orchestrator.ebClient.DisableRule(context.TODO(), &eventbridge.DisableRuleInput{
Name: aws.String(ruleName),
})
if err != nil {
log.Error().Err(err).Msg("Error disabling EventBridge rule")
}
// Disable queue_not_empty_alarm actions
for _, component := range AllComponents {
alarmName := viper.GetString(fmt.Sprintf(QueueNotEmptyAlarmNameSetting, component))
log.Info().Msgf("Disabling alarm actions for %s", alarmName)
_, err := orchestrator.cwClient.DisableAlarmActions(context.TODO(), &cloudwatch.DisableAlarmActionsInput{
AlarmNames: []string{alarmName},
})
if err != nil {
log.Error().Err(err).Msgf("Error disabling alarm actions for %s", alarmName)
}
}
// Shutdown http server
log.Info().Msg("Shutting down HTTP server")
if err := server.Shutdown(context.TODO()); err != nil {
log.Error().Err(err).Msg("Error shutting down HTTP server")
}
}
func (orchestrator *Orchestrator) checkCountParams(
instanceIds map[Component][]string,
instances map[string]*InstanceState,
newInstancesChan chan<- []*InstanceState,
rebootChan chan<- string,
) {
for _, component := range AllComponents {
countParamName := viper.GetString(fmt.Sprintf(CountParameterNameSetting, component))
response, err := orchestrator.ssmClient.GetParameter(context.TODO(), &ssm.GetParameterInput{
Name: aws.String(countParamName),
})
if err != nil {
log.Error().Err(err).Msgf("Failed to get %s count parameter", component)
continue
}
valStr := aws.ToString(response.Parameter.Value)
count, err := strconv.Atoi(valStr)
if err != nil {
log.Error().Err(err).Msgf("Invalid count parameter for %s: %s", component, valStr)
continue
}
diff := count - len(instanceIds[component])
if diff > 0 {
log.Info().Msgf("Launching %d %s instances", diff, component)
launchTemplateId := viper.GetString(fmt.Sprintf(LaunchTemplateIdSetting, component))
go orchestrator.launchInstances(component, launchTemplateId, diff, newInstancesChan, rebootChan)
} else if diff < 0 {
log.Info().Msgf("Terminating %d %s instances", -diff, component)
go orchestrator.terminateInstances(instances, component, -diff)
}
}
}
func (orchestrator *Orchestrator) launchInstances(
component Component,
launchTemplateId string,
count int,
newInstancesChan chan<- []*InstanceState,
rebootChan chan<- string,
) {
tags := []ec2types.Tag{
{
Key: aws.String("Name"),
Value: aws.String(fmt.Sprintf("Case Harvester %s worker", component)),
},
}
response, err := orchestrator.ec2Client.RunInstances(context.TODO(), &ec2.RunInstancesInput{
MaxCount: aws.Int32(int32(count)),
MinCount: aws.Int32(int32(count)),
LaunchTemplate: &ec2types.LaunchTemplateSpecification{
LaunchTemplateId: aws.String(launchTemplateId),
Version: aws.String("$Latest"),
},
TagSpecifications: []ec2types.TagSpecification{
{
ResourceType: ec2types.ResourceTypeInstance,
Tags: tags,
},
{
ResourceType: ec2types.ResourceTypeVolume,
Tags: tags,
},
{
ResourceType: ec2types.ResourceTypeNetworkInterface,
Tags: tags,
},
},
})
if err != nil {
log.Error().Err(err).Msg("Failed to launch EC2 instances")
return
}
var instances []*InstanceState
for _, newInstance := range response.Instances {
instanceId := aws.ToString(newInstance.InstanceId)
log.Debug().Str("instanceId", instanceId).Str("state", string(newInstance.State.Name)).Msg("Launched instance")
instance := &InstanceState{
instanceId: instanceId,
component: component,
state: newInstance.State.Name,
rebootTimer: time.AfterFunc(RebootTimerDuration, func() {
rebootChan <- instanceId
}),
}
instances = append(instances, instance)
}
newInstancesChan <- instances
}
func (orchestrator *Orchestrator) terminateInstances(instances map[string]*InstanceState, component Component, count int) {
var toTerminate []string
for _, instance := range instances {
if len(toTerminate) < count && instance.component == component {
toTerminate = append(toTerminate, instance.instanceId)
}
}
if len(toTerminate) < count {
log.Warn().Msgf(
"Number of available %s instances (%d) less than requested to terminate (%d).",
component, len(toTerminate), count)
}
_, err := orchestrator.ec2Client.TerminateInstances(context.TODO(), &ec2.TerminateInstancesInput{
InstanceIds: toTerminate,
})
if err != nil {
log.Error().Err(err).Msg("Failed to terminate instances")
}
}
func (orchestrator *Orchestrator) refreshInstanceData(instances map[string]*InstanceState, updatesChan chan<- []InstanceUpdate) {
var instanceIds []string
for instanceId := range instances {
instanceIds = append(instanceIds, instanceId)
}
paginator := ec2.NewDescribeInstancesPaginator(orchestrator.ec2Client, &ec2.DescribeInstancesInput{
InstanceIds: instanceIds,
})
var updates []InstanceUpdate
for paginator.HasMorePages() {
response, err := paginator.NextPage(context.TODO())
if err != nil {
log.Error().Err(err).Msg("Failed to get instance data")
return
}
for _, res := range response.Reservations {
for _, instance := range res.Instances {
updates = append(updates, InstanceUpdate{
instanceId: aws.ToString(instance.InstanceId),
state: instance.State.Name,
})
}
}
}
updatesChan <- updates
}
func (orchestrator *Orchestrator) startInstance(instanceId string) {
response, err := orchestrator.ec2Client.StartInstances(context.TODO(), &ec2.StartInstancesInput{
InstanceIds: []string{instanceId},
})
if err != nil {
log.Error().Err(err).Str("instanceId", instanceId).Msg("Failed to start instance")
return
}
if response.StartingInstances[0].CurrentState.Name != ec2types.InstanceStateNamePending {
log.Warn().Str("instanceId", instanceId).Msgf(
"Instance not in expected pending state: %s", response.StartingInstances[0].CurrentState.Name)
}
}
func (orchestrator *Orchestrator) stopInstance(instanceId string) {
_, err := orchestrator.ec2Client.StopInstances(context.TODO(), &ec2.StopInstancesInput{
InstanceIds: []string{instanceId},
})
if err != nil {
log.Error().Err(err).Str("instanceId", instanceId).Msg("Failed to stop instance")
}
}
func (orchestrator *Orchestrator) setupHttpHandlers(
updatesChan chan<- []InstanceUpdate,
queueUpdateChan chan<- QueueUpdate,
) *http.Server {
router := mux.NewRouter()
for _, state := range []ec2types.InstanceStateName{
ec2types.InstanceStateNamePending,
ec2types.InstanceStateNameRunning,
ec2types.InstanceStateNameStopping,
ec2types.InstanceStateNameStopped,
ec2types.InstanceStateNameShuttingDown,
ec2types.InstanceStateNameTerminated,
} {
router.HandleFunc(fmt.Sprintf("/%s/{instance_id}", state), func(state ec2types.InstanceStateName) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
updatesChan <- []InstanceUpdate{{
instanceId: mux.Vars(r)["instance_id"],
state: state,
}}
}
}(state))
}
for _, component := range AllComponents {
router.HandleFunc(fmt.Sprintf("/%s/empty", component), func(component Component) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
queueUpdateChan <- QueueUpdate{
component: component,
queueHasItems: false,
}
}
}(component))
router.HandleFunc(fmt.Sprintf("/%s/available", component), func(component Component) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
queueUpdateChan <- QueueUpdate{
component: component,
queueHasItems: true,
}
}
}(component))
}
return &http.Server{Addr: "0.0.0.0:80", Handler: router}
}
func main() {
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
log.Logger = log.Output(
zerolog.ConsoleWriter{Out: os.Stdout},
).With().Timestamp().Logger().With().Caller().Logger()
parser := argparse.NewParser("orchestrator",
"Orchestrate Case Harvester spider and scraper EC2 instances")
environment := parser.Selector("e", "environment",
[]string{"production", "development"}, &argparse.Options{
Required: true,
})
cloudwatch := parser.Flag("", "cloudwatch", &argparse.Options{
Help: "Log to Cloudwatch",
})
if err := parser.Parse(os.Args); err != nil {
log.Fatal().Msg(parser.Usage(err))
}
// Load config
log.Info().Msg("Loading configuration")
cwd, err := os.Getwd()
if err != nil {
log.Fatal().Err(err).Msg("Failed to get CWD")
}
viper.SetConfigName(*environment)
viper.SetConfigType("env")
viper.AddConfigPath(filepath.Join(cwd, "env"))
if err := viper.ReadInConfig(); err != nil {
log.Fatal().Err(err).Msg("Error reading config: %w")
}
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion("us-east-1"),
config.WithRetryMaxAttempts(MaxRetryAttempts),
)
if err != nil {
log.Fatal().Err(err).Msg("Failed to load default AWS config")
}
if *cloudwatch {
cwClient := cloudwatchlogs.NewFromConfig(cfg)
cloudwatchWriter, err := cloudwatchwriter2.NewWithClient(
cwClient,
time.Second,
CloudwatchLogGroupName,
time.Now().GoString(),
)
if err != nil {
log.Fatal().Err(err).Msg("Failed to create Cloudwatch writer")
}
log.Logger = zerolog.New(zerolog.MultiLevelWriter(
cloudwatchWriter,
zerolog.ConsoleWriter{Out: os.Stdout}),
).With().Timestamp().Logger().With().Caller().Logger()
}
orchestrator := NewOrchestrator(cfg, *environment)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
done := make(chan bool)
go orchestrator.Start(done)
<-sigs
done <- true
<-done
}