feat(metrics): worker job-run counters and business gauges (#60) #165

Merged
amiryahaya merged 2 commits from feat/worker-metrics-60 into main 2026-11-05 17:46:09 +01:00
Owner

Step 2a of #60 (docs/05-observability.md): the worker's /metrics now carries job-run counters and business gauges.

What

  • jobs.Config.Observe reports every run (ok, failed, permanent) -> kws_job_runs_total{kind,outcome}, kws_job_duration_seconds{kind}.
  • Business gauges from metrics/pgstore, read at most once per 30 s on a scrape (no goroutine), all on the uuidv7 primary-key range: kws_sales_last_hour, kws_payments_last_day, kws_sales_pending, kws_sales_processing, kws_sales_oldest_processing_age_seconds, kws_payments_refund_due.
  • A failed read keeps the last good values, counts kws_business_snapshot_errors_total, and kws_business_snapshot_timestamp_seconds lets an alert catch stale data. No error text is exported.
  • Appended to the existing queue gauges (ContinueOnError, uncompressed).

Review

Pass 1 (ponytail) and Pass 2 (correctness subagent) done. Pass 2 fixes: the uuidv7 bound floors the millisecond (was rounded), a failed first read is not retried every scrape, the last-good timestamp gauge. Each has a test that failed first.

Coverage

make cover: total 91.4% (minimum 80%). make lint: 0 issues.

Rulings / notes (ADR 0036)

  • The worker's HTTP port now shows sales counts: private network only. [verify] in #57.
  • Several workers export the same numbers: aggregate with max.
  • Lazy per-scrape read, not the timer of docs/05 4.2 (no goroutine to stop).
  • Deferred: kws_job_attempts_exhausted_total, kws_sales_pending_overdue (a dead sales.expire makes kws_sales_pending fall), refund_due is a seq scan (partial index past ~1M rows).

🤖 Generated with Claude Code

Step 2a of #60 (docs/05-observability.md): the worker's `/metrics` now carries job-run counters and business gauges. ## What - `jobs.Config.Observe` reports every run (`ok`, `failed`, `permanent`) -> `kws_job_runs_total{kind,outcome}`, `kws_job_duration_seconds{kind}`. - Business gauges from `metrics/pgstore`, read at most once per 30 s on a scrape (no goroutine), all on the uuidv7 primary-key range: `kws_sales_last_hour`, `kws_payments_last_day`, `kws_sales_pending`, `kws_sales_processing`, `kws_sales_oldest_processing_age_seconds`, `kws_payments_refund_due`. - A failed read keeps the last good values, counts `kws_business_snapshot_errors_total`, and `kws_business_snapshot_timestamp_seconds` lets an alert catch stale data. No error text is exported. - Appended to the existing queue gauges (`ContinueOnError`, uncompressed). ## Review Pass 1 (ponytail) and Pass 2 (correctness subagent) done. Pass 2 fixes: the uuidv7 bound floors the millisecond (was rounded), a failed first read is not retried every scrape, the last-good timestamp gauge. Each has a test that failed first. ## Coverage `make cover`: total 91.4% (minimum 80%). `make lint`: 0 issues. ## Rulings / notes (ADR 0036) - The worker's HTTP port now shows sales counts: private network only. **[verify]** in #57. - Several workers export the same numbers: aggregate with `max`. - Lazy per-scrape read, not the timer of docs/05 4.2 (no goroutine to stop). - Deferred: `kws_job_attempts_exhausted_total`, `kws_sales_pending_overdue` (a dead `sales.expire` makes `kws_sales_pending` fall), `refund_due` is a seq scan (partial index past ~1M rows). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(metrics): floor the uuidv7 bound, honour the ttl on a failed first read, export last-good timestamp (#60)
All checks were successful
ci / changes (pull_request) Successful in 33s
ci / clients (pull_request) Has been skipped
ci / web-ticket (pull_request) Has been skipped
ci / web-admin (pull_request) Has been skipped
ci / web-partner (pull_request) Has been skipped
ci / api (pull_request) Successful in 20m29s
ci / ci-gate (pull_request) Successful in 3s
16a970045e
Pass 2 review: the millisecond was rounded, not floored; a database down at start was retried on every scrape; stale gauges had no age signal. ContinueOnError keeps a bad collector from blanking the queue gauges.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!165
No description provided.