Skip to content

Commit

Permalink
Release v2021.07.17.1 (#962) [skip pd_pr]
Browse files Browse the repository at this point in the history
* Feat/distro resource (#955)

* Feat/replace distro vars (#956)

* update: release version
  • Loading branch information
shhdgit committed Jul 21, 2021
1 parent 2226872 commit 61cbaec
Show file tree
Hide file tree
Showing 59 changed files with 613 additions and 375 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ jobs:
asset_name: embedded-assets-golang.zip
asset_content_type: application/zip
pd_pr:
if: "!contains(github.event.head_commit.message, 'skip pd_pr')"
name: Create PD PR
runs-on: ubuntu-latest
needs: release
Expand Down
1 change: 1 addition & 0 deletions cmd/tidb-dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
keyvisualregion "github.com/pingcap/tidb-dashboard/pkg/keyvisual/region"
"github.com/pingcap/tidb-dashboard/pkg/swaggerserver"
"github.com/pingcap/tidb-dashboard/pkg/uiserver"
_ "github.com/pingcap/tidb-dashboard/pkg/utils/distro/populate"
"github.com/pingcap/tidb-dashboard/pkg/utils/version"
)

Expand Down
7 changes: 4 additions & 3 deletions pkg/apiserver/configuration/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/pingcap/tidb-dashboard/pkg/pd"
"github.com/pingcap/tidb-dashboard/pkg/tidb"
"github.com/pingcap/tidb-dashboard/pkg/tikv"
"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
"github.com/pingcap/tidb-dashboard/pkg/utils/topology"
)

Expand Down Expand Up @@ -119,7 +120,7 @@ func (s *Service) getConfigItemsFromTiDBToChannel(tidb *topology.TiDBInfo, ch ch

r, err := s.getConfigItemsFromTiDB(tidb.IP, int(tidb.StatusPort))
if err != nil {
ch <- channelItem{Err: ErrListConfigItemsFailed.Wrap(err, "Failed to list TiDB config items of %s", displayAddress)}
ch <- channelItem{Err: ErrListConfigItemsFailed.Wrap(err, "Failed to list %s config items of %s", distro.Data("tidb"), displayAddress)}
return
}
ch <- channelItem{
Expand Down Expand Up @@ -170,7 +171,7 @@ type ShowVariableItem struct {
func (s *Service) getGlobalVariablesFromTiDBToChannel(db *gorm.DB, ch chan<- channelItem) {
r, err := s.getGlobalVariablesFromTiDB(db)
if err != nil {
ch <- channelItem{Err: ErrListConfigItemsFailed.Wrap(err, "Failed to list TiDB variables")}
ch <- channelItem{Err: ErrListConfigItemsFailed.Wrap(err, "Failed to list %s variables", distro.Data("tidb"))}
return
}
ch <- channelItem{
Expand Down Expand Up @@ -212,7 +213,7 @@ func (s *Service) getAllConfigItems(db *gorm.DB) (*AllConfigItems, error) {

tidbInfo, err := topology.FetchTiDBTopology(s.lifecycleCtx, s.params.EtcdClient)
if err != nil {
return nil, ErrListTopologyFailed.Wrap(err, "Failed to list TiDB instances")
return nil, ErrListTopologyFailed.Wrap(err, "Failed to list %s instances", distro.Data("tidb"))
}

ch := make(chan channelItem)
Expand Down
3 changes: 2 additions & 1 deletion pkg/apiserver/statement/statement_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/thoas/go-funk"

"github.com/pingcap/tidb-dashboard/pkg/apiserver/utils"
"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
)

var (
Expand Down Expand Up @@ -51,7 +52,7 @@ func (s *Service) genSelectStmt(tableColumns []string, reqJSONColumns []string)
}).([]Field)

if len(fields) == 0 {
return "", ErrUnknownColumn.New("all columns are not included in the current version TiDB schema, columns: %q", reqJSONColumns)
return "", ErrUnknownColumn.New("all columns are not included in the current version %s schema, columns: %q", distro.Data("tidb"), reqJSONColumns)
}

stmt := funk.Map(fields, func(f Field) string {
Expand Down
11 changes: 6 additions & 5 deletions pkg/keyvisual/decorator/tidb_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"go.uber.org/zap"

"github.com/pingcap/tidb-dashboard/pkg/tidb/model"
"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
)

const (
Expand All @@ -48,7 +49,7 @@ func (s *tidbLabelStrategy) updateMap(ctx context.Context) {
if s.SchemaVersion != -1 {
log.Warn("failed to get tidb schema version", zap.Error(err))
} else {
log.Debug("failed to get tidb schema version, maybe not a TiDB cluster", zap.Error(err))
log.Debug("failed to get tidb schema version, maybe not a db cluster", zap.Error(err))
}
return
}
Expand All @@ -57,7 +58,7 @@ func (s *tidbLabelStrategy) updateMap(ctx context.Context) {
if s.SchemaVersion != -1 {
log.Warn("failed to get tidb schema version", zap.Error(err))
} else {
log.Debug("failed to get tidb schema version, maybe not a TiDB cluster", zap.Error(err))
log.Debug("failed to get tidb schema version, maybe not a db cluster", zap.Error(err))
}
return
}
Expand All @@ -71,7 +72,7 @@ func (s *tidbLabelStrategy) updateMap(ctx context.Context) {
// get all database info
var dbInfos []*model.DBInfo
if err := s.request("/schema", &dbInfos); err != nil {
log.Error("fail to send schema request to TiDB", zap.Error(err))
log.Error("fail to send schema request", zap.String("component", distro.Data("tidb")), zap.Error(err))
return
}

Expand All @@ -84,7 +85,7 @@ func (s *tidbLabelStrategy) updateMap(ctx context.Context) {
var tableInfos []*model.TableInfo
encodeName := url.PathEscape(db.Name.O)
if err := s.request(fmt.Sprintf("/schema/%s", encodeName), &tableInfos); err != nil {
log.Error("fail to send schema request to TiDB", zap.Error(err))
log.Error("fail to send schema request", zap.String("component", distro.Data("tidb")), zap.Error(err))
updateSuccess = false
continue
}
Expand Down Expand Up @@ -126,7 +127,7 @@ func (s *tidbLabelStrategy) request(path string, v interface{}) error {
return err
}
if err = json.Unmarshal(data, v); err != nil {
return ErrInvalidData.Wrap(err, "TiDB schema API unmarshal failed")
return ErrInvalidData.Wrap(err, "%s schema API unmarshal failed", distro.Data("tidb"))
}
return nil
}
7 changes: 4 additions & 3 deletions pkg/keyvisual/input/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

regionpkg "github.com/pingcap/tidb-dashboard/pkg/keyvisual/region"
"github.com/pingcap/tidb-dashboard/pkg/pd"
"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
)

var (
Expand Down Expand Up @@ -95,18 +96,18 @@ func (rs *RegionsInfo) GetValues(tag regionpkg.StatTag) []uint64 {
func read(data []byte) (*RegionsInfo, error) {
regions := &RegionsInfo{}
if err := json.Unmarshal(data, regions); err != nil {
return nil, ErrInvalidData.Wrap(err, "PD regions API unmarshal failed")
return nil, ErrInvalidData.Wrap(err, "%s regions API unmarshal failed", distro.Data("pd"))
}

for _, region := range regions.Regions {
startBytes, err := hex.DecodeString(region.StartKey)
if err != nil {
return nil, ErrInvalidData.Wrap(err, "PD regions API unmarshal failed")
return nil, ErrInvalidData.Wrap(err, "%s regions API unmarshal failed", distro.Data("pd"))
}
region.StartKey = regionpkg.String(startBytes)
endBytes, err := hex.DecodeString(region.EndKey)
if err != nil {
return nil, ErrInvalidData.Wrap(err, "PD regions API unmarshal failed")
return nil, ErrInvalidData.Wrap(err, "%s regions API unmarshal failed", distro.Data("pd"))
}
region.EndKey = regionpkg.String(endBytes)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/keyvisual/input/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go.uber.org/zap"

"github.com/pingcap/tidb-dashboard/pkg/keyvisual/storage"
"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
)

type fileInput struct {
Expand Down Expand Up @@ -61,12 +62,12 @@ func readFile(fileTime time.Time) (*RegionsInfo, error) {
fileName := fileTime.Format("./data/20060102-15-04.json")
file, err := os.Open(fileName)
if err != nil {
return nil, ErrInvalidData.Wrap(err, "PD regions API unmarshal failed, from file %s", fileName)
return nil, ErrInvalidData.Wrap(err, "%s regions API unmarshal failed, from file %s", distro.Data("pd"), fileName)
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
return nil, ErrInvalidData.Wrap(err, "PD regions API unmarshal failed, from file %s", fileName)
return nil, ErrInvalidData.Wrap(err, "%s regions API unmarshal failed, from file %s", distro.Data("pd"), fileName)
}
return read(data)
}
5 changes: 3 additions & 2 deletions pkg/pd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/pingcap/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/httpc"
"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
)

var (
Expand Down Expand Up @@ -83,7 +84,7 @@ func (c Client) WithBeforeRequest(callback func(req *http.Request)) *Client {

func (c *Client) Get(relativeURI string) (*httpc.Response, error) {
uri := fmt.Sprintf("%s/pd/api/v1%s", c.baseURL, relativeURI)
return c.httpClient.WithTimeout(c.timeout).Send(c.lifecycleCtx, uri, http.MethodGet, nil, ErrPDClientRequestFailed, "PD")
return c.httpClient.WithTimeout(c.timeout).Send(c.lifecycleCtx, uri, http.MethodGet, nil, ErrPDClientRequestFailed, distro.Data("pd"))
}

func (c *Client) SendGetRequest(relativeURI string) ([]byte, error) {
Expand All @@ -96,5 +97,5 @@ func (c *Client) SendGetRequest(relativeURI string) ([]byte, error) {

func (c *Client) SendPostRequest(relativeURI string, body io.Reader) ([]byte, error) {
uri := fmt.Sprintf("%s/pd/api/v1%s", c.baseURL, relativeURI)
return c.httpClient.WithTimeout(c.timeout).SendRequest(c.lifecycleCtx, uri, http.MethodPost, body, ErrPDClientRequestFailed, "PD")
return c.httpClient.WithTimeout(c.timeout).SendRequest(c.lifecycleCtx, uri, http.MethodPost, body, ErrPDClientRequestFailed, distro.Data("pd"))
}
19 changes: 10 additions & 9 deletions pkg/tidb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/pingcap/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/httpc"
"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
)

var (
Expand Down Expand Up @@ -108,8 +109,8 @@ func (c *Client) OpenSQLConn(user string, pass string) (*gorm.DB, error) {
overrideEndpoint := os.Getenv(tidbOverrideSQLEndpointEnvVar)
// the `tidbOverrideSQLEndpointEnvVar` and the `Client.sqlAPIAddress` have the same override priority, if both exist, an error is returned
if overrideEndpoint != "" && c.sqlAPIAddress != "" {
log.Warn(fmt.Sprintf("Reject to establish a target specified TiDB SQL connection since `%s` is set", tidbOverrideSQLEndpointEnvVar))
return nil, ErrTiDBConnFailed.New("TiDB Dashboard is configured to only connect to specified TiDB host")
log.Warn(fmt.Sprintf("Reject to establish a target specified %s SQL connection since `%s` is set", distro.Data("tidb"), tidbOverrideSQLEndpointEnvVar))
return nil, ErrTiDBConnFailed.New("%s Dashboard is configured to only connect to specified %s host", distro.Data("tidb"), distro.Data("tidb"))
}

var addr string
Expand Down Expand Up @@ -141,18 +142,18 @@ func (c *Client) OpenSQLConn(user string, pass string) (*gorm.DB, error) {
if err != nil {
if _, ok := err.(*net.OpError); ok || err == driver.ErrBadConn {
if strings.HasPrefix(addr, "0.0.0.0:") {
log.Warn("TiDB reported its address to be 0.0.0.0. Please specify `-advertise-address` command line parameter when running TiDB")
log.Warn(fmt.Sprintf("%s reported its address to be 0.0.0.0. Please specify `-advertise-address` command line parameter when running %s", distro.Data("tidb"), distro.Data("tidb")))
}
if c.forwarder.sqlProxy.noAliveRemote.Load() {
return nil, ErrNoAliveTiDB.NewWithNoMessage()
}
return nil, ErrTiDBConnFailed.Wrap(err, "failed to connect to TiDB")
return nil, ErrTiDBConnFailed.Wrap(err, "failed to connect to %s", distro.Data("tidb"))
} else if mysqlErr, ok := err.(*mysql.MySQLError); ok {
if mysqlErr.Number == mysqlerr.ER_ACCESS_DENIED_ERROR {
return nil, ErrTiDBAuthFailed.New("bad TiDB username or password")
return nil, ErrTiDBAuthFailed.New("bad %s username or password", distro.Data("tidb"))
}
}
log.Warn("Unknown error occurred while opening TiDB connection", zap.Error(err))
log.Warn(fmt.Sprintf("Unknown error occurred while opening %s connection", distro.Data("tidb")), zap.Error(err))
return nil, err
}

Expand All @@ -165,8 +166,8 @@ func (c *Client) Get(relativeURI string) (*httpc.Response, error) {
overrideEndpoint := os.Getenv(tidbOverrideStatusEndpointEnvVar)
// the `tidbOverrideStatusEndpointEnvVar` and the `Client.statusAPIAddress` have the same override priority, if both exist and have not enforced `Client.statusAPIAddress` then an error is returned
if overrideEndpoint != "" && c.statusAPIAddress != "" && !c.enforceStatusAPIAddresss {
log.Warn(fmt.Sprintf("Reject to establish a target specified TiDB status connection since `%s` is set", tidbOverrideStatusEndpointEnvVar))
return nil, ErrTiDBConnFailed.New("TiDB Dashboard is configured to only connect to specified TiDB host")
log.Warn(fmt.Sprintf("Reject to establish a target specified %s status connection since `%s` is set", distro.Data("tidb"), tidbOverrideStatusEndpointEnvVar))
return nil, ErrTiDBConnFailed.New("%s Dashboard is configured to only connect to specified %s host", distro.Data("tidb"), distro.Data("tidb"))
}

var addr string
Expand All @@ -187,7 +188,7 @@ func (c *Client) Get(relativeURI string) (*httpc.Response, error) {
uri := fmt.Sprintf("%s://%s%s", c.statusAPIHTTPScheme, addr, relativeURI)
res, err := c.statusAPIHTTPClient.
WithTimeout(c.statusAPITimeout).
Send(c.lifecycleCtx, uri, http.MethodGet, nil, ErrTiDBClientRequestFailed, "TiDB")
Send(c.lifecycleCtx, uri, http.MethodGet, nil, ErrTiDBClientRequestFailed, distro.Data("tidb"))
if err != nil && c.forwarder.statusProxy.noAliveRemote.Load() {
return nil, ErrNoAliveTiDB.NewWithNoMessage()
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/tidb/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go.etcd.io/etcd/clientv3"
"go.uber.org/fx"

"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
"github.com/pingcap/tidb-dashboard/pkg/utils/topology"
)

Expand Down Expand Up @@ -115,7 +116,7 @@ func (f *Forwarder) pollingForTiDB() {

func (f *Forwarder) getEndpointAddr(port int) (string, error) {
if f.statusProxy.noAliveRemote.Load() {
log.Warn("Unable to resolve connection address since no alive TiDB instance")
log.Warn(fmt.Sprintf("Unable to resolve connection address since no alive %s instance", distro.Data("tidb")))
return "", ErrNoAliveTiDB.NewWithNoMessage()
}
return fmt.Sprintf("127.0.0.1:%d", port), nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/tiflash/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/pingcap/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/httpc"
"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
)

var (
Expand Down Expand Up @@ -66,7 +67,7 @@ func (c Client) WithTimeout(timeout time.Duration) *Client {

func (c *Client) Get(host string, statusPort int, relativeURI string) (*httpc.Response, error) {
uri := fmt.Sprintf("%s://%s:%d%s", c.httpScheme, host, statusPort, relativeURI)
return c.httpClient.WithTimeout(c.timeout).Send(c.lifecycleCtx, uri, http.MethodGet, nil, ErrFlashClientRequestFailed, "TiFlash")
return c.httpClient.WithTimeout(c.timeout).Send(c.lifecycleCtx, uri, http.MethodGet, nil, ErrFlashClientRequestFailed, distro.Data("tiflash"))
}

func (c *Client) SendGetRequest(host string, statusPort int, relativeURI string) ([]byte, error) {
Expand All @@ -79,5 +80,5 @@ func (c *Client) SendGetRequest(host string, statusPort int, relativeURI string)

func (c *Client) SendPostRequest(host string, statusPort int, relativeURI string, body io.Reader) ([]byte, error) {
uri := fmt.Sprintf("%s://%s:%d%s", c.httpScheme, host, statusPort, relativeURI)
return c.httpClient.WithTimeout(c.timeout).SendRequest(c.lifecycleCtx, uri, http.MethodPost, body, ErrFlashClientRequestFailed, "TiFlash")
return c.httpClient.WithTimeout(c.timeout).SendRequest(c.lifecycleCtx, uri, http.MethodPost, body, ErrFlashClientRequestFailed, distro.Data("tiflash"))
}
5 changes: 3 additions & 2 deletions pkg/tikv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/pingcap/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/httpc"
"github.com/pingcap/tidb-dashboard/pkg/utils/distro"
)

var (
Expand Down Expand Up @@ -66,7 +67,7 @@ func (c Client) WithTimeout(timeout time.Duration) *Client {

func (c *Client) Get(host string, statusPort int, relativeURI string) (*httpc.Response, error) {
uri := fmt.Sprintf("%s://%s:%d%s", c.httpScheme, host, statusPort, relativeURI)
return c.httpClient.WithTimeout(c.timeout).Send(c.lifecycleCtx, uri, http.MethodGet, nil, ErrTiKVClientRequestFailed, "TiKV")
return c.httpClient.WithTimeout(c.timeout).Send(c.lifecycleCtx, uri, http.MethodGet, nil, ErrTiKVClientRequestFailed, distro.Data("tikv"))
}

func (c *Client) SendGetRequest(host string, statusPort int, relativeURI string) ([]byte, error) {
Expand All @@ -79,5 +80,5 @@ func (c *Client) SendGetRequest(host string, statusPort int, relativeURI string)

func (c *Client) SendPostRequest(host string, statusPort int, relativeURI string, body io.Reader) ([]byte, error) {
uri := fmt.Sprintf("%s://%s:%d%s", c.httpScheme, host, statusPort, relativeURI)
return c.httpClient.WithTimeout(c.timeout).SendRequest(c.lifecycleCtx, uri, http.MethodPost, body, ErrTiKVClientRequestFailed, "TiKV")
return c.httpClient.WithTimeout(c.timeout).SendRequest(c.lifecycleCtx, uri, http.MethodPost, body, ErrTiKVClientRequestFailed, distro.Data("tikv"))
}
1 change: 1 addition & 0 deletions pkg/utils/distro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/distro_info.go
10 changes: 10 additions & 0 deletions pkg/utils/distro/default_distro_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build !distro

package distro

var Resource = map[string]interface{}{
"tidb": "TiDB",
"tikv": "TiKV",
"tiflash": "TiFlash",
"pd": "PD",
}
25 changes: 25 additions & 0 deletions pkg/utils/distro/distro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2021 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,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package distro

var data map[string]interface{}

func Replace(distro map[string]interface{}) {
data = distro
}

func Data(k string) string {
return data[k].(string)
}
21 changes: 21 additions & 0 deletions pkg/utils/distro/populate/populate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2021 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,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package populate

import "github.com/pingcap/tidb-dashboard/pkg/utils/distro"

func init() {
distro.Replace(distro.Resource)
}

0 comments on commit 61cbaec

Please sign in to comment.