feat(system): add runtime task queue observability dashboard for system admins
Expose live asynq queue depths and worker-pool concurrency via a new SystemAdmin API and settings UI, so operators can monitor parsing/wiki backlog without Redis CLI access.
This commit is contained in:
@@ -875,6 +875,12 @@ func RegisterSystemAdminRoutes(
|
||||
adminRoutes.PUT("/settings/:key", handler.UpdateSystemSetting)
|
||||
adminRoutes.DELETE("/settings/:key", handler.ResetSystemSetting)
|
||||
|
||||
// Runtime observability: live asynq queue depths + worker pool
|
||||
// concurrency for the parse/wiki pools. Read-only snapshot for the
|
||||
// SystemAdmin runtime dashboard. Returns available=false in Lite
|
||||
// mode (no Redis) so the UI degrades gracefully.
|
||||
adminRoutes.GET("/runtime/queues", handler.GetRuntimeQueues)
|
||||
|
||||
// Bulk action — write the current default-quota setting onto
|
||||
// every existing tenant. Lives under /tenants instead of
|
||||
// /settings because it changes tenants, not the setting row.
|
||||
|
||||
@@ -182,7 +182,6 @@ func NewParseAsynqServer(svc interfaces.SystemSettingService) *asynq.Server {
|
||||
log.Printf("asynq parse-pool server starting with concurrency=%d redis_op_timeout=%dms",
|
||||
concurrency, readRedisOpTimeoutMs())
|
||||
return newAsynqServer(concurrency, map[string]int{
|
||||
types.QueueCritical: 6, // Highest priority queue
|
||||
types.QueueDefault: 3, // Default priority queue
|
||||
types.QueueLow: 1, // Lowest priority queue
|
||||
types.QueueMultimodal: 1, // Isolated lane for high-volume slow VLM image tasks
|
||||
|
||||
@@ -18,8 +18,8 @@ func NewAsynqInspector() *asynq.Inspector {
|
||||
}
|
||||
|
||||
// asynqTaskInspector implements interfaces.TaskInspector backed by an
|
||||
// *asynq.Inspector. Scans the queues we actually use ("default",
|
||||
// "critical", "low") and matches tasks whose payload carries the given
|
||||
// *asynq.Inspector. Scans the queues we actually use and matches tasks
|
||||
// whose payload carries the given
|
||||
// knowledge_id. Best-effort: any scan/delete error is logged and
|
||||
// swallowed so the cancel API still returns success even when Redis is
|
||||
// flaky.
|
||||
@@ -52,7 +52,6 @@ type knowledgeIDProbe struct {
|
||||
// its (potentially hundreds of) pending image:multimodal tasks.
|
||||
var queuesScanned = []string{
|
||||
types.QueueDefault,
|
||||
types.QueueCritical,
|
||||
types.QueueLow,
|
||||
types.QueueMultimodal,
|
||||
types.QueueGraph,
|
||||
@@ -60,6 +59,22 @@ var queuesScanned = []string{
|
||||
types.QueueWiki,
|
||||
}
|
||||
|
||||
// queueMeta records each queue's worker pool and scheduling weight for
|
||||
// the runtime dashboard. Weights MUST stay in sync with the maps in
|
||||
// NewParseAsynqServer / NewWikiAsynqServer (task.go) — this is display
|
||||
// metadata only, the servers remain the source of truth for scheduling.
|
||||
var queueMeta = map[string]struct {
|
||||
pool string
|
||||
weight int
|
||||
}{
|
||||
types.QueueDefault: {pool: "parse", weight: 3},
|
||||
types.QueueLow: {pool: "parse", weight: 1},
|
||||
types.QueueMultimodal: {pool: "parse", weight: 1},
|
||||
types.QueueGraph: {pool: "parse", weight: 1},
|
||||
types.QueueQuestion: {pool: "parse", weight: 1},
|
||||
types.QueueWiki: {pool: "wiki", weight: 1},
|
||||
}
|
||||
|
||||
// taskTypesForKnowledgeCancel lists every asynq task type that carries
|
||||
// a knowledge_id in its payload and should be cancelable. The set is
|
||||
// deliberately narrow: we don't touch FAQ import / KB-level tasks
|
||||
@@ -137,6 +152,53 @@ func (a *asynqTaskInspector) HasQueuedTasksForKnowledge(
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// QueueStats returns a depth snapshot for every queue this app enqueues
|
||||
// into. Read-only: it calls Inspector.GetQueueInfo per queue and maps
|
||||
// the result onto types.QueueStat, attaching static pool/weight metadata
|
||||
// from queueMeta. A queue that has never received a task yields
|
||||
// ErrQueueNotFound from asynq; we still surface it as a zeroed row so the
|
||||
// dashboard shows the complete lane set even before a queue receives its
|
||||
// first task.
|
||||
func (a *asynqTaskInspector) QueueStats(
|
||||
ctx context.Context,
|
||||
) ([]types.QueueStat, bool, error) {
|
||||
if a == nil || a.inspector == nil {
|
||||
return nil, false, nil
|
||||
}
|
||||
stats := make([]types.QueueStat, 0, len(queuesScanned))
|
||||
for _, queue := range queuesScanned {
|
||||
meta := queueMeta[queue]
|
||||
stat := types.QueueStat{
|
||||
Name: queue,
|
||||
Pool: meta.pool,
|
||||
Weight: meta.weight,
|
||||
}
|
||||
info, err := a.inspector.GetQueueInfo(queue)
|
||||
if err != nil {
|
||||
if !errors.Is(err, asynq.ErrQueueNotFound) {
|
||||
logger.Warnf(ctx, "[TaskInspector] queue info queue=%s: %v", queue, err)
|
||||
}
|
||||
// Zeroed row: queue not created yet (or transient error).
|
||||
stats = append(stats, stat)
|
||||
continue
|
||||
}
|
||||
stat.Size = info.Size
|
||||
stat.Pending = info.Pending
|
||||
stat.Active = info.Active
|
||||
stat.Scheduled = info.Scheduled
|
||||
stat.Retry = info.Retry
|
||||
stat.Archived = info.Archived
|
||||
stat.Completed = info.Completed
|
||||
stat.Processed = info.Processed
|
||||
stat.Failed = info.Failed
|
||||
stat.Paused = info.Paused
|
||||
stat.LatencyMs = info.Latency.Milliseconds()
|
||||
stat.MemoryUsageBytes = info.MemoryUsage
|
||||
stats = append(stats, stat)
|
||||
}
|
||||
return stats, true, nil
|
||||
}
|
||||
|
||||
// queueStateHasMatch pages through one (queue, state) list looking for a
|
||||
// task that references knowledgeID. Mirrors the delete* scanners but is
|
||||
// strictly read-only and returns early on the first hit. A backend error
|
||||
@@ -335,3 +397,12 @@ func (noopTaskInspector) HasQueuedTasksForKnowledge(
|
||||
) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// QueueStats reports "not supported" in Lite mode: there is no Redis /
|
||||
// asynq backend to inspect, so the runtime dashboard renders an
|
||||
// "unavailable in this deployment" state instead of an empty table.
|
||||
func (noopTaskInspector) QueueStats(
|
||||
ctx context.Context,
|
||||
) ([]types.QueueStat, bool, error) {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user