Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
Signed-off-by: okJiang <[email protected]>
  • Loading branch information
okJiang committed Jun 24, 2024
1 parent 26e205a commit a31dd0f
Show file tree
Hide file tree
Showing 21 changed files with 40 additions and 30 deletions.
6 changes: 3 additions & 3 deletions pkg/schedule/checker/checker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c *Controller) CheckRegion(region *core.RegionInfo) []*operator.Operator {
if opController.OperatorCount(operator.OpReplica) < c.conf.GetReplicaScheduleLimit() {
return []*operator.Operator{op}
}
operator.OperatorLimitCounter.WithLabelValues(c.ruleChecker.GetType(), operator.OpReplica.String()).Inc()
operator.IncOperatorLimitCounter(c.ruleChecker.GetType(), operator.OpReplica.String())
c.regionWaitingList.Put(region.GetID(), nil)
}
}
Expand All @@ -116,7 +116,7 @@ func (c *Controller) CheckRegion(region *core.RegionInfo) []*operator.Operator {
if opController.OperatorCount(operator.OpReplica) < c.conf.GetReplicaScheduleLimit() {
return []*operator.Operator{op}
}
operator.OperatorLimitCounter.WithLabelValues(c.replicaChecker.GetType(), operator.OpReplica.String()).Inc()
operator.IncOperatorLimitCounter(c.replicaChecker.GetType(), operator.OpReplica.String())
c.regionWaitingList.Put(region.GetID(), nil)
}
}
Expand All @@ -133,7 +133,7 @@ func (c *Controller) CheckRegion(region *core.RegionInfo) []*operator.Operator {
if c.mergeChecker != nil {
allowed := opController.OperatorCount(operator.OpMerge) < c.conf.GetMergeScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(c.mergeChecker.GetType(), operator.OpMerge.String()).Inc()
operator.IncOperatorLimitCounter(c.mergeChecker.GetType(), operator.OpMerge.String())
} else if ops := c.mergeChecker.Check(region); ops != nil {
// It makes sure that two operators can be added successfully altogether.
return ops
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/checker/rule_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (c *RuleChecker) allowLeader(fit *placement.RegionFit, peer *metapb.Peer) b
if s == nil {
return false
}
stateFilter := &filter.StoreStateFilter{ActionScope: "rule_checker", TransferLeader: true}
stateFilter := &filter.StoreStateFilter{ActionScope: c.name.String(), TransferLeader: true}
if !stateFilter.Target(c.cluster.GetCheckerConfig(), s).IsOK() {
return false
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/schedule/filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package filter

import (
"strconv"
"strings"

"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/log"
Expand Down Expand Up @@ -338,7 +339,7 @@ type StoreStateFilter struct {

// Scope returns the scheduler or the checker which the filter acts on.
func (f *StoreStateFilter) Scope() string {
return f.ActionScope
return strings.ReplaceAll(f.ActionScope, "_", "-")
}

// Type returns the type of the Filter.
Expand Down
17 changes: 13 additions & 4 deletions pkg/schedule/operator/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package operator

import "github.com/prometheus/client_golang/prometheus"
import (
"strings"

"github.com/prometheus/client_golang/prometheus"
)

var (
operatorStepDuration = prometheus.NewHistogramVec(
Expand All @@ -26,8 +30,7 @@ var (
Buckets: []float64{0.5, 1, 2, 4, 8, 16, 20, 40, 60, 90, 120, 180, 240, 300, 480, 600, 720, 900, 1200, 1800, 3600},
}, []string{"type"})

// OperatorLimitCounter exposes the counter when meeting limit.
OperatorLimitCounter = prometheus.NewCounterVec(
operatorLimitCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "pd",
Subsystem: "schedule",
Expand Down Expand Up @@ -82,10 +85,16 @@ var (

func init() {
prometheus.MustRegister(operatorStepDuration)
prometheus.MustRegister(OperatorLimitCounter)
prometheus.MustRegister(operatorLimitCounter)
prometheus.MustRegister(OperatorExceededStoreLimitCounter)
prometheus.MustRegister(operatorCounter)
prometheus.MustRegister(operatorDuration)
prometheus.MustRegister(operatorSizeHist)
prometheus.MustRegister(storeLimitCostCounter)
}

// IncOperatorLimitCounter increases the counter of operator meeting limit.
func IncOperatorLimitCounter(typ, name string) {
operatorLimitCounter.WithLabelValues(
strings.ReplaceAll(typ, "_", "-"), name).Inc()
}
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/balance_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (l *balanceLeaderScheduler) ReloadConfig() error {
func (l *balanceLeaderScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := l.OpController.OperatorCount(operator.OpLeader) < cluster.GetSchedulerConfig().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(l.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(l.GetType(), operator.OpLeader.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/balance_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (s *balanceRegionScheduler) EncodeConfig() ([]byte, error) {
func (s *balanceRegionScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := s.OpController.OperatorCount(operator.OpRegion) < cluster.GetSchedulerConfig().GetRegionScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpRegion.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpRegion.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/balance_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (b *balanceWitnessScheduler) ReloadConfig() error {
func (b *balanceWitnessScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := b.OpController.OperatorCount(operator.OpWitness) < cluster.GetSchedulerConfig().GetWitnessScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(b.GetType(), operator.OpWitness.String()).Inc()
operator.IncOperatorLimitCounter(b.GetType(), operator.OpWitness.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/evict_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (s *evictLeaderScheduler) CleanConfig(cluster sche.SchedulerCluster) {
func (s *evictLeaderScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := s.OpController.OperatorCount(operator.OpLeader) < cluster.GetSchedulerConfig().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpLeader.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/evict_slow_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (s *evictSlowStoreScheduler) IsScheduleAllowed(cluster sche.SchedulerCluste
if s.conf.evictStore() != 0 {
allowed := s.OpController.OperatorCount(operator.OpLeader) < cluster.GetSchedulerConfig().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpLeader.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/evict_slow_trend.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (s *evictSlowTrendScheduler) IsScheduleAllowed(cluster sche.SchedulerCluste
}
allowed := s.OpController.OperatorCount(operator.OpLeader) < cluster.GetSchedulerConfig().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpLeader.String())
}
return allowed
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/schedule/schedulers/grant_hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ func (s *grantHotRegionScheduler) IsScheduleAllowed(cluster sche.SchedulerCluste
regionAllowed := s.OpController.OperatorCount(operator.OpRegion) < conf.GetRegionScheduleLimit()
leaderAllowed := s.OpController.OperatorCount(operator.OpLeader) < conf.GetLeaderScheduleLimit()
if !regionAllowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpRegion.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpRegion.String())
}
if !leaderAllowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpLeader.String())
}
return regionAllowed && leaderAllowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/grant_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (s *grantLeaderScheduler) CleanConfig(cluster sche.SchedulerCluster) {
func (s *grantLeaderScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := s.OpController.OperatorCount(operator.OpLeader) < cluster.GetSchedulerConfig().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpLeader.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (h *hotScheduler) GetNextInterval(time.Duration) time.Duration {
func (h *hotScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := h.OpController.OperatorCount(operator.OpHotRegion) < cluster.GetSchedulerConfig().GetHotRegionScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(h.GetType(), operator.OpHotRegion.String()).Inc()
operator.IncOperatorLimitCounter(h.GetType(), operator.OpHotRegion.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s *labelScheduler) EncodeConfig() ([]byte, error) {
func (s *labelScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := s.OpController.OperatorCount(operator.OpLeader) < cluster.GetSchedulerConfig().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpLeader.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/random_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *randomMergeScheduler) EncodeConfig() ([]byte, error) {
func (s *randomMergeScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := s.OpController.OperatorCount(operator.OpMerge) < cluster.GetSchedulerConfig().GetMergeScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpMerge.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpMerge.String())
}
return allowed
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/schedule/schedulers/scatter_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ func (l *scatterRangeScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster)
func (l *scatterRangeScheduler) allowBalanceLeader(cluster sche.SchedulerCluster) bool {
allowed := l.OpController.OperatorCount(operator.OpRange) < cluster.GetSchedulerConfig().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(l.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(l.GetType(), operator.OpLeader.String())
}
return allowed
}

func (l *scatterRangeScheduler) allowBalanceRegion(cluster sche.SchedulerCluster) bool {
allowed := l.OpController.OperatorCount(operator.OpRange) < cluster.GetSchedulerConfig().GetRegionScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(l.GetType(), operator.OpRegion.String()).Inc()
operator.IncOperatorLimitCounter(l.GetType(), operator.OpRegion.String())
}
return allowed
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/schedule/schedulers/shuffle_hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ func (s *shuffleHotRegionScheduler) IsScheduleAllowed(cluster sche.SchedulerClus
regionAllowed := s.OpController.OperatorCount(operator.OpRegion) < conf.GetRegionScheduleLimit()
leaderAllowed := s.OpController.OperatorCount(operator.OpLeader) < conf.GetLeaderScheduleLimit()
if !hotRegionAllowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpHotRegion.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpHotRegion.String())
}
if !regionAllowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpRegion.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpRegion.String())
}
if !leaderAllowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpLeader.String())
}
return hotRegionAllowed && regionAllowed && leaderAllowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/shuffle_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *shuffleLeaderScheduler) EncodeConfig() ([]byte, error) {
func (s *shuffleLeaderScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := s.OpController.OperatorCount(operator.OpLeader) < cluster.GetSchedulerConfig().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpLeader.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/shuffle_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *shuffleRegionScheduler) ReloadConfig() error {
func (s *shuffleRegionScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := s.OpController.OperatorCount(operator.OpRegion) < cluster.GetSchedulerConfig().GetRegionScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpRegion.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpRegion.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/split_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (s *splitBucketScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster)
allowed := s.BaseScheduler.OpController.OperatorCount(operator.OpSplit) < s.conf.getSplitLimit()
if !allowed {
splitBuckerSplitLimitCounter.Inc()
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpSplit.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpSplit.String())
}
return allowed
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/scheduler_example/evict_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (s *evictLeaderScheduler) CleanConfig(cluster sche.SchedulerCluster) {
func (s *evictLeaderScheduler) IsScheduleAllowed(cluster sche.SchedulerCluster) bool {
allowed := s.OpController.OperatorCount(operator.OpLeader) < cluster.GetSchedulerConfig().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
operator.IncOperatorLimitCounter(s.GetType(), operator.OpLeader.String())
}
return allowed
}
Expand Down

0 comments on commit a31dd0f

Please sign in to comment.