Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2021.12.30.1 [skip pd_pr] #1113

Merged
merged 36 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a28d3fc
Revert "Release v2021.12.06.1 (#1084)"
baurine Dec 30, 2021
ee4d16d
Compitable with different TiDB versions for conprof and non-root-logi…
baurine Nov 10, 2021
b8399a9
build(deps): bump ws from 5.2.2 to 5.2.3 in /ui (#1055)
dependabot[bot] Nov 10, 2021
975d426
CICD: Update the release pipeline for recent PD format policies (#1054)
breezewish Nov 10, 2021
6d63f33
fix i18n wording (#1056)
baurine Nov 10, 2021
f47da2e
Refactor: Change util module to util package (#1052)
breezewish Nov 11, 2021
d9c5a56
Refactor: Fix godot incorrectly add dot suffix to annotations (#1059)
breezewish Nov 11, 2021
b6560ae
lint: Add goheader for copyright lints (#1062)
breezewish Nov 12, 2021
877899a
Refactor: Migrate to use the `rest` package in util/ (#1060)
breezewish Nov 22, 2021
50daa9e
fix(*): globally delete/update data by GORM (#1065)
shhdgit Nov 22, 2021
819a45a
ui: bump dependencies (#1066)
breezewish Nov 23, 2021
bd90f01
refactor: Switch to use ziputil, netutil, reflectutil and fileswap (#…
breezewish Nov 24, 2021
926c58c
Fix request header being pinned after pd profiling (#1069)
shhdgit Nov 25, 2021
9af1a84
Integrate speedscope (#1064)
YiniXu9506 Nov 29, 2021
2d2ab19
fix potential panic when GetPDInstances (#1075)
crazycs520 Nov 30, 2021
78fafc2
Refactor: a new httpclient (#1073)
breezewish Dec 1, 2021
3db85c2
Refactor: Switch to use util/distro in all places (#1078)
breezewish Dec 1, 2021
3728b24
chore: support import relative file URL (#1082)
YiniXu9506 Dec 5, 2021
1a7d6e1
Refactor: Move tools into a standalone module (#1079)
breezewish Dec 6, 2021
f98b8f4
Fix script to embed the ui (#1088)
breezewish Dec 8, 2021
b858495
Refactor feature flag to support more modules (#1057)
shhdgit Dec 8, 2021
1b47110
Drop sysutil dependency (#1093)
breezewish Dec 10, 2021
f9dd2d7
chore: add graph generation (#1085)
YiniXu9506 Dec 14, 2021
37341db
Refactor: Add TopologyProvider (#1098)
breezewish Dec 16, 2021
0148da5
esbuild: i18n + dep (#1101)
baurine Dec 16, 2021
564c6a5
script: Add a script to generate version matrix (#1104)
breezewish Dec 21, 2021
e9caf73
distro: support dynamic config (#1094)
baurine Dec 22, 2021
6bdcdf2
chore: support multiple profiling types (#1095)
YiniXu9506 Dec 22, 2021
eefe543
fix(distro): check distro_strings.json fmt by prettier (#1106)
shhdgit Dec 22, 2021
daeb3a2
script: fix generate assets (#1107)
baurine Dec 27, 2021
14f6a34
Add integration test (#1083)
shhdgit Dec 27, 2021
c4f3719
debug_api: Switch to use the new util (#1103)
breezewish Dec 27, 2021
2214f60
refactor(ui): auto refresh button (#1105)
shhdgit Dec 28, 2021
cc3bc17
ui: refine conprof (#1102)
baurine Dec 29, 2021
1a7c822
update release-version
baurine Dec 30, 2021
9d6b17a
sync with master
baurine Dec 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
distro: support dynamic config (#1094)
  • Loading branch information
baurine committed Dec 30, 2021
commit e9caf735905e7782e0ccfbe9b7e175e1f5f11978
27 changes: 25 additions & 2 deletions cmd/tidb-dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
_ "net/http/pprof" // #nosec
"os"
"os/signal"
"path"
"strings"
"sync"
"syscall"
Expand All @@ -31,13 +32,13 @@ import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

_ "github.com/pingcap/tidb-dashboard/internal/resource/distrores"
"github.com/pingcap/tidb-dashboard/pkg/apiserver"
"github.com/pingcap/tidb-dashboard/pkg/config"
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/version"
"github.com/pingcap/tidb-dashboard/util/distro"
)

type DashboardCLIConfig struct {
Expand Down Expand Up @@ -147,6 +148,26 @@ func buildTLSConfig(caPath, keyPath, certPath *string) *tls.Config {
return tlsConfig
}

const (
distroResFolderName string = "distro-res"
distroStringsResFileName string = "strings.json"
)

func loadDistroStringsRes() {
exePath, err := os.Executable()
if err != nil {
log.Fatal("Failed to get executable path", zap.Error(err))
}

distroStringsResPath := path.Join(path.Dir(exePath), distroResFolderName, distroStringsResFileName)
distroStringsRes, err := distro.ReadResourceStringsFromFile(distroStringsResPath)
if err != nil {
log.Fatal("Failed to load distro strings res", zap.String("path", distroStringsResPath), zap.Error(err))
}

distro.ReplaceGlobal(distroStringsRes)
}

func main() {
// Flushing any buffered log entries
defer log.Sync() //nolint:errcheck
Expand All @@ -164,10 +185,12 @@ func main() {
log.SetLevel(zapcore.DebugLevel)
}

loadDistroStringsRes()

listenAddr := fmt.Sprintf("%s:%d", cliConfig.ListenHost, cliConfig.ListenPort)
listener, err := net.Listen("tcp", listenAddr)
if err != nil {
log.Fatal("TiDB Dashboard server listen failed", zap.String("addr", listenAddr), zap.Error(err))
log.Fatal("Dashboard server listen failed", zap.String("addr", listenAddr), zap.Error(err))
}

var customKeyVisualProvider *keyvisualregion.DataProvider
Expand Down
11 changes: 0 additions & 11 deletions internal/resource/distrores/populate.go

This file was deleted.

11 changes: 0 additions & 11 deletions internal/resource/distrores/strings.go

This file was deleted.

12 changes: 11 additions & 1 deletion pkg/uiserver/embedded_assets_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,27 @@ package uiserver
import (
"net/http"
"os"
"path"
"sync"
"time"

"go.uber.org/zap"

"github.com/pingcap/log"
"github.com/pingcap/tidb-dashboard/pkg/config"
)

var once sync.Once

func Assets(cfg *config.Config) http.FileSystem {
once.Do(func() {
RewriteAssets(assets, cfg, func(fs http.FileSystem, f http.File, path, newContent string, bs []byte) {
exePath, err := os.Executable()
if err != nil {
log.Fatal("Failed to get executable path", zap.Error(err))
}

distroResFolderPath := path.Join(path.Dir(exePath), distroResFolderName)
RewriteAssets(assets, cfg, distroResFolderPath, 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
76 changes: 75 additions & 1 deletion pkg/uiserver/uiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,32 @@ package uiserver
import (
"bytes"
"compress/gzip"
"encoding/base64"
"encoding/json"
"errors"
"html"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"strings"

"github.com/pingcap/log"
"github.com/shurcooL/httpgzip"
"go.uber.org/zap"

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

const (
distroResFolderName = "distro-res"
)

type UpdateContentFunc func(fs http.FileSystem, oldFile http.File, path, newContent string, zippedBytes []byte)

func RewriteAssets(fs http.FileSystem, cfg *config.Config, updater UpdateContentFunc) {
func RewriteAssets(fs http.FileSystem, cfg *config.Config, distroResFolderPath string, updater UpdateContentFunc) {
if fs == nil {
return
}
Expand All @@ -39,6 +49,9 @@ func RewriteAssets(fs http.FileSystem, cfg *config.Config, updater UpdateContent
tmplText := string(bs)
updated := strings.ReplaceAll(tmplText, "__PUBLIC_PATH_PREFIX__", html.EscapeString(cfg.PublicPathPrefix))

distroStrings, _ := json.Marshal(distro.R()) // this will never fail
updated = strings.ReplaceAll(updated, "__DISTRO_STRINGS_RES__", base64.StdEncoding.EncodeToString(distroStrings))

var b bytes.Buffer
w := gzip.NewWriter(&b)
if _, err := w.Write([]byte(updated)); err != nil {
Expand All @@ -53,6 +66,67 @@ func RewriteAssets(fs http.FileSystem, cfg *config.Config, updater UpdateContent

rewrite("/index.html")
rewrite("/diagnoseReport.html")

if err := overrideDistroAssetsRes(fs, distroResFolderPath, updater); err != nil {
log.Fatal("Failed to load distro assets res", zap.Error(err))
}
}

func overrideDistroAssetsRes(fs http.FileSystem, distroResFolderPath string, updater UpdateContentFunc) error {
info, err := os.Stat(distroResFolderPath)
if errors.Is(err, os.ErrNotExist) || !info.IsDir() {
// just ignore if the folder doesn't exist or it's not a folder
return nil
}
if err != nil {
return err
}

// traverse
files, err := ioutil.ReadDir(distroResFolderPath)
if err != nil {
return err
}
for _, file := range files {
if err := overrideSingleDistroAsset(fs, distroResFolderPath, file.Name(), updater); err != nil {
return err
}
}
return nil
}

func overrideSingleDistroAsset(fs http.FileSystem, distroResFolderPath, assetName string, updater UpdateContentFunc) error {
assetPath := path.Join("/", distroResFolderName, assetName)
targetFile, err := fs.Open(assetPath)
if err != nil {
// has no target asset to be overried, skip
return nil
}
defer targetFile.Close()

assetFullPath := path.Join(distroResFolderPath, assetName)
sourceFile, err := os.Open(assetFullPath)
if err != nil {
return err
}
defer sourceFile.Close()

data, err := ioutil.ReadAll(sourceFile)
if err != nil {
return err
}

var b bytes.Buffer
w := gzip.NewWriter(&b)
if _, err := w.Write(data); err != nil {
return err
}
if err := w.Close(); err != nil {
return err
}

updater(fs, targetFile, assetPath, string(data), b.Bytes())
return nil
}

func Handler(root http.FileSystem) http.Handler {
Expand Down
28 changes: 0 additions & 28 deletions scripts/distro/replace_resources.sh

This file was deleted.

1 change: 0 additions & 1 deletion scripts/distro/write_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/pingcap/log"
"go.uber.org/zap"

_ "github.com/pingcap/tidb-dashboard/internal/resource/distrores"
"github.com/pingcap/tidb-dashboard/util/distro"
)

Expand Down
18 changes: 5 additions & 13 deletions scripts/distro/write_strings.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
#!/usr/bin/env bash

# This script writes distribution strings in json which is required for the frontend.
# This script outputs distribution strings to json which is required for the frontend.

set -euo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PROJECT_DIR=$(cd "$DIR/../.."; pwd)
BUILD_TAG=""

if [[ -f "${PROJECT_DIR}/internal/resource/distrores/strings.go" ]]; then
echo "+ Existing distribution resource is detected, using it to write strings"
BUILD_TAG=distro
fi

echo "+ Write resource strings"
echo "+ Write distro strings"
cd "$PROJECT_DIR"
# FIXME: distro/write_strings needs to access the /internal package, which is not allowed to be invoked in another module
# Currently we workaround this by invoking in the TiDB Dashboard module.
go run -tags="${BUILD_TAG}" scripts/distro/write_strings.go -o="${PROJECT_DIR}/ui/lib/distribution.json"
go run scripts/distro/write_strings.go -o="${PROJECT_DIR}/ui/lib/distro_strings.json"

echo " - Success! Resource strings:"
cat "${PROJECT_DIR}/ui/lib/distribution.json"
echo " - Success! Distro strings:"
cat "${PROJECT_DIR}/ui/lib/distro_strings.json"

echo
43 changes: 32 additions & 11 deletions ui/config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const fs = require('fs')
const fs = require('fs-extra')
const os = require('os')
const {
override,
Expand All @@ -17,16 +17,37 @@ const WebpackBar = require('webpackbar')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const rewireHtmlWebpackPlugin = require('react-app-rewire-html-webpack-plugin')

function copyDistroRes() {
const distroResPath = '../bin/distro-res'
if (fs.existsSync(distroResPath)) {
fs.copySync(distroResPath, './public/distro-res')
}
}

function injectDistroToHTML(config, env) {
const distroInfo = Object.entries(require('./lib/distribution.json')).reduce(
(prev, [k, v]) => {
return {
...prev,
[`distro_${k}`]: v,
}
let distroStringsResMeta = '__DISTRO_STRINGS_RES__'

// For dev mode,
// we copy distro assets from bin/distro-res to public/distro-res to override the default assets,
// read distro strings res from public/distro-res/strings.json and encode it by base64 if it exists.
// For production mode, we keep the "__DISTRO_STRINGS_RES__" value, it will be replaced by the backend RewriteAssets() method in the run time.
if (isBuildAsDevServer()) {
copyDistroRes()

const distroStringsResFilePath = './public/distro-res/strings.json'
if (fs.existsSync(distroStringsResFilePath)) {
const distroStringsRes = require(distroStringsResFilePath)
distroStringsResMeta = btoa(JSON.stringify(distroStringsRes))
}
}

// Store the distro strings res in the html head meta,
// HtmlWebpacPlugin will write this meta into the html head.
const distroInfo = {
meta: {
'x-distro-strings-res': distroStringsResMeta,
},
{}
)
}
return rewireHtmlWebpackPlugin(config, env, distroInfo)
}

Expand Down Expand Up @@ -183,10 +204,10 @@ module.exports = override(
)
),
disableMinimizeByEnv(),
addExtraEntries(),
supportDynamicPublicPathPrefix(),
overrideProcessEnv({
REACT_APP_RELEASE_VERSION: JSON.stringify(getInternalVersion()),
}),
injectDistroToHTML
injectDistroToHTML,
addExtraEntries()
)
3 changes: 3 additions & 0 deletions ui/dashboardApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AppRegistry from '@lib/utils/registry'
import * as routing from '@lib/utils/routing'
import * as auth from '@lib/utils/auth'
import * as i18n from '@lib/utils/i18n'
import { distro } from '@lib/utils/i18n'
import { saveAppOptions, loadAppOptions } from '@lib/utils/appOptions'
import {
initSentryRoutingInstrument,
Expand Down Expand Up @@ -148,6 +149,8 @@ async function webPageStart() {
}

async function main() {
document.title = `${distro.tidb} Dashboard`

if (routing.isPortalPage()) {
// the portal page is only used to receive options
function handlePortalEvent(event) {
Expand Down
Loading