fix: coordinate SMS completion and improve operations diagnostics
CSS quality / css-quality (push) Has been cancelled

This commit is contained in:
hectorzhao
2026-09-16 18:27:29 +08:00
parent a0209f93bc
commit a350aca883
40 changed files with 2599 additions and 366 deletions
+26
View File
@@ -0,0 +1,26 @@
type CompletionMetric =
'claimed' | 'not_claimed' | 'recovered' | 'fence_rejected' | 'event_committed' | 'retry_wait' | 'needs_review';
const counts = new Map<CompletionMetric, number>();
let snapshot: Array<{ state: string; count: number; age: number }> = [];
const states = ['pending', 'processing', 'retry_wait', 'needs_review'];
export function countCompletion(event: CompletionMetric) {
counts.set(event, (counts.get(event) ?? 0) + 1);
}
export function observeCompletion(rows: typeof snapshot) {
snapshot = rows;
}
export function renderCompletionMetrics() {
return [
'# TYPE cmpp_completion_events_total counter',
...[...counts].map(([event, value]) => `cmpp_completion_events_total{event="${event}"} ${value}`),
'# TYPE cmpp_completion_work gauge',
'# TYPE cmpp_completion_oldest_seconds gauge',
...states.flatMap((state) => {
const row = snapshot.find((item) => item.state === state);
return [
`cmpp_completion_work{state="${state}"} ${Number(row?.count ?? 0)}`,
`cmpp_completion_oldest_seconds{state="${state}"} ${Math.max(0, Number(row?.age ?? 0))}`,
];
}),
];
}