Skip to content

Commit

Permalink
Cherry pick #2454 to release-4.0 (#2457)
Browse files Browse the repository at this point in the history
* Cherry pick #2454

Signed-off-by: Breezewish <[email protected]>

* Add TiDB Dashboard configurations

Signed-off-by: Breezewish <[email protected]>

* Fix race

Signed-off-by: Breezewish <[email protected]>

* Cherry pick #2460

Signed-off-by: Breezewish <[email protected]>
  • Loading branch information
breezewish authored May 27, 2020
1 parent 2303e3a commit 56d4c3d
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
17 changes: 16 additions & 1 deletion conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ merge-schedule-limit = 8
hot-region-schedule-limit = 4
## There are some policies supported: ["count", "size"], default: "count"
# leader-schedule-policy = "count"
## When the score difference between the leader or Region of the two stores is
## When the score difference between the leader or Region of the two stores is
## less than specified multiple times of the Region size, it is considered in balance by PD.
## If it equals 0.0, PD will automatically adjust it.
# tolerant-size-ratio = 0.0
Expand Down Expand Up @@ -108,3 +108,18 @@ location-labels = []
# [[label-property.reject-leader]]
# key = "zone"
# value = "cn1

[dashboard]
## Configurations below are for the TiDB Dashboard embedded in the PD.

## The path of the CA certificate used to verify the TiDB server in TLS.
# tidb-cacert-path = ""
## The path of the certificate used to connect to TiDB server in TLS.
# tidb-cert-path = ""
## The path of the certificate private key.
# tidb-key-path = ""

## The public path prefix to serve Dashboard urls. It can be set when Dashboard
## is running behind a reverse proxy. Do not configure it if you access
## Dashboard directly.
# public-path-prefix = "/dashboard"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/opentracing/opentracing-go v1.0.2
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d
github.com/pingcap-incubator/tidb-dashboard v0.0.0-20200514075710-eecc9a4525b5
github.com/pingcap-incubator/tidb-dashboard v0.0.0-20200526165651-52e570bf6f0a
github.com/pingcap/check v0.0.0-20191216031241-8a5a85928f12
github.com/pingcap/errcode v0.0.0-20180921232412-a1a7271709d9
github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/goccy/go-graphviz v0.0.5 h1:qcjgvNiYbLyfLAq9LvyYBJ7sNMbQh9w4FoAzBDrYhYw=
github.com/goccy/go-graphviz v0.0.5/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk=
Expand Down Expand Up @@ -294,8 +296,8 @@ github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g=
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d/go.mod h1:lXfE4PvvTW5xOjO6Mba8zDPyw8M93B6AQ7frTGnMlA8=
github.com/pingcap-incubator/tidb-dashboard v0.0.0-20200514075710-eecc9a4525b5 h1:bsNvEA2a34FcrBVjAaI/a+y5cU8IxP16J2PIVNDHZaM=
github.com/pingcap-incubator/tidb-dashboard v0.0.0-20200514075710-eecc9a4525b5/go.mod h1:8q+yDx0STBPri8xS4A2duS1dAf+xO0cMtjwe0t6MWJk=
github.com/pingcap-incubator/tidb-dashboard v0.0.0-20200526165651-52e570bf6f0a h1:FE7NgHM9ubPb7elnJUot9XBRLWDqhyXWIby5r1q1JXA=
github.com/pingcap-incubator/tidb-dashboard v0.0.0-20200526165651-52e570bf6f0a/go.mod h1:c+hdTnQglVGcBvQwLZvCUYzvi1+1SYHfnWH/XlKI/BI=
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8 h1:USx2/E1bX46VG32FIw034Au6seQ2fY9NEILmNh/UlQg=
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8/go.mod h1:B1+S9LNcuMyLH/4HMTViQOJevkGiik3wW2AN9zb2fNQ=
github.com/pingcap/check v0.0.0-20191107115940-caf2b9e6ccf4 h1:iRtOAQ6FXkY/BGvst3CDfTva4nTqh6CL8WXvanLdbu0=
Expand Down
2 changes: 2 additions & 0 deletions pkg/dashboard/adapter/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func NewAPIService(srv *server.Server, redirector http.Handler) (*apiserver.Serv
dashboardCfg := &config.Config{
DataDir: cfg.DataDir,
PDEndPoint: etcdCfg.ACUrls[0].String(),
PathPrefix: cfg.Dashboard.PublicPathPrefix,
}
uiserver.InitAssetFS(cfg.Dashboard.PublicPathPrefix)
dashboardCfg.ClusterTLSConfig, err = cfg.Security.ToTLSConfig()
if err != nil {
return nil, err
Expand Down
57 changes: 57 additions & 0 deletions pkg/dashboard/uiserver/embedded_assets_rewriter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package uiserver

import (
"html"
"os"
"strings"
"sync"
)

var once sync.Once

type modifiedFileInfo struct {
os.FileInfo
size int64
}

func (f modifiedFileInfo) Size() int64 {
return f.size
}

func (f modifiedFileInfo) Sys() interface{} {
return nil
}

// InitAssetFS init the static resources with given public path prefix.
func InitAssetFS(prefix string) {
once.Do(func() {
rewrite := func(assetPath string) {
a, err := _bindata[assetPath]()
if err != nil {
panic("Asset " + assetPath + " not found.")
}
tmplText := string(a.bytes)
updated := strings.ReplaceAll(tmplText, "__PUBLIC_PATH_PREFIX__", html.EscapeString(prefix))
a.bytes = []byte(updated)
a.info = modifiedFileInfo{a.info, int64(len(a.bytes))}
_bindata[assetPath] = func() (*asset, error) {
return a, nil
}
}
rewrite("build/index.html")
rewrite("build/diagnoseReport.html")
})
}
14 changes: 11 additions & 3 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ const (

defaultDRWaitStoreTimeout = time.Minute
defaultDRWaitSyncTimeout = time.Minute

defaultPublicPathPrefix = "/dashboard"
)

var (
Expand Down Expand Up @@ -464,6 +466,11 @@ func (c *Config) Adjust(meta *toml.MetaData) error {

c.ReplicationMode.adjust(configMetaData.Child("replication-mode"))

if c.Dashboard.PublicPathPrefix == "" {
c.Dashboard.PublicPathPrefix = defaultPublicPathPrefix
}
c.Dashboard.PublicPathPrefix = strings.TrimRight(c.Dashboard.PublicPathPrefix, "/")

return nil
}

Expand Down Expand Up @@ -1117,9 +1124,10 @@ func (c *Config) GenEmbedEtcdConfig() (*embed.Config, error) {

// DashboardConfig is the configuration for tidb-dashboard.
type DashboardConfig struct {
TiDBCAPath string `toml:"tidb-cacert-path" json:"tidb_cacert_path"`
TiDBCertPath string `toml:"tidb-cert-path" json:"tidb_cert_path"`
TiDBKeyPath string `toml:"tidb-key-path" json:"tidb_key_path"`
TiDBCAPath string `toml:"tidb-cacert-path" json:"tidb_cacert_path"`
TiDBCertPath string `toml:"tidb-cert-path" json:"tidb_cert_path"`
TiDBKeyPath string `toml:"tidb-key-path" json:"tidb_key_path"`
PublicPathPrefix string `toml:"public-path-prefix" json:"public_path_prefix"`
}

// ToTiDBTLSConfig generates tls config for connecting to TiDB, used by tidb-dashboard.
Expand Down

0 comments on commit 56d4c3d

Please sign in to comment.