From fd8e5413d4a3dadc58097a0eab7a30d19936686d Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Fri, 1 Nov 2024 11:54:07 +0800 Subject: [PATCH] address comments Signed-off-by: lhy1024 --- pkg/schedule/schedulers/balance_leader.go | 3 --- pkg/schedule/schedulers/balance_region.go | 6 +++--- pkg/schedule/schedulers/metrics.go | 10 ++++++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/schedule/schedulers/balance_leader.go b/pkg/schedule/schedulers/balance_leader.go index 1ea8b300a63..e8aea0d7269 100644 --- a/pkg/schedule/schedulers/balance_leader.go +++ b/pkg/schedule/schedulers/balance_leader.go @@ -518,9 +518,6 @@ func (s *balanceLeaderScheduler) createOperator(solver *solver, collector *plan. solver.calcTargetStoreScore(s.GetName()) if !solver.shouldBalance(s.GetName()) { balanceLeaderSkipCounter.Inc() - if solver.isPotentialReverse() { - balanceLeaderPotentialReverse.Inc() - } if collector != nil { collector.Collect(plan.SetStatus(plan.NewStatus(plan.StatusStoreScoreDisallowed))) } diff --git a/pkg/schedule/schedulers/balance_region.go b/pkg/schedule/schedulers/balance_region.go index 4f889a9210b..bb1f7244997 100644 --- a/pkg/schedule/schedulers/balance_region.go +++ b/pkg/schedule/schedulers/balance_region.go @@ -226,12 +226,14 @@ func (s *balanceRegionScheduler) transferPeer(solver *solver, collector *plan.Co regionID := solver.Region.GetID() sourceID := solver.Source.GetID() targetID := solver.Target.GetID() + sourceLabel := strconv.FormatUint(sourceID, 10) + targetLabel := strconv.FormatUint(targetID, 10) log.Debug("candidate store", zap.Uint64("region-id", regionID), zap.Uint64("source-store", sourceID), zap.Uint64("target-store", targetID)) if !solver.shouldBalance(s.GetName()) { balanceRegionSkipCounter.Inc() if solver.isPotentialReverse() { - balanceRegionPotentialReverse.Inc() + balancePotentialReverseCounter.WithLabelValues(s.GetName(), sourceLabel, targetLabel) } if collector != nil { collector.Collect(plan.SetStatus(plan.NewStatus(plan.StatusStoreScoreDisallowed))) @@ -254,8 +256,6 @@ func (s *balanceRegionScheduler) transferPeer(solver *solver, collector *plan.Co collector.Collect() } solver.Step-- - sourceLabel := strconv.FormatUint(sourceID, 10) - targetLabel := strconv.FormatUint(targetID, 10) op.FinishedCounters = append(op.FinishedCounters, balanceDirectionCounter.WithLabelValues(s.GetName(), sourceLabel, targetLabel), ) diff --git a/pkg/schedule/schedulers/metrics.go b/pkg/schedule/schedulers/metrics.go index 2d4488a8a53..6bd99986710 100644 --- a/pkg/schedule/schedulers/metrics.go +++ b/pkg/schedule/schedulers/metrics.go @@ -79,6 +79,14 @@ var ( Help: "Counter of direction of balance related schedulers.", }, []string{"type", "source", "target"}) + balancePotentialReverseCounter = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "pd", + Subsystem: "scheduler", + Name: "potential_reverse", + Help: "Counter of direction which would introduce potential reverse.", + }, []string{"type", "source", "target"}) + // TODO: pre-allocate gauge metrics hotDirectionCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ @@ -229,7 +237,6 @@ var ( balanceLeaderNoTargetStoreCounter = balanceLeaderCounterWithEvent("no-target-store") balanceLeaderNoFollowerRegionCounter = balanceLeaderCounterWithEvent("no-follower-region") balanceLeaderSkipCounter = balanceLeaderCounterWithEvent("skip") - balanceLeaderPotentialReverse = balanceLeaderCounterWithEvent("potential-reverse") balanceLeaderNewOpCounter = balanceLeaderCounterWithEvent("new-operator") balanceRegionScheduleCounter = balanceRegionCounterWithEvent("schedule") @@ -238,7 +245,6 @@ var ( balanceRegionNoLeaderCounter = balanceRegionCounterWithEvent("no-leader") balanceRegionNewOpCounter = balanceRegionCounterWithEvent("new-operator") balanceRegionSkipCounter = balanceRegionCounterWithEvent("skip") - balanceRegionPotentialReverse = balanceRegionCounterWithEvent("potential-reverse") balanceRegionCreateOpFailCounter = balanceRegionCounterWithEvent("create-operator-fail") balanceRegionNoReplacementCounter = balanceRegionCounterWithEvent("no-replacement")