feat: add bounded business state observability

This commit is contained in:
2026-09-18 20:44:41 +08:00
parent bea8efa790
commit 5284206731
18 changed files with 450 additions and 12 deletions

View File

@@ -192,6 +192,25 @@ func run() error {
case <-ticker.C:
metrics.RecordDatabase(db.Stats())
metrics.RecordProcess()
started := time.Now()
call, cancel := context.WithTimeout(metricsCtx, 900*time.Millisecond)
snapshot, err := mysql.ReadOperationalSnapshot(call, db)
cancel()
metrics.RecordBusinessSnapshot(observability.BusinessSnapshot{
TaskStates: snapshot.TaskStates, TaskOldestAgeSeconds: snapshot.TaskOldestAgeSeconds,
DeliveryStates: snapshot.DeliveryStates, DeliveryOldestAgeSeconds: snapshot.DeliveryOldestAgeSeconds,
WorkflowStates: snapshot.WorkflowStates, WorkflowOldestAgeSeconds: snapshot.WorkflowOldestAgeSeconds,
Truncated: snapshot.Truncated,
}, started, err)
if err != nil && metricsCtx.Err() == nil {
reason := "query_error"
if errors.Is(err, context.DeadlineExceeded) {
reason = "timeout"
} else if errors.Is(err, context.Canceled) {
reason = "cancelled"
}
slog.Error("business metrics snapshot failed", "node_id", node, "reason", reason)
}
}
}
}()