fix: coordinate SMS completion and improve operations diagnostics
CSS quality / css-quality (push) Has been cancelled
CSS quality / css-quality (push) Has been cancelled
This commit is contained in:
@@ -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))}`,
|
||||
];
|
||||
}),
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user