Skip to content

Commit

Permalink
Merge branch 'master' into fix-issue-4941
Browse files Browse the repository at this point in the history
  • Loading branch information
rleungx authored May 13, 2022
2 parents e03fa96 + dd8d0b0 commit c9275ba
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
89 changes: 89 additions & 0 deletions metrics/grafana/pd.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/autoscaling/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
2 changes: 2 additions & 0 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
Expand Down
10 changes: 10 additions & 0 deletions server/schedule/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -84,4 +93,5 @@ func init() {
prometheus.MustRegister(operatorWaitCounter)
prometheus.MustRegister(scatterCounter)
prometheus.MustRegister(scatterDistributionCounter)
prometheus.MustRegister(operatorSizeHist)
}
1 change: 1 addition & 0 deletions server/schedule/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion tests/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion tools/pd-ctl/pdctl/command/store_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c9275ba

Please sign in to comment.