/
main.go
60 lines (49 loc) · 1.67 KB
/
main.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
package main
import (
"flag"
"fmt"
"os"
"github.com/SotirisAlfonsos/chaos-master/config"
_ "github.com/SotirisAlfonsos/chaos-master/docs"
"github.com/SotirisAlfonsos/chaos-master/healthcheck"
"github.com/SotirisAlfonsos/chaos-master/pkg/chaoslogger"
"github.com/SotirisAlfonsos/chaos-master/pkg/network"
"github.com/SotirisAlfonsos/chaos-master/web/api"
"github.com/go-kit/kit/log/level"
)
// @title Chaos Master API
// @version 1.0
// @description This is the chaos master API.
// @host localhost:8090
// @BasePath /chaos/api/v1
func main() {
configFile := flag.String("config.file", "", "the file that contains the configuration for the chaos master")
debugLevel := flag.String("debug.level", "info", "the debug level for the chaos master")
flag.Parse()
loggers := createLoggers(*debugLevel)
conf, err := config.GetConfig(*configFile)
if err != nil {
_ = level.Error(loggers.ErrLogger).Log("err", err)
os.Exit(1)
}
connections := network.GetConnectionPool(conf, loggers)
jobMap := conf.GetJobMap(loggers)
var healthChecker *healthcheck.HealthChecker
if conf.HealthCheck.Active {
healthChecker := healthcheck.Register(connections, loggers)
healthChecker.Start(conf.HealthCheck.Report)
}
options := api.NewAPIOptions(conf.APIOptions, jobMap, connections, loggers)
restAPI := api.NewRestAPI(options, healthChecker)
restAPI.RunAPIController()
}
func createLoggers(debugLevel string) chaoslogger.Loggers {
allowLevel := &chaoslogger.AllowedLevel{}
if err := allowLevel.Set(debugLevel); err != nil {
fmt.Printf("%v", err)
}
return chaoslogger.Loggers{
OutLogger: chaoslogger.New(allowLevel, os.Stdout),
ErrLogger: chaoslogger.New(allowLevel, os.Stderr),
}
}