Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Sep 7, 2023
1 parent 0579b2a commit 958aa0d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
34 changes: 34 additions & 0 deletions tools/pd-api-bench/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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)

install-tools:
cd $(ROOT_PATH) && $(MAKE) install-tools

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
11 changes: 10 additions & 1 deletion tools/pd-api-bench/cases/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import (
)

var (
// PDAddress is the address of PD server.
PDAddress string
Debug bool
// Debug is the flag to print the output of api response for debug.
Debug bool
)

var (
Expand All @@ -39,6 +41,7 @@ var (
storesID []uint64
)

// InitCluster initializes the cluster.
func InitCluster(ctx context.Context, cli pd.Client, httpClit *http.Client) error {
req, _ := http.NewRequestWithContext(ctx, http.MethodGet,
PDAddress+"/pd/api/v1/stats/region?start_key=&end_key=&count", nil)
Expand Down Expand Up @@ -67,6 +70,7 @@ func InitCluster(ctx context.Context, cli pd.Client, httpClit *http.Client) erro
return nil
}

// Case is the interface for all cases.
type Case interface {
Name() string
SetQPS(int64)
Expand Down Expand Up @@ -101,24 +105,28 @@ func (c *baseCase) GetBurst() int64 {
return c.burst
}

// GRPCCase is the interface for all gRPC cases.
type GRPCCase interface {
Case
Unary(context.Context, pd.Client) error
}

// GRPCCaseMap is the map for all gRPC cases.
var GRPCCaseMap = map[string]GRPCCase{
"GetRegion": newGetRegion(),
"GetStore": newGetStore(),
"GetStores": newGetStores(),
"ScanRegions": newScanRegions(),
}

// HTTPCase is the interface for all HTTP cases.
type HTTPCase interface {
Case
Do(context.Context, *http.Client) error
Params(string)
}

// HTTPCaseMap is the map for all HTTP cases.
var HTTPCaseMap = map[string]HTTPCase{
"GetRegionStatus": newRegionStats(),
"GetMinResolvedTS": newMinResolvedTS(),
Expand Down Expand Up @@ -319,6 +327,7 @@ func (c *getStores) Unary(ctx context.Context, cli pd.Client) error {
return nil
}

// nolint
func generateKeyForSimulator(id int, keyLen int) []byte {
k := make([]byte, keyLen)
copy(k, fmt.Sprintf("%010d", id))
Expand Down
4 changes: 2 additions & 2 deletions tools/pd-api-bench/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rleungx/kvproto v0.0.0-20230906083326-5bca56048097 h1:luEk8MEptO8Fop2EfHqY0bsIBtGZh8Qb0eVEz3tjYG8=
github.com/rleungx/kvproto v0.0.0-20230906083326-5bca56048097/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rleungx/kvproto v0.0.0-20230907032444-eba37dcb1a38 h1:8vBwN7w7keTO+sBESkGVHM0bWAvOtc5eEEDaRR7ufbE=
github.com/rleungx/kvproto v0.0.0-20230907032444-eba37dcb1a38/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
6 changes: 3 additions & 3 deletions tools/pd-api-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func main() {
}
httpClis := make([]*http.Client, 0)
for i := 0; i < *client; i++ {
httpClis = append(httpClis, newHttpClient())
httpClis = append(httpClis, newHTTPClient())
}
err = cases.InitCluster(ctx, pdClis[0], httpClis[0])
if err != nil {
Expand Down Expand Up @@ -248,8 +248,8 @@ func exit(code int) {
os.Exit(code)
}

// newHttpClient returns an HTTP(s) client.
func newHttpClient() *http.Client {
// newHTTPClient returns an HTTP(s) client.
func newHTTPClient() *http.Client {
// defaultTimeout for non-context requests.
const defaultTimeout = 30 * time.Second
cli := &http.Client{Timeout: defaultTimeout}
Expand Down
34 changes: 34 additions & 0 deletions tools/pd-tso-bench/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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)

install-tools:
cd $(ROOT_PATH) && $(MAKE) install-tools

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
4 changes: 2 additions & 2 deletions tools/pd-tso-bench/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/rleungx/kvproto v0.0.0-20230906083326-5bca56048097 h1:luEk8MEptO8Fop2EfHqY0bsIBtGZh8Qb0eVEz3tjYG8=
github.com/rleungx/kvproto v0.0.0-20230906083326-5bca56048097/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/rleungx/kvproto v0.0.0-20230907032444-eba37dcb1a38 h1:8vBwN7w7keTO+sBESkGVHM0bWAvOtc5eEEDaRR7ufbE=
github.com/rleungx/kvproto v0.0.0-20230907032444-eba37dcb1a38/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
Expand Down

0 comments on commit 958aa0d

Please sign in to comment.