Skip to content

Commit

Permalink
ui: Online Config (#733)
Browse files Browse the repository at this point in the history
Signed-off-by: Breezewish <me@breeswish.org>
  • Loading branch information
breezewish authored Aug 19, 2020
1 parent fb43f5b commit 89fd495
Show file tree
Hide file tree
Showing 56 changed files with 2,297 additions and 504 deletions.
12 changes: 6 additions & 6 deletions cmd/tidb-dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ type DashboardCLIConfig struct {
// NewCLIConfig generates the configuration of the dashboard in standalone mode.
func NewCLIConfig() *DashboardCLIConfig {
cfg := &DashboardCLIConfig{}
cfg.CoreConfig = &config.Config{}
cfg.CoreConfig = config.Default()

flag.StringVarP(&cfg.ListenHost, "host", "h", "127.0.0.1", "listen host of the Dashboard Server")
flag.IntVarP(&cfg.ListenPort, "port", "p", 12333, "listen port of the Dashboard Server")
flag.BoolVarP(&cfg.EnableDebugLog, "debug", "d", false, "enable debug logs")
flag.StringVar(&cfg.CoreConfig.DataDir, "data-dir", "/tmp/dashboard-data", "path to the Dashboard Server data directory")
flag.StringVar(&cfg.CoreConfig.PublicPathPrefix, "path-prefix", config.DefaultPublicPathPrefix, "public URL path prefix for reverse proxies")
flag.StringVar(&cfg.CoreConfig.PDEndPoint, "pd", "http://127.0.0.1:2379", "PD endpoint address that Dashboard Server connects to")
flag.BoolVar(&cfg.CoreConfig.EnableTelemetry, "telemetry", true, "allow telemetry")
flag.BoolVar(&cfg.CoreConfig.EnableExperimental, "experimental", false, "allow experimental features")
flag.StringVar(&cfg.CoreConfig.DataDir, "data-dir", cfg.CoreConfig.DataDir, "path to the Dashboard Server data directory")
flag.StringVar(&cfg.CoreConfig.PublicPathPrefix, "path-prefix", cfg.CoreConfig.PublicPathPrefix, "public URL path prefix for reverse proxies")
flag.StringVar(&cfg.CoreConfig.PDEndPoint, "pd", cfg.CoreConfig.PDEndPoint, "PD endpoint address that Dashboard Server connects to")
flag.BoolVar(&cfg.CoreConfig.EnableTelemetry, "telemetry", cfg.CoreConfig.EnableTelemetry, "allow telemetry")
flag.BoolVar(&cfg.CoreConfig.EnableExperimental, "experimental", cfg.CoreConfig.EnableExperimental, "allow experimental features")

showVersion := flag.BoolP("version", "v", false, "print version information and exit")

Expand Down
2 changes: 1 addition & 1 deletion etc/manualTestEnv/multiHost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TiDB, PD, TiKV, TiFlash each in different hosts.
1. Use [TiUP](https://tiup.io/) to deploy the cluster to the box (only need to do it once):

```bash
tiup cluster deploy multiHost v4.0.0 topology.yaml -i ../_shared/vagrant_key -y --user vagrant
tiup cluster deploy multiHost v4.0.4 topology.yaml -i ../_shared/vagrant_key -y --user vagrant
```

1. Start the cluster in the box:
Expand Down
2 changes: 1 addition & 1 deletion etc/manualTestEnv/multiReplica/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Multiple TiKV nodes in different labels.
1. Use [TiUP](https://tiup.io/) to deploy the cluster to the box (only need to do it once):

```bash
tiup cluster deploy multiReplica v4.0.0 topology.yaml -i ../_shared/vagrant_key -y --user vagrant
tiup cluster deploy multiReplica v4.0.4 topology.yaml -i ../_shared/vagrant_key -y --user vagrant
```

1. Start the cluster in the box:
Expand Down
2 changes: 1 addition & 1 deletion etc/manualTestEnv/singleHost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TiDB, PD, TiKV, TiFlash in the same host.
1. Use [TiUP](https://tiup.io/) to deploy the cluster to the box (only need to do it once):

```bash
tiup cluster deploy singleHost v4.0.0 topology.yaml -i ../_shared/vagrant_key -y --user vagrant
tiup cluster deploy singleHost v4.0.4 topology.yaml -i ../_shared/vagrant_key -y --user vagrant
```

1. Start the cluster in the box:
Expand Down
2 changes: 1 addition & 1 deletion etc/manualTestEnv/singleHostMultiDisk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ All instances in a single host, but on different disks.
1. Use [TiUP](https://tiup.io/) to deploy the cluster to the box (only need to do it once):

```bash
tiup cluster deploy singleHostMultiDisk v4.0.0 topology.yaml -i ../_shared/vagrant_key -y --user vagrant
tiup cluster deploy singleHostMultiDisk v4.0.4 topology.yaml -i ../_shared/vagrant_key -y --user vagrant
```

1. Start the cluster in the box:
Expand Down
12 changes: 8 additions & 4 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"go.uber.org/fx"

"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver/clusterinfo"
"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver/configuration"
"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver/diagnose"
"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver/info"
"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver/logsearch"
Expand All @@ -38,11 +39,12 @@ import (
apiutils "github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver/utils"
"github.com/pingcap-incubator/tidb-dashboard/pkg/config"
"github.com/pingcap-incubator/tidb-dashboard/pkg/dbstore"
pkghttp "github.com/pingcap-incubator/tidb-dashboard/pkg/http"
"github.com/pingcap-incubator/tidb-dashboard/pkg/httpc"
"github.com/pingcap-incubator/tidb-dashboard/pkg/keyvisual"
keyvisualregion "github.com/pingcap-incubator/tidb-dashboard/pkg/keyvisual/region"
"github.com/pingcap-incubator/tidb-dashboard/pkg/pd"
"github.com/pingcap-incubator/tidb-dashboard/pkg/tidb"
"github.com/pingcap-incubator/tidb-dashboard/pkg/tikv"
"github.com/pingcap-incubator/tidb-dashboard/pkg/utils"
"github.com/pingcap-incubator/tidb-dashboard/pkg/utils/version"
)
Expand Down Expand Up @@ -103,12 +105,12 @@ func (s *Service) Start(ctx context.Context) error {
newAPIHandlerEngine,
s.provideLocals,
dbstore.NewDBStore,
httpc.NewHTTPClient,
pd.NewEtcdClient,
pd.NewPDClient,
config.NewDynamicConfigManager,
tidb.NewForwarderConfig,
tidb.NewForwarder,
pkghttp.NewHTTPClientWithConf,
tidb.NewTiDBClient,
tikv.NewTiKVClient,
user.NewAuthService,
info.NewService,
clusterinfo.NewService,
Expand All @@ -120,6 +122,7 @@ func (s *Service) Start(ctx context.Context) error {
keyvisual.NewService,
metrics.NewService,
queryeditor.NewService,
configuration.NewService,
),
fx.Populate(&s.apiHandlerEngine),
fx.Invoke(
Expand All @@ -134,6 +137,7 @@ func (s *Service) Start(ctx context.Context) error {
keyvisual.Register,
metrics.Register,
queryeditor.Register,
configuration.Register,
// Must be at the end
s.status.Register,
),
Expand Down
48 changes: 24 additions & 24 deletions pkg/apiserver/clusterinfo/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ import (

"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver/user"
"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver/utils"
"github.com/pingcap-incubator/tidb-dashboard/pkg/httpc"
"github.com/pingcap-incubator/tidb-dashboard/pkg/pd"
"github.com/pingcap-incubator/tidb-dashboard/pkg/tidb"
"github.com/pingcap-incubator/tidb-dashboard/pkg/utils/topology"
)

type ServiceParams struct {
fx.In
PDClient *pd.Client
EtcdClient *clientv3.Client
HTTPClient *httpc.Client
TiDBClient *tidb.Client
}

type Service struct {
params ServiceParams
lifecycleCtx context.Context

pdClient *pd.Client
etcdClient *clientv3.Client
httpClient *http.Client
tidbForwarder *tidb.Forwarder
}

func NewService(lc fx.Lifecycle, pdClient *pd.Client, etcdClient *clientv3.Client, httpClient *http.Client, tidbForwarder *tidb.Forwarder) *Service {
s := &Service{
pdClient: pdClient,
etcdClient: etcdClient,
httpClient: httpClient,
tidbForwarder: tidbForwarder,
}
func NewService(lc fx.Lifecycle, p ServiceParams) *Service {
s := &Service{params: p}
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
s.lifecycleCtx = ctx
Expand All @@ -75,7 +75,7 @@ func Register(r *gin.RouterGroup, auth *user.AuthService, s *Service) {

endpoint = r.Group("/host")
endpoint.Use(auth.MWAuthRequired())
endpoint.Use(utils.MWConnectTiDB(s.tidbForwarder))
endpoint.Use(utils.MWConnectTiDB(s.params.TiDBClient))
endpoint.GET("/all", s.getHostsInfo)
}

Expand All @@ -100,7 +100,7 @@ func (s *Service) deleteTiDBTopology(c *gin.Context) {
wg.Add(1)
go func(toDel string) {
defer wg.Done()
if _, err := s.etcdClient.Delete(ctx, toDel); err != nil {
if _, err := s.params.EtcdClient.Delete(ctx, toDel); err != nil {
errorChannel <- err
}
}(key)
Expand Down Expand Up @@ -129,7 +129,7 @@ func (s *Service) deleteTiDBTopology(c *gin.Context) {
// @Security JwtAuth
// @Failure 401 {object} utils.APIError "Unauthorized failure"
func (s *Service) getTiDBTopology(c *gin.Context) {
instances, err := topology.FetchTiDBTopology(s.lifecycleCtx, s.etcdClient)
instances, err := topology.FetchTiDBTopology(s.lifecycleCtx, s.params.EtcdClient)
if err != nil {
_ = c.Error(err)
return
Expand All @@ -151,7 +151,7 @@ type StoreTopologyResponse struct {
// @Security JwtAuth
// @Failure 401 {object} utils.APIError "Unauthorized failure"
func (s *Service) getStoreTopology(c *gin.Context) {
tikvInstances, tiFlashInstances, err := topology.FetchStoreTopology(s.pdClient)
tikvInstances, tiFlashInstances, err := topology.FetchStoreTopology(s.params.PDClient)
if err != nil {
_ = c.Error(err)
return
Expand All @@ -171,7 +171,7 @@ func (s *Service) getStoreTopology(c *gin.Context) {
// @Security JwtAuth
// @Failure 401 {object} utils.APIError "Unauthorized failure"
func (s *Service) getStoreLocationTopology(c *gin.Context) {
storeLocation, err := topology.FetchStoreLocation(s.pdClient)
storeLocation, err := topology.FetchStoreLocation(s.params.PDClient)
if err != nil {
_ = c.Error(err)
return
Expand All @@ -188,7 +188,7 @@ func (s *Service) getStoreLocationTopology(c *gin.Context) {
// @Security JwtAuth
// @Failure 401 {object} utils.APIError "Unauthorized failure"
func (s *Service) getPDTopology(c *gin.Context) {
instances, err := topology.FetchPDTopology(s.pdClient)
instances, err := topology.FetchPDTopology(s.params.PDClient)
if err != nil {
_ = c.Error(err)
return
Expand All @@ -205,7 +205,7 @@ func (s *Service) getPDTopology(c *gin.Context) {
// @Security JwtAuth
// @Failure 401 {object} utils.APIError "Unauthorized failure"
func (s *Service) getAlertManagerTopology(c *gin.Context) {
instance, err := topology.FetchAlertManagerTopology(s.lifecycleCtx, s.etcdClient)
instance, err := topology.FetchAlertManagerTopology(s.lifecycleCtx, s.params.EtcdClient)
if err != nil {
_ = c.Error(err)
return
Expand All @@ -222,7 +222,7 @@ func (s *Service) getAlertManagerTopology(c *gin.Context) {
// @Security JwtAuth
// @Failure 401 {object} utils.APIError "Unauthorized failure"
func (s *Service) getGrafanaTopology(c *gin.Context) {
instance, err := topology.FetchGrafanaTopology(s.lifecycleCtx, s.etcdClient)
instance, err := topology.FetchGrafanaTopology(s.lifecycleCtx, s.params.EtcdClient)
if err != nil {
_ = c.Error(err)
return
Expand All @@ -241,7 +241,7 @@ func (s *Service) getGrafanaTopology(c *gin.Context) {
// @Failure 401 {object} utils.APIError "Unauthorized failure"
func (s *Service) getAlertManagerCounts(c *gin.Context) {
address := c.Param("address")
cnt, err := fetchAlertManagerCounts(s.lifecycleCtx, address, s.httpClient)
cnt, err := fetchAlertManagerCounts(s.lifecycleCtx, address, s.params.HTTPClient)
if err != nil {
_ = c.Error(err)
return
Expand Down Expand Up @@ -297,15 +297,15 @@ func (s *Service) getHostsInfo(c *gin.Context) {

func (s *Service) fetchAllInstanceHostsMap() (map[string]struct{}, error) {
allHosts := make(map[string]struct{})
pdInfo, err := topology.FetchPDTopology(s.pdClient)
pdInfo, err := topology.FetchPDTopology(s.params.PDClient)
if err != nil {
return nil, err
}
for _, i := range pdInfo {
allHosts[i.IP] = struct{}{}
}

tikvInfo, tiFlashInfo, err := topology.FetchStoreTopology(s.pdClient)
tikvInfo, tiFlashInfo, err := topology.FetchStoreTopology(s.params.PDClient)
if err != nil {
return nil, err
}
Expand All @@ -316,7 +316,7 @@ func (s *Service) fetchAllInstanceHostsMap() (map[string]struct{}, error) {
allHosts[i.IP] = struct{}{}
}

tidbInfo, err := topology.FetchTiDBTopology(s.lifecycleCtx, s.etcdClient)
tidbInfo, err := topology.FetchTiDBTopology(s.lifecycleCtx, s.params.EtcdClient)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/apiserver/clusterinfo/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (
"fmt"
"io/ioutil"
"net/http"

"github.com/pingcap-incubator/tidb-dashboard/pkg/httpc"
)

func fetchAlertManagerCounts(ctx context.Context, alertManagerAddr string, httpClient *http.Client) (int, error) {
func fetchAlertManagerCounts(ctx context.Context, alertManagerAddr string, httpClient *httpc.Client) (int, error) {
// FIXME: Use httpClient.SendGetRequest

uri := fmt.Sprintf("http://%s/api/v2/alerts", alertManagerAddr)
req, err := http.NewRequestWithContext(ctx, "GET", uri, nil)
if err != nil {
Expand Down
Loading

0 comments on commit 89fd495

Please sign in to comment.