Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: make counter inc when operator finished rather than operator add (#2962) #2983

Merged
merged 4 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions server/schedule/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,18 @@ 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
}

// NewOperator creates a new operator.
Expand Down
3 changes: 3 additions & 0 deletions server/schedule/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
4 changes: 3 additions & 1 deletion server/schedulers/balance_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +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"),
balanceDirectionCounter.WithLabelValues(l.GetName(), sourceLabel, targetLabel),
)
op.FinishedCounters = append(op.FinishedCounters,
l.counter.WithLabelValues("move-leader", source.GetAddress()+"-out", sourceLabel),
l.counter.WithLabelValues("move-leader", target.GetAddress()+"-in", targetLabel),
balanceDirectionCounter.WithLabelValues(l.GetName(), sourceLabel, targetLabel),
)
return []*operator.Operator{op}
}
4 changes: 3 additions & 1 deletion server/schedulers/balance_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +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,
balanceDirectionCounter.WithLabelValues(s.GetName(), sourceLabel, targetLabel),
)
op.FinishedCounters = append(op.FinishedCounters,
s.counter.WithLabelValues("move-peer", source.GetAddress()+"-out", sourceLabel),
s.counter.WithLabelValues("move-peer", target.GetAddress()+"-in", targetLabel),
balanceDirectionCounter.WithLabelValues(s.GetName(), sourceLabel, targetLabel),
)
return op
}
Expand Down
3 changes: 2 additions & 1 deletion server/schedulers/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down