diff --git a/service/matching/db.go b/service/matching/db.go index 937798ebbdd..cfeebc001b8 100644 --- a/service/matching/db.go +++ b/service/matching/db.go @@ -5,6 +5,7 @@ import ( "fmt" "math" "slices" + "strconv" "sync" "time" @@ -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. @@ -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 {