fix(task): Use existing scheduler metrics (#15765)

pull/15767/head
Lyon Hill 2019-11-05 10:36:45 -07:00 committed by GitHub
parent 3804d50fbd
commit d4494273e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -1,6 +1,8 @@
package scheduler
import (
"time"
"github.com/prometheus/client_golang/prometheus"
)
@ -103,6 +105,18 @@ func (em *SchedulerMetrics) release(taskID ID) {
em.releaseCalls.Inc()
}
func (em *SchedulerMetrics) reportScheduleDelay(d time.Duration) {
em.scheduleDelay.Observe(d.Seconds())
}
func (em *SchedulerMetrics) reportExecution(err error, d time.Duration) {
em.totalExecuteCalls.Inc()
em.executeDelta.Observe(d.Seconds())
if err != nil {
em.totalExecuteFailure.Inc()
}
}
func newExecutingTasks(ts *TreeScheduler) *executingTasks {
return &executingTasks{
desc: prometheus.NewDesc(

View File

@ -314,7 +314,14 @@ func (s *TreeScheduler) work(ctx context.Context, ch chan Item) {
err = &ErrUnrecoverable{errors.New("executor panicked")}
}
}()
return s.executor.Execute(ctx, it.id, t)
// report the difference between when the item was supposed to be scheduled and now
s.sm.reportScheduleDelay(time.Since(it.Next()))
preExec := time.Now()
// execute
err = s.executor.Execute(ctx, it.id, t)
// report how long execution took
s.sm.reportExecution(err, time.Since(preExec))
return err
}()
if err != nil {
s.onErr(ctx, it.id, it.Next(), err)