From 3d426e201c995b0db2942ec442a623d827225f0b Mon Sep 17 00:00:00 2001 From: Shirly Date: Thu, 12 May 2022 17:58:35 +0800 Subject: [PATCH 1/3] server/grpc_service: create scatter_region operator with OpAdmin (#4938) close tikv/pd#4833 Signed-off-by: shirly --- server/grpc_service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/grpc_service.go b/server/grpc_service.go index 38dfc088da9..d6aacb70755 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -34,6 +34,7 @@ import ( "github.com/tikv/pd/pkg/tsoutil" "github.com/tikv/pd/server/cluster" "github.com/tikv/pd/server/core" + "github.com/tikv/pd/server/schedule/operator" "github.com/tikv/pd/server/storage/endpoint" "github.com/tikv/pd/server/storage/kv" "github.com/tikv/pd/server/tso" @@ -1646,6 +1647,7 @@ func scatterRegions(cluster *cluster.RaftCluster, regionsID []uint64, group stri return 0, err } for _, op := range ops { + op.AttachKind(operator.OpAdmin) if ok := cluster.GetOperatorController().AddOperator(op); !ok { failures[op.RegionID()] = fmt.Errorf("region %v failed to add operator", op.RegionID()) } From cbd714540456a31905b298a0425eb4e02244d474 Mon Sep 17 00:00:00 2001 From: buffer <1045931706@qq.com> Date: Fri, 13 May 2022 11:22:35 +0800 Subject: [PATCH 2/3] metrics: add operator region size metric (#4936) close tikv/pd#4935 Signed-off-by: bufferflies <1045931706@qq.com> Co-authored-by: Ti Chi Robot --- metrics/grafana/pd.json | 89 ++++++++++++++++++++++++++ server/schedule/metrics.go | 10 +++ server/schedule/operator_controller.go | 1 + 3 files changed, 100 insertions(+) diff --git a/metrics/grafana/pd.json b/metrics/grafana/pd.json index 7825f921364..1fc9844bc32 100644 --- a/metrics/grafana/pd.json +++ b/metrics/grafana/pd.json @@ -3277,6 +3277,95 @@ "align": false, "alignLevel": null } + },{ + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "description": "99% operator region size", + "fill": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 42 + }, + "id": 1455, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "hideEmpty": true, + "hideZero": true, + "max": true, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 2, + "links": [], + "nullPointMode": "null", + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "histogram_quantile(0.99, sum(rate(pd_schedule_operator_region_size_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\"}[5m])) by (type,le))", + "format": "time_series", + "intervalFactor": 2, + "legendFormat": "{{type,le}}", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "99% operator region size", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "decmbytes", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } } ], "repeat": null, diff --git a/server/schedule/metrics.go b/server/schedule/metrics.go index db79c972c5e..89dabf8e74e 100644 --- a/server/schedule/metrics.go +++ b/server/schedule/metrics.go @@ -34,6 +34,15 @@ var ( Buckets: []float64{0.5, 1, 2, 4, 8, 16, 20, 40, 60, 90, 120, 180, 240, 300, 480, 600, 720, 900, 1200, 1800, 3600}, }, []string{"type"}) + operatorSizeHist = prometheus.NewHistogramVec( + prometheus.HistogramOpts{ + Namespace: "pd", + Subsystem: "schedule", + Name: "operator_region_size", + Help: "Bucketed histogram of the operator region size.", + Buckets: prometheus.ExponentialBuckets(1, 2, 20), // 1MB~1TB + }, []string{"type"}) + operatorWaitCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "pd", @@ -84,4 +93,5 @@ func init() { prometheus.MustRegister(operatorWaitCounter) prometheus.MustRegister(scatterCounter) prometheus.MustRegister(scatterDistributionCounter) + prometheus.MustRegister(operatorSizeHist) } diff --git a/server/schedule/operator_controller.go b/server/schedule/operator_controller.go index bb3bd934baa..6e9ba263663 100644 --- a/server/schedule/operator_controller.go +++ b/server/schedule/operator_controller.go @@ -470,6 +470,7 @@ func (oc *OperatorController) addOperatorLocked(op *operator.Operator) bool { } oc.operators[regionID] = op operatorCounter.WithLabelValues(op.Desc(), "start").Inc() + operatorSizeHist.WithLabelValues(op.Desc()).Observe(float64(op.ApproximateSize)) operatorWaitDuration.WithLabelValues(op.Desc()).Observe(op.ElapsedTime().Seconds()) opInfluence := NewTotalOpInfluence([]*operator.Operator{op}, oc.cluster) for storeID := range opInfluence.StoresInfluence { From dd8d0b018339fe73f04cacd8bba36ec765e4b485 Mon Sep 17 00:00:00 2001 From: ShuNing Date: Fri, 13 May 2022 14:08:36 +0800 Subject: [PATCH 3/3] *: Fix linter after Go 1.18 upgrade (#4945) close tikv/pd#4944, ref tikv/pd#4944 Signed-off-by: nolouch --- .github/workflows/check.yaml | 3 +-- Makefile | 2 +- go.mod | 1 + pkg/autoscaling/prometheus.go | 2 +- tests/client/client_test.go | 3 ++- tools/pd-ctl/pdctl/command/store_command.go | 5 ++++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 34cbf8b3a30..4fbed3641e5 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/setup-go@v2 with: - go-version: 1.17 + go-version: 1.18 - name: Checkout code uses: actions/checkout@v2 - name: Restore cache @@ -18,7 +18,6 @@ jobs: path: | ~/go/pkg/mod ~/.cache/go-build - **/.tools **/.dashboard_download_cache key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }} restore-keys: | diff --git a/Makefile b/Makefile index c85b541c1d1..20e64a8bfc8 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash) install-tools: @mkdir -p $(GO_TOOLS_BIN_PATH) - @which golangci-lint >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_TOOLS_BIN_PATH) v1.43.0 + @which golangci-lint >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_TOOLS_BIN_PATH) v1.46.0 @grep '_' tools.go | sed 's/"//g' | awk '{print $$2}' | xargs go install .PHONY: install-tools diff --git a/go.mod b/go.mod index 3a45721a069..dd64d72272e 100644 --- a/go.mod +++ b/go.mod @@ -50,6 +50,7 @@ require ( go.etcd.io/etcd v0.5.0-alpha.5.0.20191023171146-3cf2f69b5738 go.uber.org/goleak v1.1.12 go.uber.org/zap v1.19.1 + golang.org/x/text v0.3.3 golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 golang.org/x/tools v0.1.5 google.golang.org/grpc v1.26.0 diff --git a/pkg/autoscaling/prometheus.go b/pkg/autoscaling/prometheus.go index c4178bc3c5d..43ba768a585 100644 --- a/pkg/autoscaling/prometheus.go +++ b/pkg/autoscaling/prometheus.go @@ -97,7 +97,7 @@ func (prom *PrometheusQuerier) queryMetricsFromPrometheus(query string, timestam return nil, errs.ErrPrometheusQuery.Wrap(err).FastGenWithCause() } - if warnings != nil && len(warnings) > 0 { + if len(warnings) > 0 { log.Warn("prometheus query returns with warnings", zap.Strings("warnings", warnings)) } diff --git a/tests/client/client_test.go b/tests/client/client_test.go index ef31821eb9b..16e8570097d 100644 --- a/tests/client/client_test.go +++ b/tests/client/client_test.go @@ -1292,7 +1292,8 @@ func (s *testConfigTTLSuite) TestConfigTTLAfterTransferLeader(c *C) { addr := fmt.Sprintf("%s/pd/api/v1/config?ttlSecond=5", leader.GetAddr()) postData, err := json.Marshal(ttlConfig) c.Assert(err, IsNil) - _, err = leader.GetHTTPClient().Post(addr, "application/json", bytes.NewBuffer(postData)) + resp, err := leader.GetHTTPClient().Post(addr, "application/json", bytes.NewBuffer(postData)) + resp.Body.Close() c.Assert(err, IsNil) time.Sleep(2 * time.Second) _ = leader.Destroy() diff --git a/tools/pd-ctl/pdctl/command/store_command.go b/tools/pd-ctl/pdctl/command/store_command.go index f68a21aefeb..a0bad6e0774 100644 --- a/tools/pd-ctl/pdctl/command/store_command.go +++ b/tools/pd-ctl/pdctl/command/store_command.go @@ -25,6 +25,8 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/spf13/cobra" "github.com/tikv/pd/server/api" + "golang.org/x/text/cases" + "golang.org/x/text/language" ) var ( @@ -603,7 +605,8 @@ func storeCheckCommandFunc(cmd *cobra.Command, args []string) { return } - state := strings.Title(strings.ToLower(args[0])) + caser := cases.Title(language.Und) + state := caser.String(strings.ToLower(args[0])) stateValue, ok := metapb.StoreState_value[state] if !ok { cmd.Println("Unknown state: " + state)