Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions service/matching/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"slices"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -729,10 +730,13 @@ func (db *taskQueueDB) emitBacklogGaugesLocked() {
return
}

var approximateBacklogCount, totalLag int64
var totalLag int64
var oldestTime time.Time
count := make(map[int32]int64)
for _, s := range db.subqueues {
approximateBacklogCount += s.ApproximateBacklogCount
c := count[s.Key.Priority]
c += s.ApproximateBacklogCount
count[s.Key.Priority] = c
oldestTime = minNonZeroTime(oldestTime, s.oldestTime)
// note: this metric is only an estimation for the lag.
// taskID in DB may not be continuous, especially when task list ownership changes.
Expand All @@ -745,7 +749,13 @@ func (db *taskQueueDB) emitBacklogGaugesLocked() {
}
}

metrics.ApproximateBacklogCount.With(db.metricsHandler).Record(float64(approximateBacklogCount))
for _, v := range count {
priStr := ""
if v > 0 {
priStr = strconv.FormatInt(v, 10)
}
metrics.ApproximateBacklogCount.With(db.metricsHandler).Record(float64(v), metrics.StringTag(metrics.TaskPriorityTagName, priStr))
}
if oldestTime.IsZero() {
metrics.ApproximateBacklogAgeSeconds.With(db.metricsHandler).Record(0)
} else {
Expand Down
Loading