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

ci: support real cluster test in jenkins #7493

Merged
merged 11 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ ifeq ($(ENABLE_FIPS), 1)
BUILD_TOOL_CGO_ENABLED := 1
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
endif

LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDReleaseVersion=$(RELEASE_VERSION)"
Comment on lines +58 to +63
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 :(

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
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 @@ -185,7 +185,7 @@ require (
golang.org/x/arch v0.3.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 @@ -683,8 +683,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 @@ -700,8 +700,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 @@ -57,7 +57,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 @@ -199,7 +199,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.3
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.3
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
74 changes: 74 additions & 0 deletions tests/integrations/realtiup/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2023 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.

ROOT_PATH := ../../..
GO_TOOLS_BIN_PATH := $(ROOT_PATH)/.tools/bin
PATH := $(GO_TOOLS_BIN_PATH):$(PATH)
SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)

check: deploy test clean

static: install-tools
@ echo "gofmt ..."
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ echo "golangci-lint ..."
@ golangci-lint run -c $(ROOT_PATH)/.golangci.yml --verbose ./... --allow-parallel-runners
@ echo "revive ..."
@ revive -formatter friendly -config $(ROOT_PATH)/revive.toml ./...

tidy:
@ go mod tidy
git diff go.mod go.sum | cat
git diff --quiet go.mod go.sum

deploy: clean
@ echo "downloading binaries..."
./download_binaries.sh
@ echo "deploying..."
./deploy.sh
@ echo "wait tiup cluster ready..."
./wait_tiup.sh 15 20
@ echo "check cluster status..."
@ pid=$$(ps -ef | grep 'tiup' | grep -v grep | awk '{print $$2}' | head -n 1); \
echo $$pid;

redeploy: kill_tiup
@ echo "deploying..."
./deploy.sh
@ echo "wait tiup cluster ready..."
./wait_tiup.sh 15 20
@ echo "check cluster status..."
@ pid=$$(ps -ef | grep 'tiup' | grep -v grep | awk '{print $$2}' | head -n 1); \
echo $$pid;

clean: kill_tiup
@ echo "cleaning..."
@ rm -rf playground.log
@ rm -rf bin

kill_tiup:
@ echo "kill tiup..."
@ pid=$$(ps -ef | grep 'tiup' | grep -v grep | awk '{print $$2}' | head -n 1); \
if [ ! -z "$$pid" ]; then \
echo $$pid; \
kill $$pid; \
echo "waiting for tiup to exit..."; \
sleep 10; \
fi

test:
CGO_ENABLED=1 go test ./... -v -tags deadlock -race -cover || { exit 1; }

install-tools:
cd $(ROOT_PATH) && $(MAKE) install-tools
19 changes: 19 additions & 0 deletions tests/integrations/realtiup/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# deploy `tiup playground`

TIUP_BIN_DIR=$HOME/.tiup/bin/tiup

# See https://misc.flogisoft.com/bash/tip_colors_and_formatting.
color-green() { # Green
echo -e "\x1B[1;32m${*}\x1B[0m"
}

# Install TiUP
color-green "install TiUP..."
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
$TIUP_BIN_DIR update playground

# Run TiUP
$TIUP_BIN_DIR playground nightly --kv 3 --tiflash 1 --db 1 --pd 3 --without-monitor \
HuSharp marked this conversation as resolved.
Show resolved Hide resolved
--pd.binpath ./bin/pd-server --kv.binpath ./bin/tikv-server --db.binpath ./bin/tidb-server --tiflash.binpath ./bin/tiflash --tag pd_test \
> ./playground.log 2>&1 &
93 changes: 93 additions & 0 deletions tests/integrations/realtiup/download_binaries.sh
Copy link
Member

Choose a reason for hiding this comment

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

I suggest moving the logic here to the internal script of CI instead of the repo, otherwise, there may be some exposure of internal information.

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

# download_binaries.sh will
# * download all the binaries you need for integration testing

# Notice:
# Please don't try the script locally,
# it downloads files for linux platform. We only use it in docker-compose.

set -o errexit
set -o pipefail

# Specify which branch to be utilized for executing the test, which is
# exclusively accessible when obtaining binaries from
# http://fileserver.pingcap.net.
branch=${THIRD_PARTY_TARGET_BRANCH:-master}
set -o nounset

# See https://misc.flogisoft.com/bash/tip_colors_and_formatting.
color-green() { # Green
echo -e "\x1B[1;32m${*}\x1B[0m"
}

function download() {
local url=$1
local file_name=$2
local file_path=$3
if [[ -f "${file_path}" ]]; then
echo "file ${file_name} already exists, skip download"
return
fi
echo ">>>"
echo "download ${file_name} from ${url}"
wget --no-verbose --retry-connrefused --waitretry=1 -t 3 -O "${file_path}" "${url}"
}

function download_binaries() {
color-green "Download binaries..."
# PingCAP file server URL.
file_server_url="http://fileserver.pingcap.net"

# Get sha1 based on branch name.
tidb_sha1=$(curl "${file_server_url}/download/refs/pingcap/tidb/${branch}/sha1")
tikv_sha1=$(curl "${file_server_url}/download/refs/pingcap/tikv/${branch}/sha1")
tiflash_sha1=$(curl "${file_server_url}/download/refs/pingcap/tiflash/${branch}/sha1")

# All download links.
tidb_download_url="${file_server_url}/download/builds/pingcap/tidb/${tidb_sha1}/centos7/tidb-server.tar.gz"
tikv_download_url="${file_server_url}/download/builds/pingcap/tikv/${tikv_sha1}/centos7/tikv-server.tar.gz"
tiflash_download_url="${file_server_url}/download/builds/pingcap/tiflash/${branch}/${tiflash_sha1}/centos7/tiflash.tar.gz"

download "$tidb_download_url" "tidb-server.tar.gz" "tmp/tidb-server.tar.gz"
tar -xz -C third_bin bin/tidb-server -f tmp/tidb-server.tar.gz && mv third_bin/bin/* bin/

download "$tikv_download_url" "tikv-server.tar.gz" "tmp/tikv-server.tar.gz"
tar -xz -C third_bin bin/tikv-server -f tmp/tikv-server.tar.gz && mv third_bin/bin/tikv-server bin/

download "$tiflash_download_url" "tiflash.tar.gz" "tmp/tiflash.tar.gz"
tar -xz -C third_bin -f tmp/tiflash.tar.gz
mv third_bin/tiflash third_bin/_tiflash
mv third_bin/_tiflash/* bin && rm -rf third_bin/_tiflash

chmod a+x bin/*
}

function make_pd() {
echo 'download pd-server'
CUR_PATH=$(pwd)
cd ../../../
rm -rf bin
RUN_CI=1 make pd-server-basic
cd $CUR_PATH
mv ../../../bin/pd-server ./bin/
}

# Some temporary dir.
rm -rf tmp
rm -rf bin
rm -rf third_bin

mkdir -p tmp
mkdir -p bin
mkdir -p third_bin

# build pd-server
make_pd
download_binaries

# Copy it to the bin directory in the root directory.
rm -rf tmp
rm -rf third_bin

color-green "Download SUCCESS"
47 changes: 47 additions & 0 deletions tests/integrations/realtiup/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module github.com/tikv/pd/tests/integrations/realtiup

go 1.21

replace github.com/tikv/pd/client => ../../../client

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/go-sql-driver/mysql v1.7.1
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/stretchr/testify v1.8.4
github.com/tikv/pd/client v0.0.0-00010101000000-000000000000
gorm.io/driver/mysql v1.5.2
gorm.io/gorm v1.25.5
moul.io/zapgorm2 v1.3.0
)

require (
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c // indirect
github.com/pingcap/kvproto v0.0.0-20230727073445-53e1f8730c30 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.54.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading