From 034b35b06ec8aa56f0bf11d1e7f509ddb5b20b91 Mon Sep 17 00:00:00 2001 From: Hu# Date: Fri, 26 Apr 2024 10:12:11 +0800 Subject: [PATCH] This is an automated cherry-pick of #8124 close tikv/pd#8125 Signed-off-by: ti-chi-bot --- server/schedule/filter/counter.go | 4 ++++ server/schedulers/balance_leader.go | 7 +++++++ server/schedulers/balance_region.go | 7 +++++++ server/schedulers/scatter_range.go | 8 ++++++++ 4 files changed, 26 insertions(+) diff --git a/server/schedule/filter/counter.go b/server/schedule/filter/counter.go index 783eabfe6f72..85fba292c966 100644 --- a/server/schedule/filter/counter.go +++ b/server/schedule/filter/counter.go @@ -183,6 +183,10 @@ func NewCounter(scope string) *Counter { return &Counter{counter: counter, scope: scope} } +func (c *Counter) SetScope(scope string) { + c.scope = scope +} + // Add adds the filter counter. func (c *Counter) inc(action action, filterType filterType, sourceID uint64, targetID uint64) { if _, ok := c.counter[action][filterType][sourceID]; !ok { diff --git a/server/schedulers/balance_leader.go b/server/schedulers/balance_leader.go index 209b94feb82e..f1ca40b8d848 100644 --- a/server/schedulers/balance_leader.go +++ b/server/schedulers/balance_leader.go @@ -217,10 +217,17 @@ func (l *balanceLeaderScheduler) ServeHTTP(w http.ResponseWriter, r *http.Reques // BalanceLeaderCreateOption is used to create a scheduler with an option. type BalanceLeaderCreateOption func(s *balanceLeaderScheduler) +<<<<<<< HEAD:server/schedulers/balance_leader.go // WithBalanceLeaderCounter sets the counter for the scheduler. func WithBalanceLeaderCounter(counter *prometheus.CounterVec) BalanceLeaderCreateOption { return func(s *balanceLeaderScheduler) { s.counter = counter +======= +// WithBalanceLeaderFilterCounterName sets the filter counter name for the scheduler. +func WithBalanceLeaderFilterCounterName(name string) BalanceLeaderCreateOption { + return func(s *balanceLeaderScheduler) { + s.filterCounter.SetScope(name) +>>>>>>> 50c80407c (scheduler: fix scatter counter name (#8124)):pkg/schedule/schedulers/balance_leader.go } } diff --git a/server/schedulers/balance_region.go b/server/schedulers/balance_region.go index b71ccc082f53..ded1a69cfaf8 100644 --- a/server/schedulers/balance_region.go +++ b/server/schedulers/balance_region.go @@ -119,6 +119,13 @@ func WithBalanceRegionName(name string) BalanceRegionCreateOption { } } +// WithBalanceRegionFilterCounterName sets the filter counter name for the scheduler. +func WithBalanceRegionFilterCounterName(name string) BalanceRegionCreateOption { + return func(s *balanceRegionScheduler) { + s.filterCounter.SetScope(name) + } +} + func (s *balanceRegionScheduler) GetName() string { return s.conf.Name } diff --git a/server/schedulers/scatter_range.go b/server/schedulers/scatter_range.go index 5d4d7fd68913..0eb866e87d43 100644 --- a/server/schedulers/scatter_range.go +++ b/server/schedulers/scatter_range.go @@ -164,13 +164,21 @@ func newScatterRangeScheduler(opController *schedule.OperatorController, config opController, &balanceLeaderSchedulerConfig{Ranges: []core.KeyRange{core.NewKeyRange("", "")}}, WithBalanceLeaderName("scatter-range-leader"), +<<<<<<< HEAD:server/schedulers/scatter_range.go WithBalanceLeaderCounter(scatterRangeLeaderCounter), +======= + WithBalanceLeaderFilterCounterName("scatter-range-leader"), +>>>>>>> 50c80407c (scheduler: fix scatter counter name (#8124)):pkg/schedule/schedulers/scatter_range.go ), balanceRegion: newBalanceRegionScheduler( opController, &balanceRegionSchedulerConfig{Ranges: []core.KeyRange{core.NewKeyRange("", "")}}, WithBalanceRegionName("scatter-range-region"), +<<<<<<< HEAD:server/schedulers/scatter_range.go WithBalanceRegionCounter(scatterRangeRegionCounter), +======= + WithBalanceRegionFilterCounterName("scatter-range-region"), +>>>>>>> 50c80407c (scheduler: fix scatter counter name (#8124)):pkg/schedule/schedulers/scatter_range.go ), } return scheduler