Skip to content

Commit

Permalink
clean up handling metrics process
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Nov 15, 2023
1 parent 52858a1 commit eee7c2b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 41 deletions.
16 changes: 0 additions & 16 deletions pkg/mcs/scheduling/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,6 @@ func (c *Cluster) collectMetrics() {

c.coordinator.GetSchedulersController().CollectSchedulerMetrics()
c.coordinator.CollectHotSpotMetrics()
c.collectClusterMetrics()
}

func (c *Cluster) collectClusterMetrics() {
if c.regionStats == nil {
return
}
Expand All @@ -501,20 +497,8 @@ func (c *Cluster) collectClusterMetrics() {

func (c *Cluster) resetMetrics() {
statistics.Reset()

schedulers.ResetSchedulerMetrics()
schedule.ResetHotSpotMetrics()
c.resetClusterMetrics()
}

func (c *Cluster) resetClusterMetrics() {
if c.regionStats == nil {
return
}
c.regionStats.Reset()
c.labelStats.Reset()
// reset hot cache metrics
c.hotStat.ResetMetrics()
}

// StartBackgroundJobs starts background jobs.
Expand Down
4 changes: 2 additions & 2 deletions pkg/statistics/hot_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (w *HotCache) CollectMetrics() {
w.CheckReadAsync(newCollectMetricsTask())
}

// ResetMetrics resets the hot cache metrics.
func (w *HotCache) ResetMetrics() {
// ResetHotCacheStatusMetrics resets the hot cache metrics.
func ResetHotCacheStatusMetrics() {
hotCacheStatusGauge.Reset()
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/statistics/region_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ func (r *RegionStatistics) Collect() {
regionWitnessLeaderRegionCounter.Set(float64(len(r.stats[WitnessLeader])))
}

// Reset resets the metrics of the regions' status.
func (r *RegionStatistics) Reset() {
// ResetRegionStatsMetrics resets the metrics of the regions' status.
func ResetRegionStatsMetrics() {
regionMissPeerRegionCounter.Set(0)
regionExtraPeerRegionCounter.Set(0)
regionDownPeerRegionCounter.Set(0)
Expand Down Expand Up @@ -326,8 +326,8 @@ func (l *LabelStatistics) Collect() {
}
}

// Reset resets the metrics of the label status.
func (l *LabelStatistics) Reset() {
// ResetLabelStatsMetrics resets the metrics of the label status.
func ResetLabelStatsMetrics() {
regionLabelLevelGauge.Reset()
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/statistics/store_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,7 @@ func Reset() {
storeStatusGauge.Reset()
clusterStatusGauge.Reset()
placementStatusGauge.Reset()
ResetRegionStatsMetrics()
ResetLabelStatsMetrics()
ResetHotCacheStatusMetrics()
}
14 changes: 10 additions & 4 deletions server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2500,14 +2500,17 @@ func TestCollectMetricsConcurrent(t *testing.T) {
}(i)
}
controller := co.GetSchedulersController()
rc := co.GetCluster().(*RaftCluster)
rc.SchedulingController = NewSchedulingController(rc.serverCtx, rc.GetBasicCluster(), rc.GetOpts(), rc.GetRuleManager())
rc.SchedulingController.coordinator = co
for i := 0; i < 1000; i++ {
co.CollectHotSpotMetrics()
controller.CollectSchedulerMetrics()
co.GetCluster().(*RaftCluster).collectStatisticsMetrics()
rc.collectSchedulingMetrics()
}
schedule.ResetHotSpotMetrics()
schedulers.ResetSchedulerMetrics()
co.GetCluster().(*RaftCluster).resetStatisticsMetrics()
rc.resetSchedulingMetrics()
wg.Wait()
}

Expand Down Expand Up @@ -2535,10 +2538,13 @@ func TestCollectMetrics(t *testing.T) {
}
}
controller := co.GetSchedulersController()
rc := co.GetCluster().(*RaftCluster)
rc.SchedulingController = NewSchedulingController(rc.serverCtx, rc.GetBasicCluster(), rc.GetOpts(), rc.GetRuleManager())
rc.SchedulingController.coordinator = co
for i := 0; i < 1000; i++ {
co.CollectHotSpotMetrics()
controller.CollectSchedulerMetrics()
co.GetCluster().(*RaftCluster).collectStatisticsMetrics()
rc.collectSchedulingMetrics()
}
stores := co.GetCluster().GetStores()
regionStats := co.GetCluster().RegionWriteStats()
Expand All @@ -2553,7 +2559,7 @@ func TestCollectMetrics(t *testing.T) {
re.Equal(status1, status2)
schedule.ResetHotSpotMetrics()
schedulers.ResetSchedulerMetrics()
co.GetCluster().(*RaftCluster).resetStatisticsMetrics()
rc.resetSchedulingMetrics()
}

func prepare(setCfg func(*sc.ScheduleConfig), setTc func(*testCluster), run func(*schedule.Coordinator), re *require.Assertions) (*testCluster, *schedule.Coordinator, func()) {
Expand Down
19 changes: 4 additions & 15 deletions server/cluster/scheduling_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ func (sc *SchedulingController) resetSchedulingMetrics() {
statistics.Reset()
schedulers.ResetSchedulerMetrics()
schedule.ResetHotSpotMetrics()
sc.resetStatisticsMetrics()
statistics.ResetRegionStatsMetrics()
statistics.ResetLabelStatsMetrics()
// reset hot cache metrics
statistics.ResetHotCacheStatusMetrics()
}

func (sc *SchedulingController) collectSchedulingMetrics() {
Expand All @@ -181,20 +184,6 @@ func (sc *SchedulingController) collectSchedulingMetrics() {
statsMap.Collect()
sc.coordinator.GetSchedulersController().CollectSchedulerMetrics()
sc.coordinator.CollectHotSpotMetrics()
sc.collectStatisticsMetrics()
}

func (sc *SchedulingController) resetStatisticsMetrics() {
if sc.regionStats == nil {
return
}
sc.regionStats.Reset()
sc.labelStats.Reset()
// reset hot cache metrics
sc.hotStat.ResetMetrics()
}

func (sc *SchedulingController) collectStatisticsMetrics() {
if sc.regionStats == nil {
return
}
Expand Down

0 comments on commit eee7c2b

Please sign in to comment.