Skip to content

Commit

Permalink
mcs: improve scheduling service log (#7060)
Browse files Browse the repository at this point in the history
ref #5839

Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Sep 8, 2023
1 parent 1fbe2d7 commit d031342
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ require (
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 // indirect
github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/prometheus/client_model v0.2.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion pkg/gc/safepoint_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"context"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/keyspacepb"
"github.com/pingcap/log"
"github.com/pkg/errors"
"github.com/tikv/pd/pkg/keyspace"
"github.com/tikv/pd/pkg/slice"
"github.com/tikv/pd/pkg/storage/endpoint"
Expand Down
6 changes: 5 additions & 1 deletion pkg/mcs/scheduling/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (s *Server) updateAPIServerMemberLoop() {
ticker = time.NewTicker(100 * time.Millisecond)
})
defer ticker.Stop()
var curLeader uint64
for {
select {
case <-ctx.Done():
Expand All @@ -180,7 +181,10 @@ func (s *Server) updateAPIServerMemberLoop() {
log.Info("failed to get delegate client", errs.ZapError(err))
}
if s.cluster.SwitchAPIServerLeader(pdpb.NewPDClient(cc)) {
log.Info("switch leader", zap.String("leader-id", fmt.Sprintf("%x", ep.ID)), zap.String("endpoint", ep.ClientURLs[0]))
if status.Leader != curLeader {
log.Info("switch leader", zap.String("leader-id", fmt.Sprintf("%x", ep.ID)), zap.String("endpoint", ep.ClientURLs[0]))
}
curLeader = ep.ID
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/tso/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"time"

"github.com/BurntSushi/toml"
"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"github.com/tikv/pd/pkg/mcs/utils"
"github.com/tikv/pd/pkg/tso"
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/tso/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"strings"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/tsopb"
"github.com/pingcap/log"
"github.com/pkg/errors"
bs "github.com/tikv/pd/pkg/basicserver"
"github.com/tikv/pd/pkg/mcs/registry"
"github.com/tikv/pd/pkg/utils/apiutil"
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"time"

"github.com/gin-gonic/gin"
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/diagnosticspb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/soheilhy/cmux"
Expand Down
2 changes: 1 addition & 1 deletion pkg/mock/mockcluster/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"time"

"github.com/docker/go-units"
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"
"github.com/pkg/errors"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/core/storelimit"
"github.com/tikv/pd/pkg/errs"
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package config
import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pkg/errors"
"github.com/tikv/pd/pkg/core/storelimit"
"github.com/tikv/pd/pkg/utils/configutil"
"github.com/tikv/pd/pkg/utils/syncutil"
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/configutil/configutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"github.com/BurntSushi/toml"
"github.com/pkg/errors"
"github.com/pingcap/errors"
"github.com/spf13/pflag"
"github.com/tikv/pd/pkg/encryption"
"github.com/tikv/pd/pkg/utils/grpcutil"
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/grpcutil/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"net/url"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pkg/errors"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/utils/logutil"
"go.etcd.io/etcd/pkg/transport"
Expand Down
2 changes: 1 addition & 1 deletion server/apiv2/handlers/tso_keyspace_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sync"

"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"github.com/pingcap/errors"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/mcs/utils"
"github.com/tikv/pd/pkg/slice"
Expand Down
2 changes: 2 additions & 0 deletions tests/scheduling_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/stretchr/testify/require"
scheduling "github.com/tikv/pd/pkg/mcs/scheduling/server"
sc "github.com/tikv/pd/pkg/mcs/scheduling/server/config"
"github.com/tikv/pd/pkg/schedule/schedulers"
"github.com/tikv/pd/pkg/utils/tempurl"
"github.com/tikv/pd/pkg/utils/testutil"
)
Expand All @@ -36,6 +37,7 @@ type TestSchedulingCluster struct {

// NewTestSchedulingCluster creates a new scheduling test cluster.
func NewTestSchedulingCluster(ctx context.Context, initialServerCount int, backendEndpoints string) (tc *TestSchedulingCluster, err error) {
schedulers.Register()
tc = &TestSchedulingCluster{
ctx: ctx,
backendEndpoints: backendEndpoints,
Expand Down
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
1 change: 0 additions & 1 deletion tools/pd-api-bench/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ require (
github.com/pingcap/kvproto v0.0.0-20230905082026-5336fac26974 // indirect
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 // indirect
github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
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

0 comments on commit d031342

Please sign in to comment.