Skip to content

Commit

Permalink
update tidb-dashboard to 2021.12.31.1 (tikv#4502)
Browse files Browse the repository at this point in the history
ref tikv#4257

support dynamic distro res

make `DASHBOARD=COMPILE make pd-server` works

Signed-off-by: baurine <[email protected]>
  • Loading branch information
baurine authored Dec 31, 2021
1 parent 59991d5 commit 97596b1
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 203 deletions.
53 changes: 0 additions & 53 deletions .github/workflows/check-dashboard.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
~/go/pkg/mod
~/.cache/go-build
**/.tools
**/.dashboard_asset_cache
**/.dashboard_download_cache
key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pd-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
~/go/pkg/mod
~/.cache/go-build
**/.tools
**/.dashboard_asset_cache
**/.dashboard_download_cache
key: ${{ runner.os }}-go-${{ matrix.worker_id }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.worker_id }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ vendor
default*
*.bak
.vscode/
/.dashboard_asset_cache
/.dashboard_download_cache
/.dashboard_build_temp
/.tools/bin
docs/swagger/*
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ clean-test:

clean-build:
# Cleaning building files...
rm -rf .dashboard_asset_cache/
rm -rf .dashboard_download_cache/
rm -rf $(BUILD_BIN_PATH)
rm -rf $(GO_TOOLS_BIN_PATH)

Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ require (
github.com/mgechev/revive v1.0.2
github.com/montanaflynn/stats v0.5.0
github.com/opentracing/opentracing-go v1.1.0
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 // indirect
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d
github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712
github.com/pingcap/errcode v0.3.0
github.com/pingcap/errors v0.11.5-0.20201126102027-b0a155152ca3
github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce
github.com/pingcap/kvproto v0.0.0-20211213085605-3329b3c5404c
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354
github.com/pingcap/sysutil v0.0.0-20211208032423-041a72e5860d
github.com/pingcap/tidb-dashboard v0.0.0-20211206031355-bcc43a01d537
github.com/pingcap/tidb-dashboard v0.0.0-20211231024458-18087fcc06d7
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/common v0.6.0
github.com/sasha-s/go-deadlock v0.2.0
github.com/sirupsen/logrus v1.2.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba
Expand All @@ -47,10 +47,9 @@ require (
github.com/unrolled/render v1.0.1
github.com/urfave/negroni v0.3.0
// Fix panic in unit test with go >= 1.14, ref: etcd-io/bbolt#201 https://github.com/etcd-io/bbolt/pull/201
go.etcd.io/bbolt v1.3.5 // indirect
go.etcd.io/etcd v0.5.0-alpha.5.0.20191023171146-3cf2f69b5738
go.uber.org/goleak v1.1.12
go.uber.org/zap v1.16.0
go.uber.org/zap v1.19.0
golang.org/x/tools v0.1.5
google.golang.org/grpc v1.26.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
Expand Down
233 changes: 157 additions & 76 deletions go.sum

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/dashboard/adapter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func GenDashboardConfig(srv *server.Server) (*config.Config, error) {
dashboardCfg.PublicPathPrefix = cfg.Dashboard.PublicPathPrefix
dashboardCfg.EnableTelemetry = cfg.Dashboard.EnableTelemetry
dashboardCfg.EnableExperimental = cfg.Dashboard.EnableExperimental
dashboardCfg.EnableNonRootLogin = true
if dashboardCfg.ClusterTLSConfig, err = cfg.Security.ToTLSConfig(); err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import (
"github.com/pingcap/tidb-dashboard/pkg/uiserver"

"github.com/tikv/pd/pkg/dashboard/adapter"
// inject distro information to dashboard
_ "github.com/tikv/pd/pkg/dashboard/distro"
"github.com/tikv/pd/pkg/dashboard/distroutil"
"github.com/tikv/pd/pkg/dashboard/keyvisual"
ui "github.com/tikv/pd/pkg/dashboard/uiserver"
"github.com/tikv/pd/server"
Expand Down Expand Up @@ -70,6 +69,8 @@ func GetServiceBuilders() []server.HandlerBuilder {
return []server.HandlerBuilder{
// Dashboard API Service
func(ctx context.Context, srv *server.Server) (http.Handler, server.ServiceGroup, error) {
distroutil.MustLoadAndReplaceStrings()

if cfg, err = adapter.GenDashboardConfig(srv); err != nil {
return nil, apiServiceGroup, err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/dashboard/distro/.gitignore

This file was deleted.

26 changes: 0 additions & 26 deletions pkg/dashboard/distro/distro.go

This file was deleted.

15 changes: 0 additions & 15 deletions pkg/dashboard/distro/placeholder.go

This file was deleted.

53 changes: 53 additions & 0 deletions pkg/dashboard/distroutil/distro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2021 TiKV Project Authors.
//
// 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 distroutil

import (
"os"
"path"

"github.com/pingcap/log"
"github.com/pingcap/tidb-dashboard/util/distro"
"go.uber.org/zap"
)

const (
resFolderName string = "distro-res"
stringsFileName string = "strings.json"
)

// MustGetResPath returns the default path that a distribution resource should be placed,
// which is the ${BinaryPath}/distro-res.
func MustGetResPath() string {
exePath, err := os.Executable()
if err != nil {
log.Fatal("Failed to read the execution path", zap.Error(err))
return ""
}
return path.Join(path.Dir(exePath), resFolderName)
}

// MustLoadAndReplaceStrings loads the distro strings from ${BinaryPath}/distro-res/strings.json
// and replace the strings in the TiDB Dashboard. If the strings file does not exist, the default
// distro string will be used.
func MustLoadAndReplaceStrings() {
resPath := MustGetResPath()
strings, err := distro.ReadResourceStringsFromFile(path.Join(resPath, stringsFileName))
if err != nil {
log.Fatal("Failed to load distro strings", zap.Error(err))
}
log.Info("Using distribution strings", zap.Any("strings", strings))
distro.ReplaceGlobal(strings)
}
4 changes: 3 additions & 1 deletion pkg/dashboard/uiserver/embedded_assets_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import (

"github.com/pingcap/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/uiserver"
"github.com/tikv/pd/pkg/dashboard/distroutil"
)

var once sync.Once

// Assets returns the Assets FileSystem of the dashboard UI
func Assets(cfg *config.Config) http.FileSystem {
once.Do(func() {
uiserver.RewriteAssets(assets, cfg, func(fs http.FileSystem, f http.File, path, newContent string, bs []byte) {
resPath := distroutil.MustGetResPath()
uiserver.RewriteAssets(assets, cfg, resPath, func(fs http.FileSystem, f http.File, path, newContent string, bs []byte) {
m := fs.(vfsgen۰FS)
fi := f.(os.FileInfo)
m[path] = &vfsgen۰CompressedFileInfo{
Expand Down
2 changes: 1 addition & 1 deletion scripts/embed-dashboard-ui.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition
$BASE_DIR = (get-item $DIR).parent.FullName
$CACHE_DIR = Join-Path($BASE_DIR) "\.dashboard_asset_cache"
$CACHE_DIR = Join-Path($BASE_DIR) "\.dashboard_download_cache"

echo '+ Create asset cache directory'

Expand Down
58 changes: 41 additions & 17 deletions scripts/embed-dashboard-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,16 @@ go mod tidy
DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap/tidb-dashboard)
echo " - TiDB Dashboard directory: ${DASHBOARD_DIR}"

CACHE_DIR=${BASE_DIR}/.dashboard_download_cache
echo "+ Create download cache directory: ${CACHE_DIR}"
mkdir -p "${CACHE_DIR}"

function download_embed_asset {
CACHE_DIR=${BASE_DIR}/.dashboard_asset_cache

echo '+ Create asset cache directory'
mkdir -p "${CACHE_DIR}"

echo '+ Discover TiDB Dashboard release version'
DASHBOARD_RELEASE_VERSION=$(grep -v '^#' "${DASHBOARD_DIR}/release-version")
echo " - TiDB Dashboard release version: ${DASHBOARD_RELEASE_VERSION}"

echo '+ Check embedded assets exists in cache'
echo '+ Check whether pre-built assets are available'
CACHE_FILE=${CACHE_DIR}/embedded-assets-golang-${DASHBOARD_RELEASE_VERSION}.zip
if [[ -f "$CACHE_FILE" ]]; then
echo " - Cached archive exists: ${CACHE_FILE}"
Expand Down Expand Up @@ -86,7 +84,8 @@ function download_embed_asset {
function compile_asset {
BUILD_DIR=${BASE_DIR}/.dashboard_build_temp

echo '+ Clean up TiDB Dashboard build directory'
echo '+ Compiling TiDB Dashboard UI from source code'
echo '+ Clean up build directory'
echo " - Build directory: ${DASHBOARD_DIR}"
if [ -d "${BUILD_DIR}/ui/node_modules" ]; then
echo " - Build dependency exists, keep dependency cache"
Expand All @@ -99,22 +98,47 @@ function compile_asset {
mkdir -p "${BUILD_DIR}/ui"
fi

echo '+ Copy TiDB Dashboard source code to build directory'
echo " - Src: ${DASHBOARD_DIR}"
echo '+ Discover referenced TiDB Dashboard commit'
DASHBOARD_SHA=$(echo "${DASHBOARD_DIR}" | awk -F '-' '{print $NF}')
CACHE_FILE=${CACHE_DIR}/tidb-dashboard-${DASHBOARD_SHA}.zip
echo " - TiDB Dashboard commit: ${DASHBOARD_SHA}"

echo '+ Check whether UI source code was downloaded'
if [[ -f "$CACHE_FILE" ]]; then
echo " - Source code archive exists: ${CACHE_FILE}"
else
echo ' - Source code archive does not exist'
echo ' - Download source code archive from GitHub'

DOWNLOAD_URL="https://github.com/pingcap/tidb-dashboard/archive/${DASHBOARD_SHA}.zip"
DOWNLOAD_FILE=${CACHE_DIR}/tidb-dashboard.zip
echo " - Download ${DOWNLOAD_URL}"
if ! curl -L "${DOWNLOAD_URL}" --fail --output "${DOWNLOAD_FILE}"; then
echo
echo -e "${RED}Error: Failed to download TiDB Dashboard source code archive.${NC}"
exit 1
fi

mv "${DOWNLOAD_FILE}" "${CACHE_FILE}"
echo " - Source code archive downloaded to: ${CACHE_FILE}"
fi

echo '+ Unpack source code archive'
DASHBOARD_FULL_SHA=$(unzip -l "${CACHE_FILE}" | sed -n '2p')
DASHBOARD_UNZIP_PATH=/tmp/tidb-dashboard-${DASHBOARD_FULL_SHA}
unzip -o "${CACHE_FILE}" -d /tmp

echo '+ Copy unpacked source code to build directory'
echo " - Src: ${DASHBOARD_UNZIP_PATH}"
echo " - Dest: ${BUILD_DIR}"
cp -r "${DASHBOARD_DIR}/." "${BUILD_DIR}/"
cp -r "${DASHBOARD_UNZIP_PATH}/." "${BUILD_DIR}/"

chmod -R u+w "${BUILD_DIR}"
chmod u+x "${BUILD_DIR}"/scripts/*.sh

echo '+ Build UI'
cd "${BUILD_DIR}"

if [ -n "${DISTRIBUTION_DIR}" ]; then
DISTRIBUTION_DIR=${DISTRIBUTION_DIR} scripts/replace_distro_resource.sh
DISTRO_BUILD_TAG=1 make ui
else
make ui
fi
make ui

echo '+ Generating UI assets'
echo ' - Generating...'
Expand Down

0 comments on commit 97596b1

Please sign in to comment.