Skip to content

Commit

Permalink
owner(cdc): clean up stale metrics (pingcap#4775)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzix committed Apr 24, 2022
1 parent 1a35190 commit 57f85ed
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cdc/owner/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func (o *Owner) cleanUpChangefeed(state *orchestrator.ChangefeedReactorState) {
// Bootstrap checks if the state contains incompatible or incorrect information and tries to fix it.
func (o *Owner) Bootstrap(state *orchestrator.GlobalReactorState) {
log.Info("Start bootstrapping")
o.cleanStaleMetrics()
fixChangefeedInfos(state)
}

Expand All @@ -298,16 +299,25 @@ func fixChangefeedInfos(state *orchestrator.GlobalReactorState) {
}
}

func (o *Owner) cleanStaleMetrics() {
// The gauge metrics of the Owner should be reset
// each time a new owner is launched, in case the previous owner
// has crashed and has not cleaned up the stale metrics values.
changefeedCheckpointTsGauge.Reset()
changefeedCheckpointTsLagGauge.Reset()
changefeedResolvedTsGauge.Reset()
changefeedResolvedTsLagGauge.Reset()
ownerMaintainTableNumGauge.Reset()
changefeedStatusGauge.Reset()
}

func (o *Owner) updateMetrics(state *orchestrator.GlobalReactorState) {
// Keep the value of prometheus expression `rate(counter)` = 1
// Please also change alert rule in ticdc.rules.yml when change the expression value.
now := time.Now()
ownershipCounter.Add(float64(now.Sub(o.lastTickTime)) / float64(time.Second))
o.lastTickTime = now

ownerMaintainTableNumGauge.Reset()
changefeedStatusGauge.Reset()

conf := config.GetGlobalServerConfig()

// TODO refactor this piece of code when the new scheduler is stabilized,
Expand Down

0 comments on commit 57f85ed

Please sign in to comment.