From f1fb830de0463ae4397c0619764e971606eb36fd Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Thu, 23 May 2024 16:08:42 +0800 Subject: [PATCH 01/13] command: replace doRequest of HTTP client to get health status Signed-off-by: okJiang <819421878@qq.com> --- client/http/api.go | 1 + client/http/interface.go | 14 ++++++++++++++ client/http/request_info.go | 1 + client/http/types.go | 9 +++++++++ tools/pd-ctl/pdctl/command/health_command.go | 17 +++++++---------- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/client/http/api.go b/client/http/api.go index a1ca96b38f1..3376a48770d 100644 --- a/client/http/api.go +++ b/client/http/api.go @@ -41,6 +41,7 @@ const ( membersPrefix = "/pd/api/v1/members" leaderPrefix = "/pd/api/v1/leader" transferLeader = "/pd/api/v1/leader/transfer" + health = "/pd/api/v1/health" // Config Config = "/pd/api/v1/config" ClusterVersion = "/pd/api/v1/config/cluster-version" diff --git a/client/http/interface.go b/client/http/interface.go index 7b15291d9e7..76fe133f1ac 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -50,6 +50,7 @@ type Client interface { GetStores(context.Context) (*StoresInfo, error) GetStore(context.Context, uint64) (*StoreInfo, error) SetStoreLabels(context.Context, int64, map[string]string) error + GetHealthStatus(context.Context) ([]Health, error) /* Config-related interfaces */ GetConfig(context.Context) (map[string]any, error) SetConfig(context.Context, map[string]any, ...float64) error @@ -337,6 +338,19 @@ func (c *client) SetStoreLabels(ctx context.Context, storeID int64, storeLabels WithBody(jsonInput)) } +func (c *client) GetHealthStatus(ctx context.Context) ([]Health, error) { + var healths []Health + err := c.request(ctx, newRequestInfo(). + WithName(getHealthName). + WithURI(health). + WithMethod(http.MethodGet). + WithResp(&healths)) + if err != nil { + return nil, err + } + return healths, nil +} + // GetConfig gets the configurations. func (c *client) GetConfig(ctx context.Context) (map[string]any, error) { var config map[string]any diff --git a/client/http/request_info.go b/client/http/request_info.go index 0ce7072d1ba..38fe831f42a 100644 --- a/client/http/request_info.go +++ b/client/http/request_info.go @@ -39,6 +39,7 @@ const ( getStoresName = "GetStores" getStoreName = "GetStore" setStoreLabelsName = "SetStoreLabels" + getHealthName = "GetHealth" getConfigName = "GetConfig" setConfigName = "SetConfig" getScheduleConfigName = "GetScheduleConfig" diff --git a/client/http/types.go b/client/http/types.go index 31b2bfdaea7..f7273068b8c 100644 --- a/client/http/types.go +++ b/client/http/types.go @@ -661,3 +661,12 @@ func stringToKeyspaceState(str string) (keyspacepb.KeyspaceState, error) { return keyspacepb.KeyspaceState(0), fmt.Errorf("invalid KeyspaceState string: %s", str) } } + +// Health reflects the cluster's health. +// NOTE: This type is moved from `server/api/health.go`, maybe move them to the same place later. +type Health struct { + Name string `json:"name"` + MemberID uint64 `json:"member_id"` + ClientUrls []string `json:"client_urls"` + Health bool `json:"health"` +} diff --git a/tools/pd-ctl/pdctl/command/health_command.go b/tools/pd-ctl/pdctl/command/health_command.go index 50ac7763d28..96a0e9069c2 100644 --- a/tools/pd-ctl/pdctl/command/health_command.go +++ b/tools/pd-ctl/pdctl/command/health_command.go @@ -15,30 +15,27 @@ package command import ( - "net/http" + "context" "github.com/spf13/cobra" ) -var ( - healthPrefix = "pd/api/v1/health" -) - // NewHealthCommand return a health subcommand of rootCmd func NewHealthCommand() *cobra.Command { m := &cobra.Command{ - Use: "health", - Short: "show all node's health information of the pd cluster", - Run: showHealthCommandFunc, + Use: "health", + Short: "show all node's health information of the pd cluster", + PersistentPreRunE: requirePDClient, + Run: showHealthCommandFunc, } return m } func showHealthCommandFunc(cmd *cobra.Command, _ []string) { - r, err := doRequest(cmd, healthPrefix, http.MethodGet, http.Header{}) + health, err := PDCli.GetHealthStatus(context.Background()) if err != nil { cmd.Println(err) return } - cmd.Println(r) + jsonPrint(cmd, health) } From ee483b04873ed050b0e2c75a08c78c0c29b309d8 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Thu, 23 May 2024 16:14:55 +0800 Subject: [PATCH 02/13] add a note Signed-off-by: okJiang <819421878@qq.com> --- pkg/dashboard/uiserver/embedded_assets_rewriter.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/dashboard/uiserver/embedded_assets_rewriter.go b/pkg/dashboard/uiserver/embedded_assets_rewriter.go index 2a5b4a5b3b6..d19db01936f 100644 --- a/pkg/dashboard/uiserver/embedded_assets_rewriter.go +++ b/pkg/dashboard/uiserver/embedded_assets_rewriter.go @@ -28,6 +28,7 @@ import ( var once sync.Once // Assets returns the Assets FileSystem of the dashboard UI +// NOTE: if you see "undefined: assets" error, please run `make dashboard-ui` in the root directory of the repository. func Assets(cfg *config.Config) http.FileSystem { once.Do(func() { resPath := distroutil.MustGetResPath() From 9f609790faed7f8cceaef9aa02f99596ac7f24ca Mon Sep 17 00:00:00 2001 From: Hu# Date: Thu, 23 May 2024 10:08:47 +0800 Subject: [PATCH 03/13] tools/ut: add a parallel parameter (#8186) ref tikv/pd#7969 add parallel parameter Signed-off-by: husharp Signed-off-by: okJiang <819421878@qq.com> --- tools/pd-ut/ut.go | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/tools/pd-ut/ut.go b/tools/pd-ut/ut.go index 7781ab4ee3b..fbf2a640651 100644 --- a/tools/pd-ut/ut.go +++ b/tools/pd-ut/ut.go @@ -95,8 +95,7 @@ var ( var ( // runtime - p int - buildParallel int + parallel int workDir string coverFileTempDir string // arguments @@ -108,6 +107,7 @@ var ( func main() { race = handleFlag("--race") + parallelStr := stripFlag("--parallel") junitFile = stripFlag("--junitfile") coverProfile = stripFlag("--coverprofile") ignoreDir = stripFlag("--ignore") @@ -122,11 +122,21 @@ func main() { defer os.RemoveAll(coverFileTempDir) } - // Get the correct count of CPU if it's in docker. - p = runtime.GOMAXPROCS(0) - // We use 2 * p for `go build` to make it faster. - buildParallel = p * 2 var err error + procs := runtime.GOMAXPROCS(0) + if parallelStr == "" { + // Get the correct count of CPU if it's in docker. + parallel = procs + } else { + parallel, err = strconv.Atoi(parallelStr) + if err != nil { + fmt.Println("parse parallel error", err) + return + } + if parallel > procs { + fmt.Printf("Recommend to set parallel be same as the GOMAXPROCS=%d\n", procs) + } + } workDir, err = os.Getwd() if err != nil { fmt.Println("os.Getwd() error", err) @@ -353,12 +363,12 @@ func cmdRun(args ...string) bool { } } - fmt.Printf("building task finish, parallelism=%d, count=%d, takes=%v\n", buildParallel, len(tasks), time.Since(start)) + fmt.Printf("building task finish, parallelism=%d, count=%d, takes=%v\n", parallel*2, len(tasks), time.Since(start)) taskCh := make(chan task, 100) - works := make([]numa, p) + works := make([]numa, parallel) var wg sync.WaitGroup - for i := 0; i < p; i++ { + for i := 0; i < parallel; i++ { wg.Add(1) go works[i].worker(&wg, taskCh) } @@ -400,7 +410,7 @@ func cmdRun(args ...string) bool { // stripFlag strip the '--flag xxx' from the command line os.Args // Example of the os.Args changes -// Before: ut run pkg TestXXX --coverprofile xxx --junitfile yyy +// Before: ut run pkg TestXXX --coverprofile xxx --junitfile yyy --parallel 16 // After: ut run pkg TestXXX // The value of the flag is returned. func stripFlag(flag string) string { @@ -636,7 +646,7 @@ func (*numa) testCommand(pkg string, fn string) *exec.Cmd { args = append(args, "-test.coverprofile", tmpFile) } if strings.Contains(fn, "Suite") { - args = append(args, "-test.cpu", fmt.Sprint(p/2)) + args = append(args, "-test.cpu", fmt.Sprint(parallel/2)) } else { args = append(args, "-test.cpu", "1") } @@ -705,7 +715,8 @@ func buildTestBinaryMulti(pkgs []string) error { packages = append(packages, path.Join(modulePath, pkg)) } - p := strconv.Itoa(buildParallel) + // We use 2 * parallel for `go build` to make it faster. + p := strconv.Itoa(parallel * 2) cmd := exec.Command("go", "test", "-p", p, "--exec", xprogPath, "-vet", "off", "--tags=tso_function_test,deadlock") if coverProfile != "" { coverpkg := "./..." From 27a74a51a37ee3c3a674704f93237373548b35af Mon Sep 17 00:00:00 2001 From: ShuNing Date: Thu, 23 May 2024 10:53:46 +0800 Subject: [PATCH 04/13] metrics: fix the duplicate avg metrics (#8210) ref tikv/pd#7897 metrics: fix the duplicate avg metrics Signed-off-by: nolouch Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> Signed-off-by: okJiang <819421878@qq.com> --- metrics/grafana/pd.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/grafana/pd.json b/metrics/grafana/pd.json index a2c3d31a4b0..69afb93f531 100644 --- a/metrics/grafana/pd.json +++ b/metrics/grafana/pd.json @@ -11248,7 +11248,7 @@ }, { "exemplar": true, - "expr": "rate(pd_scheduler_handle_region_heartbeat_duration_seconds_sum{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", store=~\"$store\"}[1m]) / rate(pd_scheduler_handle_region_heartbeat_duration_seconds_count{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", store=~\"$store\"}[1m])", + "expr": "sum(rate(pd_scheduler_handle_region_heartbeat_duration_seconds_sum{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", store=~\"$store\"}[1m])) / sum(rate(pd_scheduler_handle_region_heartbeat_duration_seconds_count{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", store=~\"$store\"}[1m]))", "hide": false, "interval": "", "legendFormat": "avg", From 09bc239e7cbb8b210cd0fc9d7d6571b5c2185454 Mon Sep 17 00:00:00 2001 From: okJiang Date: Thu, 23 May 2024 16:32:19 +0800 Subject: [PATCH 05/13] Apply suggestions from code review Co-authored-by: JmPotato Signed-off-by: okJiang <819421878@qq.com> --- client/http/interface.go | 1 + tools/pd-ctl/pdctl/command/health_command.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/http/interface.go b/client/http/interface.go index 76fe133f1ac..ca14b3ae40f 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -338,6 +338,7 @@ func (c *client) SetStoreLabels(ctx context.Context, storeID int64, storeLabels WithBody(jsonInput)) } +// GetHealthStatus gets the health status of the cluster. func (c *client) GetHealthStatus(ctx context.Context) ([]Health, error) { var healths []Health err := c.request(ctx, newRequestInfo(). diff --git a/tools/pd-ctl/pdctl/command/health_command.go b/tools/pd-ctl/pdctl/command/health_command.go index 96a0e9069c2..9ffe5bb539a 100644 --- a/tools/pd-ctl/pdctl/command/health_command.go +++ b/tools/pd-ctl/pdctl/command/health_command.go @@ -32,7 +32,7 @@ func NewHealthCommand() *cobra.Command { } func showHealthCommandFunc(cmd *cobra.Command, _ []string) { - health, err := PDCli.GetHealthStatus(context.Background()) + health, err := PDCli.GetHealthStatus(cmd.Context()) if err != nil { cmd.Println(err) return From fd7e738d2d8a416f233bb31225fe7dbd7b42f979 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Thu, 23 May 2024 16:50:50 +0800 Subject: [PATCH 06/13] fix comment Signed-off-by: okJiang <819421878@qq.com> --- client/http/interface.go | 2 +- client/http/request_info.go | 2 +- tools/pd-ctl/pdctl/command/health_command.go | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/client/http/interface.go b/client/http/interface.go index ca14b3ae40f..11c24beaefd 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -342,7 +342,7 @@ func (c *client) SetStoreLabels(ctx context.Context, storeID int64, storeLabels func (c *client) GetHealthStatus(ctx context.Context) ([]Health, error) { var healths []Health err := c.request(ctx, newRequestInfo(). - WithName(getHealthName). + WithName(getHealthStatusName). WithURI(health). WithMethod(http.MethodGet). WithResp(&healths)) diff --git a/client/http/request_info.go b/client/http/request_info.go index 38fe831f42a..202eab1150f 100644 --- a/client/http/request_info.go +++ b/client/http/request_info.go @@ -39,7 +39,7 @@ const ( getStoresName = "GetStores" getStoreName = "GetStore" setStoreLabelsName = "SetStoreLabels" - getHealthName = "GetHealth" + getHealthStatusName = "GetHealthStatus" getConfigName = "GetConfig" setConfigName = "SetConfig" getScheduleConfigName = "GetScheduleConfig" diff --git a/tools/pd-ctl/pdctl/command/health_command.go b/tools/pd-ctl/pdctl/command/health_command.go index 9ffe5bb539a..a10ee118397 100644 --- a/tools/pd-ctl/pdctl/command/health_command.go +++ b/tools/pd-ctl/pdctl/command/health_command.go @@ -15,8 +15,6 @@ package command import ( - "context" - "github.com/spf13/cobra" ) @@ -24,7 +22,7 @@ import ( func NewHealthCommand() *cobra.Command { m := &cobra.Command{ Use: "health", - Short: "show all node's health information of the pd cluster", + Short: "show all node's health information of the PD cluster", PersistentPreRunE: requirePDClient, Run: showHealthCommandFunc, } From b1234949e72339bca5805ea7533d7caefd59d159 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Thu, 23 May 2024 17:24:35 +0800 Subject: [PATCH 07/13] fix comment: add ut Signed-off-by: okJiang <819421878@qq.com> --- tests/integrations/client/http_client_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/integrations/client/http_client_test.go b/tests/integrations/client/http_client_test.go index d35b7f00584..62ceb6f1391 100644 --- a/tests/integrations/client/http_client_test.go +++ b/tests/integrations/client/http_client_test.go @@ -811,3 +811,22 @@ func (suite *httpClientTestSuite) checkUpdateKeyspaceGCManagementType(mode mode, re.True(ok) re.Equal(expectGCManagementType, val) } + +func (suite *httpClientTestSuite) TestGetHealthStatus() { + suite.RunTestInTwoModes(suite.checkGetHealthStatus) +} + +func (suite *httpClientTestSuite) checkGetHealthStatus(mode mode, client pd.Client) { + re := suite.Require() + env := suite.env[mode] + + healths, err := client.GetHealthStatus(env.ctx) + re.NoError(err) + re.Len(healths, 2) + sort.Slice(healths, func(i, j int) bool { + return healths[i].Name < healths[j].Name + }) + re.Equal("pd1", healths[0].Name) + re.Equal("pd2", healths[1].Name) + re.Equal(true, healths[0].Health && healths[1].Health) +} From d31faf8cb9e056dcf2d5f89042ff37b93b6acb40 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Thu, 23 May 2024 17:32:24 +0800 Subject: [PATCH 08/13] fix lint Signed-off-by: okJiang <819421878@qq.com> --- tests/integrations/client/http_client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/client/http_client_test.go b/tests/integrations/client/http_client_test.go index 62ceb6f1391..9e712b808f3 100644 --- a/tests/integrations/client/http_client_test.go +++ b/tests/integrations/client/http_client_test.go @@ -828,5 +828,5 @@ func (suite *httpClientTestSuite) checkGetHealthStatus(mode mode, client pd.Clie }) re.Equal("pd1", healths[0].Name) re.Equal("pd2", healths[1].Name) - re.Equal(true, healths[0].Health && healths[1].Health) + re.True(healths[0].Health && healths[1].Health) } From cef9427423f00b4fc36da6c8914c82b287ccf05d Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Fri, 24 May 2024 14:15:29 +0800 Subject: [PATCH 09/13] fix ci Signed-off-by: okJiang <819421878@qq.com> --- tools/pd-ctl/tests/global_test.go | 33 +++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tools/pd-ctl/tests/global_test.go b/tools/pd-ctl/tests/global_test.go index f4f55e2af89..1387a0cdd51 100644 --- a/tools/pd-ctl/tests/global_test.go +++ b/tools/pd-ctl/tests/global_test.go @@ -16,26 +16,36 @@ package tests import ( "context" - "fmt" + "encoding/json" "net/http" "testing" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" "github.com/stretchr/testify/require" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/assertutil" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server" + "github.com/tikv/pd/server/api" cmd "github.com/tikv/pd/tools/pd-ctl/pdctl" + "github.com/unrolled/render" "go.uber.org/zap" ) -const pdControlCallerID = "pd-ctl" +const pdControlCallerID = "pd-http-client" func TestSendAndGetComponent(t *testing.T) { re := require.New(t) handler := func(context.Context, *server.Server) (http.Handler, apiutil.APIServiceGroup, error) { mux := http.NewServeMux() + mux.HandleFunc("/pd/api/v1/cluster", func(w http.ResponseWriter, r *http.Request) { + cluster := &metapb.Cluster{ + Id: 0, + } + var rd render.Render + rd.JSON(w, http.StatusOK, cluster) + }) mux.HandleFunc("/pd/api/v1/health", func(w http.ResponseWriter, r *http.Request) { callerID := apiutil.GetCallerIDOnHTTP(r) for k := range r.Header { @@ -43,7 +53,14 @@ func TestSendAndGetComponent(t *testing.T) { } log.Info("caller id", zap.String("caller-id", callerID)) re.Equal(pdControlCallerID, callerID) - fmt.Fprint(w, callerID) + healths := []api.Health{ + { + Name: "test", + }, + } + healthsBytes, err := json.Marshal(healths) + re.NoError(err) + w.Write(healthsBytes) }) info := apiutil.APIServiceGroup{ IsCore: true, @@ -67,5 +84,13 @@ func TestSendAndGetComponent(t *testing.T) { args := []string{"-u", pdAddr, "health"} output, err := ExecuteCommand(cmd, args...) re.NoError(err) - re.Equal(fmt.Sprintf("%s\n", pdControlCallerID), string(output)) + re.Equal(`[ + { + "name": "test", + "member_id": 0, + "client_urls": null, + "health": false + } +] +`, string(output)) } From 120c0d42ffddb5b0a303f76aac1c0aac0f6ad95b Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Fri, 24 May 2024 14:20:05 +0800 Subject: [PATCH 10/13] make check Signed-off-by: okJiang <819421878@qq.com> --- tools/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/go.mod b/tools/go.mod index eb2c279e7fa..873881997db 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -31,6 +31,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tikv/pd v0.0.0-00010101000000-000000000000 github.com/tikv/pd/client v0.0.0-00010101000000-000000000000 + github.com/unrolled/render v1.0.1 go.etcd.io/etcd v0.5.0-alpha.5.0.20240320135013-950cd5fbe6ca go.uber.org/automaxprocs v1.5.3 go.uber.org/goleak v1.3.0 @@ -153,7 +154,6 @@ require ( github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect - github.com/unrolled/render v1.0.1 // indirect github.com/urfave/negroni v0.3.0 // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect From a425cbad92024cbcdaa3690961d0dc72e5029015 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Fri, 24 May 2024 14:25:06 +0800 Subject: [PATCH 11/13] make check Signed-off-by: okJiang <819421878@qq.com> --- tools/pd-ctl/tests/global_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pd-ctl/tests/global_test.go b/tools/pd-ctl/tests/global_test.go index 1387a0cdd51..cdc866f4e0c 100644 --- a/tools/pd-ctl/tests/global_test.go +++ b/tools/pd-ctl/tests/global_test.go @@ -39,7 +39,7 @@ func TestSendAndGetComponent(t *testing.T) { re := require.New(t) handler := func(context.Context, *server.Server) (http.Handler, apiutil.APIServiceGroup, error) { mux := http.NewServeMux() - mux.HandleFunc("/pd/api/v1/cluster", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/pd/api/v1/cluster", func(w http.ResponseWriter, _ *http.Request) { cluster := &metapb.Cluster{ Id: 0, } From eea4858601c372f47d8c11bfdebe1b8745482da9 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Fri, 24 May 2024 14:33:34 +0800 Subject: [PATCH 12/13] fix lint Signed-off-by: okJiang <819421878@qq.com> --- tools/go.mod | 2 +- tools/pd-ctl/tests/global_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/go.mod b/tools/go.mod index 873881997db..eb2c279e7fa 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -31,7 +31,6 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tikv/pd v0.0.0-00010101000000-000000000000 github.com/tikv/pd/client v0.0.0-00010101000000-000000000000 - github.com/unrolled/render v1.0.1 go.etcd.io/etcd v0.5.0-alpha.5.0.20240320135013-950cd5fbe6ca go.uber.org/automaxprocs v1.5.3 go.uber.org/goleak v1.3.0 @@ -154,6 +153,7 @@ require ( github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect + github.com/unrolled/render v1.0.1 // indirect github.com/urfave/negroni v0.3.0 // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect diff --git a/tools/pd-ctl/tests/global_test.go b/tools/pd-ctl/tests/global_test.go index cdc866f4e0c..e3c29fa9768 100644 --- a/tools/pd-ctl/tests/global_test.go +++ b/tools/pd-ctl/tests/global_test.go @@ -29,7 +29,6 @@ import ( "github.com/tikv/pd/server" "github.com/tikv/pd/server/api" cmd "github.com/tikv/pd/tools/pd-ctl/pdctl" - "github.com/unrolled/render" "go.uber.org/zap" ) @@ -43,8 +42,9 @@ func TestSendAndGetComponent(t *testing.T) { cluster := &metapb.Cluster{ Id: 0, } - var rd render.Render - rd.JSON(w, http.StatusOK, cluster) + clusterBytes, err := json.Marshal(cluster) + re.NoError(err) + w.Write(clusterBytes) }) mux.HandleFunc("/pd/api/v1/health", func(w http.ResponseWriter, r *http.Request) { callerID := apiutil.GetCallerIDOnHTTP(r) From 132fe167ae1c29af2e7a0c04ab3b018df6b0e7a6 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Mon, 27 May 2024 11:06:29 +0800 Subject: [PATCH 13/13] revert comment Signed-off-by: okJiang <819421878@qq.com> --- tools/pd-ctl/tests/global_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/pd-ctl/tests/global_test.go b/tools/pd-ctl/tests/global_test.go index 42956010163..766e357088e 100644 --- a/tools/pd-ctl/tests/global_test.go +++ b/tools/pd-ctl/tests/global_test.go @@ -45,6 +45,7 @@ func TestSendAndGetComponent(t *testing.T) { w.Write(clusterBytes) }) // check http client api + // TODO: remove this comment after replacing dialClient with the PD HTTP client completely. mux.HandleFunc("/pd/api/v1/stores", func(w http.ResponseWriter, r *http.Request) { callerID := apiutil.GetCallerIDOnHTTP(r) re.Equal(command.PDControlCallerID, callerID)