Skip to content

Commit 559f218

Browse files
authored
dxf: fix the task num count incorrectly (#57127)
close #57172
1 parent 120b36b commit 559f218

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

pkg/disttask/framework/scheduler/scheduler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/pingcap/tidb/pkg/disttask/framework/storage"
3030
"github.com/pingcap/tidb/pkg/domain/infosync"
3131
"github.com/pingcap/tidb/pkg/kv"
32-
"github.com/pingcap/tidb/pkg/metrics"
3332
"github.com/pingcap/tidb/pkg/sessionctx"
3433
"github.com/pingcap/tidb/pkg/util/backoff"
3534
disttaskutil "github.com/pingcap/tidb/pkg/util/disttask"
@@ -170,6 +169,8 @@ func (s *BaseScheduler) scheduleTask() {
170169
if errors.Cause(err) == storage.ErrTaskNotFound {
171170
// this can happen when task is reverted/succeed, but before
172171
// we reach here, cleanup routine move it to history.
172+
s.logger.Debug("task not found, might be reverted/succeed/failed", zap.Int64("task_id", s.GetTask().ID),
173+
zap.String("task_key", s.GetTask().Key))
173174
return
174175
}
175176
s.logger.Error("refresh task failed", zap.Error(err))
@@ -399,7 +400,6 @@ func (s *BaseScheduler) onRunning() error {
399400

400401
func (s *BaseScheduler) onFinished() {
401402
task := s.GetTask()
402-
metrics.UpdateMetricsForFinishTask(task)
403403
s.logger.Debug("schedule task, task is finished", zap.Stringer("state", task.State))
404404
}
405405

pkg/disttask/framework/scheduler/scheduler_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ func (sm *Manager) startSchedulers(schedulableTasks []*proto.TaskBase) error {
285285
zap.Int64("task-id", task.ID), zap.Stringer("state", task.State))
286286
}
287287

288-
metrics.DistTaskGauge.WithLabelValues(task.Type.String(), metrics.SchedulingStatus).Inc()
289-
metrics.UpdateMetricsForScheduleTask(task.ID, task.Type)
288+
metrics.UpdateMetricsForScheduleTask(task)
290289
sm.startScheduler(task, allocateSlots, reservedExecID)
291290
}
292291
return nil
@@ -437,6 +436,7 @@ func (sm *Manager) cleanupFinishedTasks(tasks []*proto.Task) error {
437436
// if task doesn't register cleanup function, mark it as cleaned.
438437
cleanedTasks = append(cleanedTasks, task)
439438
}
439+
metrics.UpdateMetricsForFinishTask(task)
440440
}
441441
if firstErr != nil {
442442
sm.logger.Warn("cleanup routine failed", zap.Error(errors.Trace(firstErr)))

pkg/metrics/disttask.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ func UpdateMetricsForAddTask(task *proto.TaskBase) {
8080
}
8181

8282
// UpdateMetricsForScheduleTask update metrics when a task is added
83-
func UpdateMetricsForScheduleTask(id int64, taskType proto.TaskType) {
84-
DistTaskGauge.WithLabelValues(taskType.String(), WaitingStatus).Dec()
85-
DistTaskStartTimeGauge.DeleteLabelValues(taskType.String(), WaitingStatus, fmt.Sprint(id))
86-
DistTaskStartTimeGauge.WithLabelValues(taskType.String(), SchedulingStatus, fmt.Sprint(id)).SetToCurrentTime()
83+
func UpdateMetricsForScheduleTask(task *proto.TaskBase) {
84+
DistTaskGauge.WithLabelValues(task.Type.String(), WaitingStatus).Dec()
85+
DistTaskGauge.WithLabelValues(task.Type.String(), SchedulingStatus).Inc()
86+
DistTaskStartTimeGauge.DeleteLabelValues(task.Type.String(), WaitingStatus, fmt.Sprint(task.ID))
87+
DistTaskStartTimeGauge.WithLabelValues(task.Type.String(), SchedulingStatus, fmt.Sprint(task.ID)).SetToCurrentTime()
8788
}
8889

8990
// UpdateMetricsForRunTask update metrics when a task starts running

pkg/metrics/grafana/tidb.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16487,7 +16487,7 @@
1648716487
"targets": [
1648816488
{
1648916489
"exemplar": true,
16490-
"expr": "sum(tidb_disttask_subtasks{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", status=~\"pending|running|reverting|revert_pending|paused\"}) by (exec_id)",
16490+
"expr": "sum(tidb_disttask_subtasks{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", status=~\"pending|running|failed|canceled|paused\"}) by (exec_id)",
1649116491
"interval": "",
1649216492
"legendFormat": "",
1649316493
"queryType": "randomWalk",

0 commit comments

Comments
 (0)