...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package main
17
18 import (
19 "context"
20 "flag"
21 stdlog "log"
22 "os"
23
24 fxlogr "github.com/chaos-mesh/fx-logr"
25 _ "github.com/jinzhu/gorm/dialects/mssql"
26 _ "github.com/jinzhu/gorm/dialects/mysql"
27 _ "github.com/jinzhu/gorm/dialects/postgres"
28 _ "github.com/jinzhu/gorm/dialects/sqlite"
29 "go.uber.org/fx"
30 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
31 ctrl "sigs.k8s.io/controller-runtime"
32
33 "github.com/chaos-mesh/chaos-mesh/pkg/config"
34 "github.com/chaos-mesh/chaos-mesh/pkg/dashboard/apiserver"
35 "github.com/chaos-mesh/chaos-mesh/pkg/dashboard/collector"
36 "github.com/chaos-mesh/chaos-mesh/pkg/dashboard/store"
37 "github.com/chaos-mesh/chaos-mesh/pkg/dashboard/ttlcontroller"
38 "github.com/chaos-mesh/chaos-mesh/pkg/log"
39 "github.com/chaos-mesh/chaos-mesh/pkg/version"
40 )
41
42
43
44
45
46
47
48
49
50
51
52
53 func main() {
54 var printVersion bool
55
56 flag.BoolVar(&printVersion, "version", false, "print version information and exit")
57 flag.Parse()
58
59 version.PrintVersionInfo("Chaos Dashboard")
60 if printVersion {
61 os.Exit(0)
62 }
63
64 rootLogger, err := log.NewDefaultZapLogger()
65 if err != nil {
66 stdlog.Fatal("failed to create root logger", err)
67 }
68
69 ctrl.SetLogger(rootLogger)
70 mainLog := rootLogger.WithName("main")
71 fxLogger := rootLogger.WithName("fx")
72
73 dashboardConfig, err := config.GetChaosDashboardEnv()
74 if err != nil {
75 mainLog.Error(err, "invalid ChaosDashboardConfig")
76 os.Exit(1)
77 }
78 dashboardConfig.Version = version.Get().GitVersion
79
80 persistTTLConfigParsed, err := dashboardConfig.PersistTTL.Parse()
81 if err != nil {
82 mainLog.Error(err, "invalid PersistTTLConfig")
83 os.Exit(1)
84 }
85
86 controllerRuntimeSignalHandlerContext := ctrl.SetupSignalHandler()
87 app := fx.New(
88 fx.WithLogger(fxlogr.WithLogr(&fxLogger)),
89 fx.Supply(rootLogger),
90 fx.Provide(
91 func() (context.Context, *config.ChaosDashboardConfig, *config.TTLConfig) {
92 return controllerRuntimeSignalHandlerContext, dashboardConfig, persistTTLConfigParsed
93 },
94 store.Bootstrap,
95 collector.Bootstrap,
96 ttlcontroller.Bootstrap,
97 ),
98 store.Module,
99 apiserver.Module,
100 fx.Invoke(collector.Register),
101 fx.Invoke(ttlcontroller.Register),
102 )
103
104 app.Run()
105 }
106