fix: MetricsCollectorService does not track APPROVED or retry-pending batches
This commit is contained in:
@@ -39,7 +39,8 @@ public class MetricsCollectorService : BackgroundService
|
||||
BatchStatus.Verified,
|
||||
BatchStatus.AwaitingClinicalApproval,
|
||||
BatchStatus.Approved,
|
||||
BatchStatus.Promoted
|
||||
BatchStatus.Promoted,
|
||||
BatchStatus.Cancelled
|
||||
};
|
||||
|
||||
public MetricsCollectorService(
|
||||
@@ -121,11 +122,41 @@ public class MetricsCollectorService : BackgroundService
|
||||
DiagnosticsMetrics.QueueAgeSeconds.Set(0);
|
||||
}
|
||||
|
||||
// --- Promotion retry gauges ---
|
||||
var pendingRetries = await db.PromotionAttempts
|
||||
.AsNoTracking()
|
||||
.CountAsync(a => !a.Succeeded && a.NextRetryAt != null, ct);
|
||||
DiagnosticsMetrics.PromotionPendingRetries.Set(pendingRetries);
|
||||
|
||||
var exhaustedCount = await db.DigitizationBatches
|
||||
.AsNoTracking()
|
||||
.Where(b => b.Status == BatchStatus.Approved)
|
||||
.Where(b => db.PromotionAttempts
|
||||
.Any(a => a.BatchId == b.Id && !a.Succeeded && a.NextRetryAt == null))
|
||||
.CountAsync(ct);
|
||||
DiagnosticsMetrics.PromotionExhaustedTotal.Set(exhaustedCount);
|
||||
|
||||
// --- Approval queue age: oldest APPROVED batch ---
|
||||
var oldestApprovedUpdatedAt = await db.DigitizationBatches
|
||||
.AsNoTracking()
|
||||
.Where(b => b.Status == BatchStatus.Approved)
|
||||
.OrderBy(b => b.UpdatedAt)
|
||||
.Select(b => (DateTimeOffset?)b.UpdatedAt)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
|
||||
DiagnosticsMetrics.ApprovalQueueAgeSeconds.Set(
|
||||
oldestApprovedUpdatedAt.HasValue
|
||||
? (DateTimeOffset.UtcNow - oldestApprovedUpdatedAt.Value).TotalSeconds
|
||||
: 0);
|
||||
|
||||
_logger.LogDebug(
|
||||
"Metrics collected: {StatusCount} status groups, queue age {QueueAge}s",
|
||||
"Metrics collected: {StatusCount} status groups, queue age {QueueAge}s, " +
|
||||
"pending retries {PendingRetries}, exhausted {Exhausted}",
|
||||
statusCounts.Count,
|
||||
oldestPendingUpdatedAt.HasValue
|
||||
? (DateTimeOffset.UtcNow - oldestPendingUpdatedAt.Value).TotalSeconds
|
||||
: 0);
|
||||
: 0,
|
||||
pendingRetries,
|
||||
exhaustedCount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user