Skip to content

Commit 3aee2ef

Browse files
authored
pd: report hot read cpu in heartbeat (#10178)
close #5718 Signed-off-by: lhy1024 <admin@liudos.us>
1 parent 048f0d8 commit 3aee2ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1233
-167
lines changed

client/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/opentracing/opentracing-go v1.2.0
1111
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
1212
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
13-
github.com/pingcap/kvproto v0.0.0-20260320060847-534bbfabf736
13+
github.com/pingcap/kvproto v0.0.0-20260326084500-678ff92b1edd
1414
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
1515
github.com/prometheus/client_golang v1.20.5
1616
github.com/stretchr/testify v1.9.0
@@ -35,9 +35,9 @@ require (
3535
github.com/stretchr/objx v0.5.2 // indirect
3636
go.uber.org/atomic v1.10.0 // indirect
3737
go.uber.org/multierr v1.11.0 // indirect
38-
golang.org/x/net v0.41.0 // indirect
39-
golang.org/x/sys v0.33.0 // indirect
40-
golang.org/x/text v0.26.0 // indirect
38+
golang.org/x/net v0.51.0 // indirect
39+
golang.org/x/sys v0.41.0 // indirect
40+
golang.org/x/text v0.34.0 // indirect
4141
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
4242
google.golang.org/protobuf v1.36.6 // indirect
4343
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect

client/go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c h1:xpW9bvK+HuuTm
5353
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
5454
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
5555
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
56-
github.com/pingcap/kvproto v0.0.0-20260320060847-534bbfabf736 h1:GKdGsEfcE4ImbSN24AIt51t+3sUyqNTLoeUaJiZld8s=
57-
github.com/pingcap/kvproto v0.0.0-20260320060847-534bbfabf736/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
56+
github.com/pingcap/kvproto v0.0.0-20260326084500-678ff92b1edd h1:FA2DzGly3tuBWFjktkJxmqeOVEqgrsUvKMQXAw9xvWE=
57+
github.com/pingcap/kvproto v0.0.0-20260326084500-678ff92b1edd/go.mod h1:z6+aAHB7dBkA+LyinEX+48/ImRJ3jag0Hg0c7wkhEvE=
5858
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
5959
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
6060
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -124,8 +124,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
124124
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
125125
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
126126
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
127-
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
128-
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
127+
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
128+
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
129129
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
130130
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
131131
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -136,13 +136,13 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
136136
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
137137
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
138138
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
139-
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
140-
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
139+
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
140+
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
141141
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
142142
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
143143
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
144-
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
145-
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
144+
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
145+
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
146146
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
147147
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
148148
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
@@ -151,8 +151,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
151151
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
152152
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
153153
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
154-
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
155-
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
154+
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
155+
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
156156
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
157157
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
158158
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

client/http/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ type HotPeersStat struct {
170170
StoreByteRate float64 `json:"store_bytes"`
171171
StoreKeyRate float64 `json:"store_keys"`
172172
StoreQueryRate float64 `json:"store_query"`
173+
StoreCPURate float64 `json:"store_cpu"`
173174
TotalBytesRate float64 `json:"total_flow_bytes"`
174175
TotalKeysRate float64 `json:"total_flow_keys"`
175176
TotalQueryRate float64 `json:"total_flow_query"`
177+
TotalCPURate float64 `json:"total_flow_cpu"`
176178
Count int `json:"regions_count"`
177179
Stats []HotPeerStatShow `json:"statistics"`
178180
}
@@ -188,6 +190,7 @@ type HotPeerStatShow struct {
188190
ByteRate float64 `json:"flow_bytes"`
189191
KeyRate float64 `json:"flow_keys"`
190192
QueryRate float64 `json:"flow_query"`
193+
CPURate float64 `json:"flow_cpu"`
191194
AntiCount int `json:"anti_count"`
192195
LastUpdateTime time.Time `json:"last_update_time,omitempty"`
193196
}
@@ -249,6 +252,7 @@ type HistoryHotRegion struct {
249252
HotRegionType string `json:"hot_region_type"`
250253
HotDegree int64 `json:"hot_degree"`
251254
FlowBytes float64 `json:"flow_bytes"`
255+
FlowCPU float64 `json:"flow_cpu"`
252256
KeyRate float64 `json:"key_rate"`
253257
QueryRate float64 `json:"query_rate"`
254258
StartKey string `json:"start_key"`

client/http/types_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,78 @@ func TestRuleOpStartEndKey(t *testing.T) {
300300
re.Equal(ruleOpToMarshal.DeleteByIDPrefix, ruleOp.DeleteByIDPrefix)
301301
}
302302

303+
func TestHotRegionStatsCPUFields(t *testing.T) {
304+
re := require.New(t)
305+
raw := []byte(`{
306+
"as_peer": {
307+
"1": {
308+
"store_bytes": 10,
309+
"store_keys": 11,
310+
"store_query": 12,
311+
"store_cpu": 13,
312+
"total_flow_bytes": 20,
313+
"total_flow_keys": 21,
314+
"total_flow_query": 22,
315+
"total_flow_cpu": 23,
316+
"regions_count": 1,
317+
"statistics": [{
318+
"store_id": 1,
319+
"stores": [1, 2],
320+
"is_leader": true,
321+
"is_learner": false,
322+
"region_id": 100,
323+
"hot_degree": 6,
324+
"flow_bytes": 30,
325+
"flow_keys": 31,
326+
"flow_query": 32,
327+
"flow_cpu": 33,
328+
"anti_count": 4
329+
}]
330+
}
331+
},
332+
"as_leader": {
333+
"2": {
334+
"store_bytes": 40,
335+
"store_keys": 41,
336+
"store_query": 42,
337+
"store_cpu": 43,
338+
"total_flow_bytes": 50,
339+
"total_flow_keys": 51,
340+
"total_flow_query": 52,
341+
"total_flow_cpu": 53,
342+
"regions_count": 1,
343+
"statistics": [{
344+
"store_id": 2,
345+
"stores": [2, 3],
346+
"is_leader": true,
347+
"is_learner": false,
348+
"region_id": 200,
349+
"hot_degree": 7,
350+
"flow_bytes": 60,
351+
"flow_keys": 61,
352+
"flow_query": 62,
353+
"flow_cpu": 63,
354+
"anti_count": 5
355+
}]
356+
}
357+
}
358+
}`)
359+
360+
var stats StoreHotPeersInfos
361+
err := json.Unmarshal(raw, &stats)
362+
re.NoError(err)
363+
364+
re.Equal(13.0, stats.AsPeer[1].StoreCPURate)
365+
re.Equal(23.0, stats.AsPeer[1].TotalCPURate)
366+
re.Len(stats.AsPeer[1].Stats, 1)
367+
re.Equal(33.0, stats.AsPeer[1].Stats[0].CPURate)
368+
369+
re.Equal(43.0, stats.AsLeader[2].StoreCPURate)
370+
re.Equal(53.0, stats.AsLeader[2].TotalCPURate)
371+
re.Len(stats.AsLeader[2].Stats, 1)
372+
re.Equal(63.0, stats.AsLeader[2].Stats[0].CPURate)
373+
}
374+
303375
func mustMarshalAndUnmarshalRuleOp(re *require.Assertions, ruleOp *RuleOp) *RuleOp {
304376
ruleOpJSON, err := json.Marshal(ruleOp)
305377
re.NoError(err)

go.mod

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require (
3535
github.com/pingcap/errcode v0.3.0
3636
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
3737
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
38-
github.com/pingcap/kvproto v0.0.0-20260320060847-534bbfabf736
38+
github.com/pingcap/kvproto v0.0.0-20260326084500-678ff92b1edd
3939
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
4040
github.com/pingcap/metering_sdk v0.0.0-20260203082503-b9f282339654
4141
github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21
@@ -62,7 +62,7 @@ require (
6262
go.uber.org/goleak v1.3.0
6363
go.uber.org/zap v1.27.0
6464
golang.org/x/time v0.5.0
65-
golang.org/x/tools v0.38.0
65+
golang.org/x/tools v0.41.0
6666
google.golang.org/grpc v1.75.1
6767
gotest.tools/gotestsum v1.7.0
6868
)
@@ -227,17 +227,17 @@ require (
227227
go.uber.org/fx v1.12.0 // indirect
228228
go.uber.org/multierr v1.11.0
229229
golang.org/x/arch v0.22.0 // indirect
230-
golang.org/x/crypto v0.45.0 // indirect
230+
golang.org/x/crypto v0.48.0 // indirect
231231
golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4 // indirect
232232
golang.org/x/image v0.18.0 // indirect
233-
golang.org/x/mod v0.29.0 // indirect
234-
golang.org/x/net v0.47.0 // indirect
233+
golang.org/x/mod v0.32.0 // indirect
234+
golang.org/x/net v0.51.0 // indirect
235235
golang.org/x/oauth2 v0.30.0 // indirect
236-
golang.org/x/sync v0.18.0 // indirect
237-
golang.org/x/sys v0.38.0 // indirect
238-
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 // indirect
239-
golang.org/x/term v0.37.0 // indirect
240-
golang.org/x/text v0.31.0 // indirect
236+
golang.org/x/sync v0.19.0 // indirect
237+
golang.org/x/sys v0.41.0 // indirect
238+
golang.org/x/telemetry v0.0.0-20260109210033-bd525da824e2 // indirect
239+
golang.org/x/term v0.40.0 // indirect
240+
golang.org/x/text v0.34.0 // indirect
241241
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect
242242
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
243243
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect

0 commit comments

Comments
 (0)