Skip to content

Commit

Permalink
refactor: entrance of chaos dashboard (chaos-mesh#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
g1eny0ung authored Sep 10, 2020
1 parent 194c104 commit 297583e
Show file tree
Hide file tree
Showing 30 changed files with 219 additions and 551 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ ifeq ($(UI),1)
make ui
hack/embed_ui_assets.sh
endif
$(CGO) build -ldflags '$(LDFLAGS)' -tags "${BUILD_TAGS}" -o bin/chaos-dashboard cmd/chaos-dashboard/*.go
$(CGO) build -ldflags "$(LDFLAGS)" -tags "${BUILD_TAGS}" -o bin/chaos-dashboard cmd/chaos-dashboard/*.go

swagger_spec:
hack/generate_swagger_spec.sh
Expand All @@ -126,7 +126,7 @@ yarn_dependencies:

ui: yarn_dependencies
cd ui &&\
REACT_APP_DASHBOARD_API_URL="" yarn build
yarn build

binary: chaosdaemon manager chaosfs chaos-dashboard bin/pause bin/suicide

Expand Down
83 changes: 32 additions & 51 deletions cmd/chaos-dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@
package main

import (
"context"
"flag"
"os"
"time"

"go.uber.org/fx"

_ "github.com/jinzhu/gorm/dialects/sqlite"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/chaos-mesh/chaos-mesh/pkg/apiserver"
"github.com/chaos-mesh/chaos-mesh/pkg/collector"
"github.com/chaos-mesh/chaos-mesh/pkg/config"
"github.com/chaos-mesh/chaos-mesh/pkg/store"
"github.com/chaos-mesh/chaos-mesh/pkg/store/dbstore"
"github.com/chaos-mesh/chaos-mesh/pkg/ttlcontroller"
"github.com/chaos-mesh/chaos-mesh/pkg/version"

_ "github.com/go-sql-driver/mysql"
_ "github.com/jinzhu/gorm/dialects/sqlite"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

var (
Expand All @@ -45,49 +42,45 @@ var (
printVersion bool
)

// @title Chaos Mesh Dashboard API
// @version 0.9
// @description Swagger docs for Chaos Mesh Dashboard. If you encounter any problems with API, please click on the issues link below to report bugs or questions.

// @contact.name Issues
// @contact.url https://github.com/chaos-mesh/chaos-mesh/issues

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @BasePath /api
func main() {
flag.BoolVar(&printVersion, "version", false, "print version information and exit")
flag.Parse()

conf, err := config.EnvironChaosDashboard()
if err != nil {
log.Error(err, "main: invalid configuration")
os.Exit(1)
version.PrintVersionInfo("Chaos Dashboard")
if printVersion {
os.Exit(0)
}

databaseTTLResyncPeriod, err := time.ParseDuration(conf.PersistTTL.SyncPeriod)
if err != nil {
log.Error(err, "main: invalid databaseTTLResyncPeriod")
os.Exit(1)
}
eventTTL, err := time.ParseDuration(conf.PersistTTL.Event)
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

dashboardConfig, err := config.EnvironChaosDashboard()
if err != nil {
log.Error(err, "main: invalid eventTTL")
log.Error(err, "main: invalid ChaosDashboardConfig")
os.Exit(1)
}
archiveExperimentTTL, err := time.ParseDuration(conf.PersistTTL.Experiment)

persistTTLConfigParsed, err := config.ParsePersistTTLConfig(dashboardConfig.PersistTTL)
if err != nil {
log.Error(err, "main: invalid archiveExperimentTTL")
log.Error(err, "main: invalid PersistTTLConfig")
os.Exit(1)
}

version.PrintVersionInfo("Chaos Dashboard")
if printVersion {
os.Exit(0)
}

ctrl.SetLogger(zap.Logger(true))

stopCh := ctrl.SetupSignalHandler()

controllerRuntimeStopCh := ctrl.SetupSignalHandler()
app := fx.New(
fx.Provide(
func() (<-chan struct{}, *config.ChaosDashboardConfig, ttlcontroller.TTLconfig) {
return stopCh, &conf, ttlcontroller.TTLconfig{
DatabaseTTLResyncPeriod: databaseTTLResyncPeriod,
EventTTL: eventTTL,
ArchiveExperimentTTL: archiveExperimentTTL,
}
func() (<-chan struct{}, *config.ChaosDashboardConfig, *ttlcontroller.TTLconfig) {
return controllerRuntimeStopCh, dashboardConfig, persistTTLConfigParsed
},
dbstore.NewDBStore,
collector.NewServer,
Expand All @@ -99,18 +92,6 @@ func main() {
fx.Invoke(ttlcontroller.Register),
)

startCtx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
if err := app.Start(startCtx); err != nil {
log.Error(err, "failed to start app")
os.Exit(1)
}

<-stopCh
stopCtx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
if err := app.Stop(stopCtx); err != nil {
log.Error(err, "failed to stop app")
os.Exit(1)
}
app.Run()
<-controllerRuntimeStopCh
}
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Documents

This directory was moved to [here](../website/docs).
This directory was moved to [here](../website/docs).
19 changes: 8 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ require (
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/ethercflow/hookfs v0.3.0
github.com/ghodss/yaml v1.0.0
github.com/gin-gonic/gin v1.6.2
github.com/gin-gonic/gin v1.6.3
github.com/go-logr/logr v0.1.0
github.com/go-logr/zapr v0.1.0
github.com/go-playground/validator/v10 v10.2.0
github.com/go-sql-driver/mysql v1.4.1
github.com/go-playground/validator/v10 v10.3.0
github.com/gogo/googleapis v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.3.3
github.com/google/go-cmp v0.4.0 // indirect
github.com/golang/protobuf v1.4.2
github.com/gorilla/websocket v1.4.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
Expand Down Expand Up @@ -49,21 +47,20 @@ require (
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/spf13/cobra v0.0.6 // indirect
github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba
github.com/swaggo/swag v1.6.5
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.6.7
github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect
github.com/vishvananda/netlink v1.0.0
go.uber.org/fx v1.12.0
go.uber.org/multierr v1.5.0 // indirect
go.uber.org/zap v1.14.0
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect
go.uber.org/zap v1.15.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20200320220750-118fecf932d8
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.0.0-20200309202150-20ab64c0d93f
google.golang.org/grpc v1.24.0
google.golang.org/grpc v1.27.0
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
k8s.io/api v0.17.0
k8s.io/apiextensions-apiserver v0.17.0
Expand Down
Loading

0 comments on commit 297583e

Please sign in to comment.