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

tests: add integration test and ci workflow for real tiup #7317

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions .github/workflows/real_tiup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PD Real TiUP Test
on:
push:
branches:
- master
- release-*
pull_request:
branches:
- master
- release-*
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
real-cluster:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: Checkout code
uses: actions/checkout@v3
- name: Restore cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
**/.tools
**/.dashboard_download_cache
key: ${{ runner.os }}-go-${{ matrix.worker_id }}-${{ hashFiles('**/go.sum') }}

- name: Test
run: make check
working-directory: tests/integrations/realtiup
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ ifeq ($(PLUGIN), 1)
BUILD_TAGS += with_plugin
endif

LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDReleaseVersion=$(shell git describe --tags --dirty --always)"
RELEASE_VERSION ?= $(shell git describe --tags --dirty --always)
ifeq ($(RUN_CI), 1)
RELEASE_VERSION := None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to set it to None?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no tag in the ci environment, we can not pass

pd/server/util.go

Lines 39 to 41 in bfc988b

if versioninfo.PDReleaseVersion != "None" {
pdVersion = versioninfo.MustParseVersion(versioninfo.PDReleaseVersion)
}
whithout tag :(

endif

LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDReleaseVersion=$(RELEASE_VERSION)"
LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDBuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDGitHash=$(shell git rev-parse HEAD)"
LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDGitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
Expand Down
16 changes: 16 additions & 0 deletions client/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
regionsByKey = "/pd/api/v1/regions/key"
regionsByStoreID = "/pd/api/v1/regions/store"
Stores = "/pd/api/v1/stores"
Store = "/pd/api/v1/store"
MinResolvedTSPrefix = "/pd/api/v1/min-resolved-ts"

Leader = "/pd/api/v1/leader"
TransferLeader = "/pd/api/v1/leader/transfer"

Schedulers = "/pd/api/v1/schedulers"
)

// RegionByID returns the path of PD HTTP API to get region by ID.
Expand All @@ -52,3 +58,13 @@
func RegionsByStoreID(storeID uint64) string {
return fmt.Sprintf("%s/%d", regionsByStoreID, storeID)
}

// LabelByStore returns the path of PD HTTP API to set store label.
func LabelByStore(storeID int64) string {
return fmt.Sprintf("%s/%d/label", Store, storeID)

Check warning on line 64 in client/http/api.go

View check run for this annotation

Codecov / codecov/patch

client/http/api.go#L64

Added line #L64 was not covered by tests
}

// TransferLeaderID returns the path of PD HTTP API to transfer leader by ID.
func TransferLeaderID(leaderID string) string {
return fmt.Sprintf("%s/%s", TransferLeader, leaderID)

Check warning on line 69 in client/http/api.go

View check run for this annotation

Codecov / codecov/patch

client/http/api.go#L69

Added line #L69 was not covered by tests
}
98 changes: 82 additions & 16 deletions client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package http

import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
Expand All @@ -25,6 +26,7 @@
"time"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
Expand All @@ -49,6 +51,14 @@
GetHotWriteRegions(context.Context) (*StoreHotPeersInfos, error)
GetStores(context.Context) (*StoresInfo, error)
GetMinResolvedTSByStoresIDs(context.Context, []uint64) (uint64, map[uint64]uint64, error)
SetStoreLabel(context.Context, int64, map[string]string) error

GetLeader(context.Context) (*pdpb.Member, error)
TransferLeader(context.Context, string) error

GetSchedulers(context.Context) ([]string, error)
AddScheduler(context.Context, string, map[string]interface{}) error

Close()
}

Expand Down Expand Up @@ -154,7 +164,8 @@
// it consistent with the current implementation of some clients (e.g. TiDB).
func (c *client) requestWithRetry(
ctx context.Context,
name, uri string,
name, uri, method string,
body io.Reader,
res interface{},
) error {
var (
Expand All @@ -163,7 +174,7 @@
)
for idx := 0; idx < len(c.pdAddrs); idx++ {
addr = c.pdAddrs[idx]
err = c.request(ctx, name, addr, uri, res)
err = c.request(ctx, name, addr, uri, method, body, res)
if err == nil {
break
}
Expand All @@ -175,16 +186,18 @@

func (c *client) request(
ctx context.Context,
name, addr, uri string,
name, addr, uri, method string,
body io.Reader,
res interface{},
) error {
reqURL := fmt.Sprintf("%s%s", addr, uri)
logFields := []zap.Field{
zap.String("name", name),
zap.String("url", reqURL),
zap.String("method", method),
}
log.Debug("[pd] request the http url", logFields...)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)
req, err := http.NewRequestWithContext(ctx, method, reqURL, body)
if err != nil {
log.Error("[pd] create http request failed", append(logFields, zap.Error(err))...)
return errors.Trace(err)
Expand Down Expand Up @@ -219,17 +232,19 @@
return errors.Errorf("request pd http api failed with status: '%s'", resp.Status)
}

err = json.NewDecoder(resp.Body).Decode(res)
if err != nil {
return errors.Trace(err)
if res != nil {
err = json.NewDecoder(resp.Body).Decode(&res)
if err != nil {
return errors.Trace(err)

Check warning on line 238 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L238

Added line #L238 was not covered by tests
}
}
return nil
}

// GetRegionByID gets the region info by ID.
func (c *client) GetRegionByID(ctx context.Context, regionID uint64) (*RegionInfo, error) {
var region RegionInfo
err := c.requestWithRetry(ctx, "GetRegionByID", RegionByID(regionID), &region)
err := c.requestWithRetry(ctx, "GetRegionByID", RegionByID(regionID), http.MethodGet, nil, &region)

Check warning on line 247 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L247

Added line #L247 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -239,7 +254,7 @@
// GetRegionByKey gets the region info by key.
func (c *client) GetRegionByKey(ctx context.Context, key []byte) (*RegionInfo, error) {
var region RegionInfo
err := c.requestWithRetry(ctx, "GetRegionByKey", RegionByKey(key), &region)
err := c.requestWithRetry(ctx, "GetRegionByKey", RegionByKey(key), http.MethodGet, nil, &region)

Check warning on line 257 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L257

Added line #L257 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -249,7 +264,7 @@
// GetRegions gets the regions info.
func (c *client) GetRegions(ctx context.Context) (*RegionsInfo, error) {
var regions RegionsInfo
err := c.requestWithRetry(ctx, "GetRegions", Regions, &regions)
err := c.requestWithRetry(ctx, "GetRegions", Regions, http.MethodGet, nil, &regions)

Check warning on line 267 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L267

Added line #L267 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -259,7 +274,7 @@
// GetRegionsByKey gets the regions info by key range. If the limit is -1, it will return all regions within the range.
func (c *client) GetRegionsByKey(ctx context.Context, startKey, endKey []byte, limit int) (*RegionsInfo, error) {
var regions RegionsInfo
err := c.requestWithRetry(ctx, "GetRegionsByKey", RegionsByKey(startKey, endKey, limit), &regions)
err := c.requestWithRetry(ctx, "GetRegionsByKey", RegionsByKey(startKey, endKey, limit), http.MethodGet, nil, &regions)

Check warning on line 277 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L277

Added line #L277 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -269,7 +284,7 @@
// GetRegionsByStoreID gets the regions info by store ID.
func (c *client) GetRegionsByStoreID(ctx context.Context, storeID uint64) (*RegionsInfo, error) {
var regions RegionsInfo
err := c.requestWithRetry(ctx, "GetRegionsByStoreID", RegionsByStoreID(storeID), &regions)
err := c.requestWithRetry(ctx, "GetRegionsByStoreID", RegionsByStoreID(storeID), http.MethodGet, nil, &regions)

Check warning on line 287 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L287

Added line #L287 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -279,7 +294,7 @@
// GetHotReadRegions gets the hot read region statistics info.
func (c *client) GetHotReadRegions(ctx context.Context) (*StoreHotPeersInfos, error) {
var hotReadRegions StoreHotPeersInfos
err := c.requestWithRetry(ctx, "GetHotReadRegions", HotRead, &hotReadRegions)
err := c.requestWithRetry(ctx, "GetHotReadRegions", HotRead, http.MethodGet, nil, &hotReadRegions)

Check warning on line 297 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L297

Added line #L297 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -289,7 +304,7 @@
// GetHotWriteRegions gets the hot write region statistics info.
func (c *client) GetHotWriteRegions(ctx context.Context) (*StoreHotPeersInfos, error) {
var hotWriteRegions StoreHotPeersInfos
err := c.requestWithRetry(ctx, "GetHotWriteRegions", HotWrite, &hotWriteRegions)
err := c.requestWithRetry(ctx, "GetHotWriteRegions", HotWrite, http.MethodGet, nil, &hotWriteRegions)

Check warning on line 307 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L307

Added line #L307 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -299,7 +314,7 @@
// GetStores gets the stores info.
func (c *client) GetStores(ctx context.Context) (*StoresInfo, error) {
var stores StoresInfo
err := c.requestWithRetry(ctx, "GetStores", Stores, &stores)
err := c.requestWithRetry(ctx, "GetStores", Stores, http.MethodGet, nil, &stores)

Check warning on line 317 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L317

Added line #L317 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -326,7 +341,7 @@
IsRealTime bool `json:"is_real_time,omitempty"`
StoresMinResolvedTS map[uint64]uint64 `json:"stores_min_resolved_ts"`
}{}
err := c.requestWithRetry(ctx, "GetMinResolvedTSByStoresIDs", uri, &resp)
err := c.requestWithRetry(ctx, "GetMinResolvedTSByStoresIDs", uri, http.MethodGet, nil, &resp)
if err != nil {
return 0, nil, err
}
Expand All @@ -335,3 +350,54 @@
}
return resp.MinResolvedTS, resp.StoresMinResolvedTS, nil
}

// SetStoreLabel sets the label of a store.
func (c *client) SetStoreLabel(ctx context.Context, storeID int64, storeLabel map[string]string) error {
jsonBody, err := json.Marshal(storeLabel)
if err != nil {
return err

Check warning on line 358 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L356-L358

Added lines #L356 - L358 were not covered by tests
}

return c.requestWithRetry(ctx, "SetStoreLabel", LabelByStore(storeID),
http.MethodPost, bytes.NewBuffer(jsonBody), nil)

Check warning on line 362 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L361-L362

Added lines #L361 - L362 were not covered by tests
}

// GetLeader gets the leader of PD cluster.
func (c *client) GetLeader(context.Context) (*pdpb.Member, error) {
var leader pdpb.Member
err := c.requestWithRetry(context.Background(), "GetLeader", Leader, http.MethodGet, nil, &leader)
if err != nil {
return nil, err

Check warning on line 370 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L367-L370

Added lines #L367 - L370 were not covered by tests
}
return &leader, nil

Check warning on line 372 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L372

Added line #L372 was not covered by tests
}

// TransferLeader transfers the PD leader.
func (c *client) TransferLeader(ctx context.Context, newLeader string) error {
return c.requestWithRetry(ctx, "TransferLeader", TransferLeaderID(newLeader), http.MethodPost, nil, nil)

Check warning on line 377 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L377

Added line #L377 was not covered by tests
}

// GetSchedulers gets the schedulers from PD cluster.
func (c *client) GetSchedulers(ctx context.Context) ([]string, error) {
var schedulers []string
err := c.requestWithRetry(ctx, "GetSchedulers", Schedulers, http.MethodGet, nil, &schedulers)
if err != nil {
return nil, err

Check warning on line 385 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L382-L385

Added lines #L382 - L385 were not covered by tests
}
return schedulers, nil

Check warning on line 387 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L387

Added line #L387 was not covered by tests
}

// AddScheduler adds a scheduler to PD cluster.
func (c *client) AddScheduler(ctx context.Context, name string, args map[string]interface{}) error {
request := map[string]interface{}{
"name": name,

Check warning on line 393 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L392-L393

Added lines #L392 - L393 were not covered by tests
}
for arg, val := range args {
request[arg] = val

Check warning on line 396 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L396

Added line #L396 was not covered by tests
}
data, err := json.Marshal(request)
if err != nil {
return err

Check warning on line 400 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L398-L400

Added lines #L398 - L400 were not covered by tests
}
return c.requestWithRetry(ctx, "AddScheduler", Schedulers, http.MethodPost, bytes.NewBuffer(data), nil)

Check warning on line 402 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L402

Added line #L402 was not covered by tests
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ require (
go.uber.org/atomic v1.10.0
go.uber.org/goleak v1.1.12
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a
golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4
golang.org/x/text v0.13.0
golang.org/x/time v0.1.0
golang.org/x/tools v0.6.0
Expand Down Expand Up @@ -179,7 +179,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sync v0.1.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a h1:tlXy25amD5A7gOfbXdqCGN5k8ESEed/Ee1E5RcrYnqU=
golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4 h1:QLureRX3moex6NVu/Lr4MGakp9FdA7sBHGBmvRW7NaM=
golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
Expand All @@ -672,8 +672,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
4 changes: 2 additions & 2 deletions pkg/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type EmbeddedEtcdMember struct {
id uint64 // etcd server id.
member *pdpb.Member // current PD's info.
rootPath string
// memberValue is the serialized string of `member`. It will be save in
// memberValue is the serialized string of `member`. It will be saved in
// etcd leader key when the PD node is successfully elected as the PD leader
// of the cluster. Every write will use it to check PD leadership.
memberValue string
Expand Down Expand Up @@ -186,7 +186,7 @@ func (m *EmbeddedEtcdMember) KeepLeader(ctx context.Context) {
m.leadership.Keep(ctx)
}

// PreCheckLeader does some pre-check before checking whether or not it's the leader.
// PreCheckLeader does some pre-check before checking whether it's the leader.
func (m *EmbeddedEtcdMember) PreCheckLeader() error {
if m.GetEtcdLeader() == 0 {
return errs.ErrEtcdLeaderNotFound
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/stretchr/testify v1.8.2
github.com/tikv/pd v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-20231101084237-a1a1eea8dafd
go.etcd.io/etcd v0.5.0-alpha.5.0.20220915004622-85b640cee793
go.uber.org/goleak v1.1.12
go.uber.org/zap v1.24.0
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/stretchr/testify v1.8.2
github.com/tikv/pd v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-20231101084237-a1a1eea8dafd
go.etcd.io/etcd v0.5.0-alpha.5.0.20220915004622-85b640cee793
go.uber.org/goleak v1.1.12
go.uber.org/zap v1.24.0
Expand Down
Loading
Loading