Skip to content

Commit

Permalink
enhance: Prevent frequently updating metric
Browse files Browse the repository at this point in the history
Signed-off-by: bigsheeper <[email protected]>
  • Loading branch information
bigsheeper committed Dec 27, 2024
1 parent 445b937 commit fccdfc1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/querycoordv2/task/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ type taskScheduler struct {
channelTasks map[replicaChannelIndex]Task
processQueue *taskQueue
waitQueue *taskQueue
<<<<<<< HEAD
taskStats *expirable.LRU[UniqueID, Task]
=======

lastUpdateMetricTime time.Time
>>>>>>> 3044ecff8f (enhance: Prevent frequently updating metric)
}

func NewScheduler(ctx context.Context,
Expand Down Expand Up @@ -285,13 +290,15 @@ func (scheduler *taskScheduler) Add(task Task) error {
}

scheduler.taskStats.Add(task.ID(), task)
scheduler.updateTaskMetrics()
log.Ctx(task.Context()).Info("task added", zap.String("task", task.String()))
task.RecordStartTs()
return nil
}

func (scheduler *taskScheduler) updateTaskMetrics() {
if time.Since(scheduler.lastUpdateMetricTime) < 30*time.Second {
return
}
segmentGrowNum, segmentReduceNum, segmentMoveNum := 0, 0, 0
channelGrowNum, channelReduceNum, channelMoveNum := 0, 0, 0
for _, task := range scheduler.segmentTasks {
Expand Down Expand Up @@ -324,6 +331,7 @@ func (scheduler *taskScheduler) updateTaskMetrics() {
metrics.QueryCoordTaskNum.WithLabelValues(metrics.ChannelGrowTaskLabel).Set(float64(channelGrowNum))
metrics.QueryCoordTaskNum.WithLabelValues(metrics.ChannelReduceTaskLabel).Set(float64(channelReduceNum))
metrics.QueryCoordTaskNum.WithLabelValues(metrics.ChannelMoveTaskLabel).Set(float64(channelMoveNum))
scheduler.lastUpdateMetricTime = time.Now()
}

// check whether the task is valid to add,
Expand Down

0 comments on commit fccdfc1

Please sign in to comment.