Skip to content

feat: prometheus histogram for deduct latency - #1

Closed
iexwr wants to merge 1 commit into
mainfrom
task/deduct-latency-hist
Closed

feat: prometheus histogram for deduct latency#1
iexwr wants to merge 1 commit into
mainfrom
task/deduct-latency-hist

Conversation

@iexwr

@iexwr iexwr commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a dedicated Prometheus histogram for end-to-end latency tracking of POST /api/billing/deduct.

Changes

  • src/metrics/registry.ts — New file registering billing_deduct_duration_seconds histogram with explicit buckets from 1ms to 10s and route + status_code labels
  • src/middleware/metricsHistogram.ts — New per-route middleware that measures request latency using performance.now() and records to the histogram on response finish
  • src/routes/billing.ts — Wired billingDeductHistogramMiddleware into the /deduct route handler
  • docs/grafana-dashboard-billing-deduct.json — New Grafana dashboard with P50/P95/P99 latency percentiles and cumulative distribution panels
  • src/tests/billingDeductMetrics.test.ts — 21 unit tests covering histogram registration, bucket boundaries, label correctness, middleware behavior, error status codes, reset, and dashboard consistency

Acceptance Criteria

  • Histogram exported (billing_deduct_duration_seconds)
  • Buckets cover 1ms..10s (12 explicit buckets)
  • Route label present (/api/billing/deduct)
  • Dashboard JSON updated
  • Tests pass (21 new tests, all 79 metrics tests passing)
  • Lint clean (0 errors)

Test Output

PASS src/__tests__/billingDeductMetrics.test.ts
Tests:       21 passed, 21 total

PASS src/__tests__/metricsLatency.test.ts
Tests:       43 passed, 43 total

PASS src/__tests__/upstreamProfiling.test.ts
Tests:       15 passed, 15 total

Add dedicated Prometheus histogram billing_deduct_duration_seconds for
POST /api/billing/deduct with explicit buckets from 1ms to 10s, route
label, and per-status-code observability.

- src/metrics/registry.ts — histogram registration and record function
- src/middleware/metricsHistogram.ts — per-route middleware that
  measures end-to-end latency and records to the histogram
- src/routes/billing.ts — wire middleware into the /deduct handler
- docs/grafana-dashboard-billing-deduct.json — Grafana dashboard with
  P50/P95/P99 panels and cumulative distribution view
- src/__tests__/billingDeductMetrics.test.ts — 21 tests covering
  histogram registration, buckets, labels, middleware, and reset
@iexwr iexwr closed this Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants