From 469dbd4f0602d4094237d1bc59835dd84ddf535a Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Thu, 17 Sep 2020 16:05:38 +0800 Subject: [PATCH 1/3] cherry pick #2962 to release-4.0 Signed-off-by: ti-srebot --- server/schedule/operator/operator.go | 15 +++++++++++++++ server/schedule/operator_controller.go | 3 +++ server/schedulers/balance_leader.go | 8 ++++++++ server/schedulers/balance_region.go | 8 ++++++++ server/schedulers/balance_test.go | 3 ++- 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/server/schedule/operator/operator.go b/server/schedule/operator/operator.go index 464cad36751..4889c5f60cc 100644 --- a/server/schedule/operator/operator.go +++ b/server/schedule/operator/operator.go @@ -49,6 +49,7 @@ type Cluster interface { // Operator contains execution steps generated by scheduler. type Operator struct { +<<<<<<< HEAD desc string brief string regionID uint64 @@ -60,6 +61,20 @@ type Operator struct { stepTime int64 level core.PriorityLevel Counters []prometheus.Counter +======= + desc string + brief string + regionID uint64 + regionEpoch *metapb.RegionEpoch + kind OpKind + steps []OpStep + stepsTime []int64 // step finish time + currentStep int32 + status OpStatusTracker + level core.PriorityLevel + Counters []prometheus.Counter + FinishedCounters []prometheus.Counter +>>>>>>> 14d559b... metrics: make counter inc when operator finished rather than operator add (#2962) } // NewOperator creates a new operator. diff --git a/server/schedule/operator_controller.go b/server/schedule/operator_controller.go index 736fd0dfa49..8cf37543aab 100644 --- a/server/schedule/operator_controller.go +++ b/server/schedule/operator_controller.go @@ -539,6 +539,9 @@ func (oc *OperatorController) buryOperator(op *operator.Operator, extraFileds .. zap.Reflect("operator", op)) operatorCounter.WithLabelValues(op.Desc(), "finish").Inc() operatorDuration.WithLabelValues(op.Desc()).Observe(op.RunningTime().Seconds()) + for _, counter := range op.FinishedCounters { + counter.Inc() + } case operator.REPLACED: log.Info("replace old operator", zap.Uint64("region-id", op.RegionID()), diff --git a/server/schedulers/balance_leader.go b/server/schedulers/balance_leader.go index 22953617402..495978f5e8a 100644 --- a/server/schedulers/balance_leader.go +++ b/server/schedulers/balance_leader.go @@ -287,9 +287,17 @@ func (l *balanceLeaderScheduler) createOperator(cluster opt.Cluster, region *cor targetLabel := strconv.FormatUint(targetID, 10) op.Counters = append(op.Counters, schedulerCounter.WithLabelValues(l.GetName(), "new-operator"), +<<<<<<< HEAD l.counter.WithLabelValues("move-leader", source.GetAddress()+"-out", sourceLabel), l.counter.WithLabelValues("move-leader", target.GetAddress()+"-in", targetLabel), balanceDirectionCounter.WithLabelValues(l.GetName(), sourceLabel, targetLabel), +======= + balanceDirectionCounter.WithLabelValues(l.GetName(), sourceLabel, targetLabel), + ) + op.FinishedCounters = append(op.FinishedCounters, + l.counter.WithLabelValues("move-leader", sourceLabel+"-out"), + l.counter.WithLabelValues("move-leader", targetLabel+"-in"), +>>>>>>> 14d559b... metrics: make counter inc when operator finished rather than operator add (#2962) ) return []*operator.Operator{op} } diff --git a/server/schedulers/balance_region.go b/server/schedulers/balance_region.go index f0d3ac719aa..b44bb092812 100644 --- a/server/schedulers/balance_region.go +++ b/server/schedulers/balance_region.go @@ -242,9 +242,17 @@ func (s *balanceRegionScheduler) transferPeer(cluster opt.Cluster, region *core. sourceLabel := strconv.FormatUint(sourceID, 10) targetLabel := strconv.FormatUint(targetID, 10) op.Counters = append(op.Counters, +<<<<<<< HEAD s.counter.WithLabelValues("move-peer", source.GetAddress()+"-out", sourceLabel), s.counter.WithLabelValues("move-peer", target.GetAddress()+"-in", targetLabel), balanceDirectionCounter.WithLabelValues(s.GetName(), sourceLabel, targetLabel), +======= + balanceDirectionCounter.WithLabelValues(s.GetName(), sourceLabel, targetLabel), + ) + op.FinishedCounters = append(op.FinishedCounters, + s.counter.WithLabelValues("move-peer", sourceLabel+"-out"), + s.counter.WithLabelValues("move-peer", targetLabel+"-in"), +>>>>>>> 14d559b... metrics: make counter inc when operator finished rather than operator add (#2962) ) return op } diff --git a/server/schedulers/balance_test.go b/server/schedulers/balance_test.go index 09dc78b5a9a..19be8e2625c 100644 --- a/server/schedulers/balance_test.go +++ b/server/schedulers/balance_test.go @@ -454,7 +454,8 @@ func (s *testBalanceLeaderRangeSchedulerSuite) TestSingleRangeBalance(c *C) { ops := lb.Schedule(s.tc) c.Assert(ops, NotNil) c.Assert(ops, HasLen, 1) - c.Assert(ops[0].Counters, HasLen, 5) + c.Assert(ops[0].Counters, HasLen, 3) + c.Assert(ops[0].FinishedCounters, HasLen, 2) lb, err = schedule.CreateScheduler(BalanceLeaderType, s.oc, core.NewStorage(kv.NewMemoryKV()), schedule.ConfigSliceDecoder(BalanceLeaderType, []string{"h", "n"})) c.Assert(err, IsNil) c.Assert(lb.Schedule(s.tc), IsNil) From e09be414f92f18b51e1fe0db35ca02a5328a04b4 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Thu, 17 Sep 2020 16:24:03 +0800 Subject: [PATCH 2/3] fix conflict Signed-off-by: lhy1024 --- server/schedule/operator/operator.go | 14 -------------- server/schedulers/balance_leader.go | 10 ++-------- server/schedulers/balance_region.go | 10 ++-------- 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/server/schedule/operator/operator.go b/server/schedule/operator/operator.go index 4889c5f60cc..8d39a6a1848 100644 --- a/server/schedule/operator/operator.go +++ b/server/schedule/operator/operator.go @@ -49,7 +49,6 @@ type Cluster interface { // Operator contains execution steps generated by scheduler. type Operator struct { -<<<<<<< HEAD desc string brief string regionID uint64 @@ -61,20 +60,7 @@ type Operator struct { stepTime int64 level core.PriorityLevel Counters []prometheus.Counter -======= - desc string - brief string - regionID uint64 - regionEpoch *metapb.RegionEpoch - kind OpKind - steps []OpStep - stepsTime []int64 // step finish time - currentStep int32 - status OpStatusTracker - level core.PriorityLevel - Counters []prometheus.Counter FinishedCounters []prometheus.Counter ->>>>>>> 14d559b... metrics: make counter inc when operator finished rather than operator add (#2962) } // NewOperator creates a new operator. diff --git a/server/schedulers/balance_leader.go b/server/schedulers/balance_leader.go index 495978f5e8a..c4d44a7da60 100644 --- a/server/schedulers/balance_leader.go +++ b/server/schedulers/balance_leader.go @@ -287,17 +287,11 @@ func (l *balanceLeaderScheduler) createOperator(cluster opt.Cluster, region *cor targetLabel := strconv.FormatUint(targetID, 10) op.Counters = append(op.Counters, schedulerCounter.WithLabelValues(l.GetName(), "new-operator"), -<<<<<<< HEAD - l.counter.WithLabelValues("move-leader", source.GetAddress()+"-out", sourceLabel), - l.counter.WithLabelValues("move-leader", target.GetAddress()+"-in", targetLabel), - balanceDirectionCounter.WithLabelValues(l.GetName(), sourceLabel, targetLabel), -======= balanceDirectionCounter.WithLabelValues(l.GetName(), sourceLabel, targetLabel), ) op.FinishedCounters = append(op.FinishedCounters, - l.counter.WithLabelValues("move-leader", sourceLabel+"-out"), - l.counter.WithLabelValues("move-leader", targetLabel+"-in"), ->>>>>>> 14d559b... metrics: make counter inc when operator finished rather than operator add (#2962) + l.counter.WithLabelValues("move-leader", source.GetAddress()+"-out", sourceLabel), + l.counter.WithLabelValues("move-leader", target.GetAddress()+"-in", targetLabel), ) return []*operator.Operator{op} } diff --git a/server/schedulers/balance_region.go b/server/schedulers/balance_region.go index b44bb092812..77b21af247c 100644 --- a/server/schedulers/balance_region.go +++ b/server/schedulers/balance_region.go @@ -242,17 +242,11 @@ func (s *balanceRegionScheduler) transferPeer(cluster opt.Cluster, region *core. sourceLabel := strconv.FormatUint(sourceID, 10) targetLabel := strconv.FormatUint(targetID, 10) op.Counters = append(op.Counters, -<<<<<<< HEAD - s.counter.WithLabelValues("move-peer", source.GetAddress()+"-out", sourceLabel), - s.counter.WithLabelValues("move-peer", target.GetAddress()+"-in", targetLabel), - balanceDirectionCounter.WithLabelValues(s.GetName(), sourceLabel, targetLabel), -======= balanceDirectionCounter.WithLabelValues(s.GetName(), sourceLabel, targetLabel), ) op.FinishedCounters = append(op.FinishedCounters, - s.counter.WithLabelValues("move-peer", sourceLabel+"-out"), - s.counter.WithLabelValues("move-peer", targetLabel+"-in"), ->>>>>>> 14d559b... metrics: make counter inc when operator finished rather than operator add (#2962) + s.counter.WithLabelValues("move-peer", source.GetAddress()+"-out", sourceLabel), + s.counter.WithLabelValues("move-peer", target.GetAddress()+"-in", targetLabel), ) return op } From acb2b3a34c901f1dc22f346c7fbf535117e3cea6 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Thu, 17 Sep 2020 16:35:01 +0800 Subject: [PATCH 3/3] lint Signed-off-by: lhy1024 --- server/schedule/operator/operator.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/server/schedule/operator/operator.go b/server/schedule/operator/operator.go index 8d39a6a1848..6c7dbb70661 100644 --- a/server/schedule/operator/operator.go +++ b/server/schedule/operator/operator.go @@ -49,17 +49,17 @@ type Cluster interface { // Operator contains execution steps generated by scheduler. type Operator struct { - desc string - brief string - regionID uint64 - regionEpoch *metapb.RegionEpoch - kind OpKind - steps []OpStep - currentStep int32 - status OpStatusTracker - stepTime int64 - level core.PriorityLevel - Counters []prometheus.Counter + desc string + brief string + regionID uint64 + regionEpoch *metapb.RegionEpoch + kind OpKind + steps []OpStep + currentStep int32 + status OpStatusTracker + stepTime int64 + level core.PriorityLevel + Counters []prometheus.Counter FinishedCounters []prometheus.Counter }