Skip to content

Commit da73cd9

Browse files
authored
Merge branch 'master' into add_metrics_for_scatter
2 parents 147cc10 + b6e80b2 commit da73cd9

File tree

10 files changed

+193
-69
lines changed

10 files changed

+193
-69
lines changed

metrics/grafana/pd.json

Lines changed: 138 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
"editable": true,
6464
"gnetId": null,
6565
"graphTooltip": 1,
66-
"id": 11,
67-
"iteration": 1608795246154,
66+
"id": 25,
67+
"iteration": 1618283470402,
6868
"links": [],
6969
"panels": [
7070
{
@@ -957,7 +957,7 @@
957957
"fontSize": "90%",
958958
"gridPos": {
959959
"h": 7,
960-
"w": 6,
960+
"w": 4,
961961
"x": 0,
962962
"y": 14
963963
},
@@ -1008,15 +1008,133 @@
10081008
"transform": "timeseries_aggregations",
10091009
"type": "table"
10101010
},
1011+
{
1012+
"columns": [],
1013+
"datasource": "${DS_TEST-CLUSTER}",
1014+
"fontSize": "100%",
1015+
"gridPos": {
1016+
"h": 7,
1017+
"w": 5,
1018+
"x": 4,
1019+
"y": 14
1020+
},
1021+
"id": 1433,
1022+
"links": [],
1023+
"pageSize": null,
1024+
"scroll": true,
1025+
"showHeader": true,
1026+
"sort": {
1027+
"col": 4,
1028+
"desc": true
1029+
},
1030+
"styles": [
1031+
{
1032+
"alias": "",
1033+
"colorMode": null,
1034+
"colors": [
1035+
"rgba(245, 54, 54, 0.9)",
1036+
"rgba(237, 129, 40, 0.89)",
1037+
"rgba(50, 172, 45, 0.97)"
1038+
],
1039+
"dateFormat": "YYYY-MM-DD HH:mm:ss",
1040+
"decimals": 2,
1041+
"link": false,
1042+
"mappingType": 1,
1043+
"pattern": "Time",
1044+
"thresholds": [],
1045+
"type": "hidden",
1046+
"unit": "short"
1047+
},
1048+
{
1049+
"alias": "",
1050+
"colorMode": null,
1051+
"colors": [
1052+
"rgba(245, 54, 54, 0.9)",
1053+
"rgba(237, 129, 40, 0.89)",
1054+
"rgba(50, 172, 45, 0.97)"
1055+
],
1056+
"dateFormat": "YYYY-MM-DD HH:mm:ss",
1057+
"decimals": 2,
1058+
"mappingType": 1,
1059+
"pattern": "__name__",
1060+
"thresholds": [],
1061+
"type": "hidden",
1062+
"unit": "short"
1063+
},
1064+
{
1065+
"alias": "",
1066+
"colorMode": null,
1067+
"colors": [
1068+
"rgba(245, 54, 54, 0.9)",
1069+
"rgba(237, 129, 40, 0.89)",
1070+
"rgba(50, 172, 45, 0.97)"
1071+
],
1072+
"dateFormat": "YYYY-MM-DD HH:mm:ss",
1073+
"decimals": 2,
1074+
"mappingType": 1,
1075+
"pattern": "instance",
1076+
"thresholds": [],
1077+
"type": "hidden",
1078+
"unit": "short"
1079+
},
1080+
{
1081+
"alias": "",
1082+
"colorMode": null,
1083+
"colors": [
1084+
"rgba(245, 54, 54, 0.9)",
1085+
"rgba(237, 129, 40, 0.89)",
1086+
"rgba(50, 172, 45, 0.97)"
1087+
],
1088+
"dateFormat": "YYYY-MM-DD HH:mm:ss",
1089+
"decimals": 2,
1090+
"mappingType": 1,
1091+
"pattern": "job",
1092+
"thresholds": [],
1093+
"type": "hidden",
1094+
"unit": "short"
1095+
},
1096+
{
1097+
"alias": "limit (opm)",
1098+
"colorMode": null,
1099+
"colors": [
1100+
"rgba(245, 54, 54, 0.9)",
1101+
"rgba(237, 129, 40, 0.89)",
1102+
"rgba(50, 172, 45, 0.97)"
1103+
],
1104+
"dateFormat": "YYYY-MM-DD HH:mm:ss",
1105+
"decimals": 0,
1106+
"mappingType": 1,
1107+
"pattern": "Value",
1108+
"thresholds": [],
1109+
"type": "number",
1110+
"unit": "short"
1111+
}
1112+
],
1113+
"targets": [
1114+
{
1115+
"expr": "pd_cluster_store_limit",
1116+
"format": "table",
1117+
"instant": true,
1118+
"intervalFactor": 1,
1119+
"legendFormat": "",
1120+
"refId": "A"
1121+
}
1122+
],
1123+
"timeFrom": null,
1124+
"timeShift": null,
1125+
"title": "Store limit",
1126+
"transform": "table",
1127+
"type": "table"
1128+
},
10111129
{
10121130
"cacheTimeout": null,
10131131
"columns": [],
10141132
"datasource": "${DS_TEST-CLUSTER}",
10151133
"fontSize": "100%",
10161134
"gridPos": {
10171135
"h": 3,
1018-
"w": 6,
1019-
"x": 6,
1136+
"w": 5,
1137+
"x": 9,
10201138
"y": 14
10211139
},
10221140
"hideTimeOverride": true,
@@ -1083,8 +1201,8 @@
10831201
"fontSize": "100%",
10841202
"gridPos": {
10851203
"h": 7,
1086-
"w": 6,
1087-
"x": 12,
1204+
"w": 5,
1205+
"x": 14,
10881206
"y": 14
10891207
},
10901208
"hideTimeOverride": true,
@@ -1160,8 +1278,8 @@
11601278
"fontSize": "100%",
11611279
"gridPos": {
11621280
"h": 7,
1163-
"w": 6,
1164-
"x": 18,
1281+
"w": 5,
1282+
"x": 19,
11651283
"y": 14
11661284
},
11671285
"hideTimeOverride": true,
@@ -1253,8 +1371,8 @@
12531371
},
12541372
"gridPos": {
12551373
"h": 2,
1256-
"w": 6,
1257-
"x": 6,
1374+
"w": 5,
1375+
"x": 9,
12581376
"y": 17
12591377
},
12601378
"hideTimeOverride": true,
@@ -1338,8 +1456,8 @@
13381456
},
13391457
"gridPos": {
13401458
"h": 2,
1341-
"w": 6,
1342-
"x": 6,
1459+
"w": 5,
1460+
"x": 9,
13431461
"y": 19
13441462
},
13451463
"hideTimeOverride": true,
@@ -10130,24 +10248,25 @@
1013010248
{
1013110249
"allValue": null,
1013210250
"current": {
10251+
"isNone": true,
10252+
"text": "None",
10253+
"value": ""
1013310254
},
1013410255
"datasource": "${DS_TEST-CLUSTER}",
10256+
"definition": "",
1013510257
"hide": 2,
1013610258
"includeAll": false,
1013710259
"label": "tidb_cluster",
1013810260
"multi": false,
1013910261
"name": "tidb_cluster",
10140-
"options": [
10141-
10142-
],
10262+
"options": [],
1014310263
"query": "label_values(pd_cluster_status, tidb_cluster)",
1014410264
"refresh": 2,
1014510265
"regex": "",
10266+
"skipUrlSync": false,
1014610267
"sort": 1,
1014710268
"tagValuesQuery": "",
10148-
"tags": [
10149-
10150-
],
10269+
"tags": [],
1015110270
"tagsQuery": "",
1015210271
"type": "query",
1015310272
"useTags": false

server/api/member.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func newLeaderHandler(svr *server.Server, rd *render.Render) *leaderHandler {
275275
// @Tags leader
276276
// @Summary Get the leader PD server of the cluster.
277277
// @Produce json
278-
// @Success 200 {string} string "The transfer command is submitted."
278+
// @Success 200 {object} pdpb.Member
279279
// @Router /leader [get]
280280
func (h *leaderHandler) Get(w http.ResponseWriter, r *http.Request) {
281281
h.rd.JSON(w, http.StatusOK, h.svr.GetLeader())
@@ -284,7 +284,7 @@ func (h *leaderHandler) Get(w http.ResponseWriter, r *http.Request) {
284284
// @Tags leader
285285
// @Summary Transfer etcd leadership to another PD server.
286286
// @Produce json
287-
// @Success 200 {string} string "The transfer command is submitted."
287+
// @Success 200 {string} string "The resign command is submitted."
288288
// @Failure 500 {string} string "PD server failed to proceed the request."
289289
// @Router /leader/resign [post]
290290
func (h *leaderHandler) Resign(w http.ResponseWriter, r *http.Request) {
@@ -294,7 +294,7 @@ func (h *leaderHandler) Resign(w http.ResponseWriter, r *http.Request) {
294294
return
295295
}
296296

297-
h.rd.JSON(w, http.StatusOK, "The transfer command is submitted.")
297+
h.rd.JSON(w, http.StatusOK, "The resign command is submitted.")
298298
}
299299

300300
// @Tags leader

server/api/member_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"bytes"
1818
"encoding/json"
1919
"fmt"
20+
"io"
2021
"io/ioutil"
2122
"math/rand"
2223
"net/http"
@@ -30,6 +31,7 @@ import (
3031
)
3132

3233
var _ = Suite(&testMemberAPISuite{})
34+
var _ = Suite(&testResignAPISuite{})
3335

3436
type testMemberAPISuite struct {
3537
cfgs []*config.Config
@@ -147,3 +149,26 @@ func changeLeaderPeerUrls(c *C, leader *pdpb.Member, id uint64, urls []string) {
147149
c.Assert(err, IsNil)
148150
c.Assert(resp.StatusCode, Equals, 204)
149151
}
152+
153+
type testResignAPISuite struct {
154+
cfgs []*config.Config
155+
servers []*server.Server
156+
clean func()
157+
}
158+
159+
func (s *testResignAPISuite) SetUpSuite(c *C) {
160+
s.cfgs, s.servers, s.clean = mustNewCluster(c, 1)
161+
}
162+
163+
func (s *testResignAPISuite) TearDownSuite(c *C) {
164+
s.clean()
165+
}
166+
167+
func (s *testResignAPISuite) TestResignMyself(c *C) {
168+
addr := s.cfgs[0].ClientUrls + apiPrefix + "/api/v1/leader/resign"
169+
resp, err := testDialClient.Post(addr, "", nil)
170+
c.Assert(err, IsNil)
171+
c.Assert(resp.StatusCode, Equals, http.StatusOK)
172+
_, _ = io.Copy(ioutil.Discard, resp.Body)
173+
resp.Body.Close()
174+
}

server/cluster/cluster.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"context"
1818
"fmt"
1919
"net/http"
20+
"strconv"
2021
"sync"
2122
"time"
2223

@@ -1257,7 +1258,6 @@ func (c *RaftCluster) collectMetrics() {
12571258

12581259
c.coordinator.collectSchedulerMetrics()
12591260
c.coordinator.collectHotSpotMetrics()
1260-
c.coordinator.opController.CollectStoreLimitMetrics()
12611261
c.collectClusterMetrics()
12621262
c.collectHealthStatus()
12631263
}
@@ -1680,6 +1680,9 @@ func (c *RaftCluster) RemoveStoreLimit(storeID uint64) {
16801680
for i := 0; i < persistLimitRetryTimes; i++ {
16811681
if err = c.opt.Persist(c.storage); err == nil {
16821682
log.Info("store limit removed", zap.Uint64("store-id", storeID))
1683+
id := strconv.FormatUint(storeID, 10)
1684+
statistics.StoreLimitGauge.DeleteLabelValues(id, "add-peer")
1685+
statistics.StoreLimitGauge.DeleteLabelValues(id, "remove-peer")
16831686
return
16841687
}
16851688
time.Sleep(persistLimitWaitTime)

server/join/join.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func PrepareJoinCluster(cfg *config.Config) error {
214214
func isDataExist(d string) bool {
215215
dir, err := os.Open(d)
216216
if err != nil {
217-
log.Error("failed to open directory", errs.ZapError(errs.ErrOSOpen, err))
217+
log.Info("failed to open directory, maybe start for the first time", zap.Error(err))
218218
return false
219219
}
220220
defer dir.Close()

server/member/member.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ func (m *Member) ResignEtcdLeader(ctx context.Context, from string, nextEtcdLead
275275
if err != nil {
276276
return err
277277
}
278+
279+
// Do nothing when I am the only member of cluster.
280+
if len(res.Members) == 1 && res.Members[0].ID == m.id && nextEtcdLeader == "" {
281+
return nil
282+
}
283+
278284
for _, member := range res.Members {
279285
if (nextEtcdLeader == "" && member.ID != m.id) || (nextEtcdLeader != "" && member.Name == nextEtcdLeader) {
280286
etcdLeaderIDs = append(etcdLeaderIDs, member.GetID())

server/schedule/metrics.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,6 @@ var (
5050
Buckets: prometheus.ExponentialBuckets(0.01, 2, 16),
5151
}, []string{"type"})
5252

53-
storeLimitAvailableGauge = prometheus.NewGaugeVec(
54-
prometheus.GaugeOpts{
55-
Namespace: "pd",
56-
Subsystem: "schedule",
57-
Name: "store_limit_available",
58-
Help: "available limit rate of store.",
59-
}, []string{"store", "limit_type"})
60-
61-
storeLimitRateGauge = prometheus.NewGaugeVec(
62-
prometheus.GaugeOpts{
63-
Namespace: "pd",
64-
Subsystem: "schedule",
65-
Name: "store_limit_rate",
66-
Help: "the limit rate of store.",
67-
}, []string{"store", "limit_type"})
68-
6953
storeLimitCostCounter = prometheus.NewCounterVec(
7054
prometheus.CounterOpts{
7155
Namespace: "pd",
@@ -95,8 +79,6 @@ func init() {
9579
prometheus.MustRegister(operatorCounter)
9680
prometheus.MustRegister(operatorDuration)
9781
prometheus.MustRegister(operatorWaitDuration)
98-
prometheus.MustRegister(storeLimitAvailableGauge)
99-
prometheus.MustRegister(storeLimitRateGauge)
10082
prometheus.MustRegister(storeLimitCostCounter)
10183
prometheus.MustRegister(operatorWaitCounter)
10284
prometheus.MustRegister(scatterCounter)

0 commit comments

Comments
 (0)