Skip to content

Commit

Permalink
*: unify the use of PD API URL constants (#48132)
Browse files Browse the repository at this point in the history
ref #35319
  • Loading branch information
JmPotato authored Nov 1, 2023
1 parent bf8c728 commit 733b10b
Show file tree
Hide file tree
Showing 23 changed files with 179 additions and 111 deletions.
1 change: 1 addition & 0 deletions br/pkg/lightning/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ go_test(
"//pkg/testkit/testsetup",
"//pkg/util/dbutil",
"//pkg/util/mock",
"//pkg/util/pdapi",
"@com_github_data_dog_go_sqlmock//:go-sqlmock",
"@com_github_go_sql_driver_mysql//:mysql",
"@com_github_pingcap_errors//:errors",
Expand Down
6 changes: 4 additions & 2 deletions br/pkg/lightning/common/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package common_test

import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -25,6 +26,7 @@ import (
"testing"

"github.com/pingcap/tidb/br/pkg/lightning/common"
"github.com/pingcap/tidb/pkg/util/pdapi"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -92,8 +94,8 @@ func TestWithHost(t *testing.T) {
false,
},
{
"http://127.0.0.1:2379/pd/api/v1/stores",
"127.0.0.1:2379/pd/api/v1/stores",
fmt.Sprintf("http://127.0.0.1:2379%s", pdapi.Stores),
fmt.Sprintf("127.0.0.1:2379%s", pdapi.Stores),
false,
},
{
Expand Down
2 changes: 2 additions & 0 deletions br/pkg/lightning/importer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ go_library(
"//pkg/util/engine",
"//pkg/util/extsort",
"//pkg/util/mock",
"//pkg/util/pdapi",
"//pkg/util/regexpr-router",
"//pkg/util/set",
"@com_github_coreos_go_semver//semver",
Expand Down Expand Up @@ -161,6 +162,7 @@ go_test(
"//pkg/util/dbutil",
"//pkg/util/extsort",
"//pkg/util/mock",
"//pkg/util/pdapi",
"//pkg/util/promutil",
"//pkg/util/table-filter",
"//pkg/util/table-router",
Expand Down
4 changes: 0 additions & 4 deletions br/pkg/lightning/importer/check_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (
)

const (
pdStores = "/pd/api/v1/stores"
pdReplicate = "/pd/api/v1/config/replicate"
pdEmptyRegions = "/pd/api/v1/regions/check/empty-region"

defaultCSVSize = 10 * units.GiB
maxSampleDataSize = 10 * 1024 * 1024
maxSampleRowCount = 10 * 1024
Expand Down
7 changes: 4 additions & 3 deletions br/pkg/lightning/importer/get_pre_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/dbterror"
"github.com/pingcap/tidb/pkg/util/mock"
"github.com/pingcap/tidb/pkg/util/pdapi"
pd "github.com/tikv/pd/client"
"go.uber.org/zap"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -236,7 +237,7 @@ func (g *TargetInfoGetterImpl) GetTargetSysVariablesForImport(ctx context.Contex
// It uses the PD interface through TLS to get the information.
func (g *TargetInfoGetterImpl) GetReplicationConfig(ctx context.Context) (*pdtypes.ReplicationConfig, error) {
result := new(pdtypes.ReplicationConfig)
if err := g.tls.WithHost(g.pdCli.GetLeaderAddr()).GetJSON(ctx, pdReplicate, &result); err != nil {
if err := g.tls.WithHost(g.pdCli.GetLeaderAddr()).GetJSON(ctx, pdapi.ReplicateConfig, &result); err != nil {
return nil, errors.Trace(err)
}
return result, nil
Expand All @@ -247,7 +248,7 @@ func (g *TargetInfoGetterImpl) GetReplicationConfig(ctx context.Context) (*pdtyp
// It uses the PD interface through TLS to get the information.
func (g *TargetInfoGetterImpl) GetStorageInfo(ctx context.Context) (*pdtypes.StoresInfo, error) {
result := new(pdtypes.StoresInfo)
if err := g.tls.WithHost(g.pdCli.GetLeaderAddr()).GetJSON(ctx, pdStores, result); err != nil {
if err := g.tls.WithHost(g.pdCli.GetLeaderAddr()).GetJSON(ctx, pdapi.Stores, result); err != nil {
return nil, errors.Trace(err)
}
return result, nil
Expand All @@ -258,7 +259,7 @@ func (g *TargetInfoGetterImpl) GetStorageInfo(ctx context.Context) (*pdtypes.Sto
// It uses the PD interface through TLS to get the information.
func (g *TargetInfoGetterImpl) GetEmptyRegionsInfo(ctx context.Context) (*pdtypes.RegionsInfo, error) {
result := new(pdtypes.RegionsInfo)
if err := g.tls.WithHost(g.pdCli.GetLeaderAddr()).GetJSON(ctx, pdEmptyRegions, &result); err != nil {
if err := g.tls.WithHost(g.pdCli.GetLeaderAddr()).GetJSON(ctx, pdapi.EmptyRegions, &result); err != nil {
return nil, errors.Trace(err)
}
return result, nil
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/lightning/importer/table_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import (
"github.com/pingcap/tidb/pkg/table/tables"
"github.com/pingcap/tidb/pkg/types"
tmock "github.com/pingcap/tidb/pkg/util/mock"
"github.com/pingcap/tidb/pkg/util/pdapi"
"github.com/pingcap/tidb/pkg/util/promutil"
filter "github.com/pingcap/tidb/pkg/util/table-filter"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1323,9 +1324,9 @@ func (s *tableRestoreSuite) TestCheckClusterRegion() {
for i, ca := range testCases {
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
var err error
if req.URL.Path == pdStores {
if req.URL.Path == pdapi.Stores {
_, err = w.Write(mustMarshal(ca.stores))
} else if req.URL.Path == pdEmptyRegions {
} else if req.URL.Path == pdapi.EmptyRegions {
_, err = w.Write(mustMarshal(ca.emptyRegions))
} else {
w.WriteHeader(http.StatusNotFound)
Expand Down
2 changes: 2 additions & 0 deletions br/pkg/lightning/tikv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"//br/pkg/version",
"//pkg/kv",
"//pkg/parser/model",
"//pkg/util/pdapi",
"@com_github_coreos_go_semver//semver",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_kvproto//pkg/debugpb",
Expand All @@ -36,6 +37,7 @@ go_test(
deps = [
":tikv",
"//br/pkg/lightning/common",
"//pkg/util/pdapi",
"@com_github_coreos_go_semver//semver",
"@com_github_pingcap_kvproto//pkg/import_sstpb",
"@com_github_stretchr_testify//require",
Expand Down
3 changes: 2 additions & 1 deletion br/pkg/lightning/tikv/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/pingcap/tidb/br/pkg/version"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/util/pdapi"
"github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -124,7 +125,7 @@ func ForAllStores(
Store Store
}
}
err := tls.GetJSON(ctx, "/pd/api/v1/stores", &stores)
err := tls.GetJSON(ctx, pdapi.Stores, &stores)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/lightning/tikv/tikv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pingcap/kvproto/pkg/import_sstpb"
"github.com/pingcap/tidb/br/pkg/lightning/common"
kv "github.com/pingcap/tidb/br/pkg/lightning/tikv"
"github.com/pingcap/tidb/pkg/util/pdapi"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -175,7 +176,7 @@ func TestCheckPDVersion(t *testing.T) {
ctx := context.Background()

mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
require.Equal(t, "/pd/api/v1/version", req.URL.Path)
require.Equal(t, pdapi.Version, req.URL.Path)
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(version))
require.NoError(t, err)
Expand Down Expand Up @@ -229,7 +230,7 @@ func TestCheckTiKVVersion(t *testing.T) {
ctx := context.Background()

mockServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
require.Equal(t, "/pd/api/v1/stores", req.URL.Path)
require.Equal(t, pdapi.Stores, req.URL.Path)
w.WriteHeader(http.StatusOK)

stores := make([]map[string]interface{}, 0, len(versions))
Expand Down
2 changes: 2 additions & 0 deletions br/pkg/pdutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//pkg/store/pdtypes",
"//pkg/tablecodec",
"//pkg/util/codec",
"//pkg/util/pdapi",
"@com_github_coreos_go_semver//semver",
"@com_github_docker_go_units//:go-units",
"@com_github_google_uuid//:uuid",
Expand Down Expand Up @@ -42,6 +43,7 @@ go_test(
"//pkg/store/pdtypes",
"//pkg/testkit/testsetup",
"//pkg/util/codec",
"//pkg/util/pdapi",
"@com_github_coreos_go_semver//semver",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pingcap_kvproto//pkg/metapb",
Expand Down
Loading

0 comments on commit 733b10b

Please sign in to comment.