API observability -- Prometheus instrumentation + business metrics #24

Closed
opened 2026-03-24 20:08:28 +00:00 by forgejo_admin · 0 comments
Contributor

Type

Feature

Lineage

Standalone -- mcd-tracker observability buildout

Repo

forgejo_admin/mcd-tracker-api

User Story

As a platform operator
I want real Prometheus metrics from mcd-tracker-api
So that I can monitor API health and business activity

Context

Replace the stub /metrics endpoint (hardcoded up 1) with real Prometheus instrumentation. Copy the pal-e-docs pattern exactly. Existing ServiceMonitor already scrapes /metrics on port 8000 every 30s -- no deployment changes needed.

File Targets

Files to modify:

  • requirements.txt or pyproject.toml -- add prometheus-fastapi-instrumentator
  • src/main.py (or equivalent) -- wire instrumentator
  • src/routes/health.py -- remove manual /metrics stub
  • Route handlers -- add custom business counters

Acceptance Criteria

  • prometheus-fastapi-instrumentator wired into app
  • /metrics returns real Prometheus metrics (request rate, latency histograms, error rates)
  • Custom business counters: mcd_receipts_uploaded_total, mcd_codes_saved_total, mcd_codes_redeemed_total, mcd_nearby_queries_total
  • Existing ServiceMonitor scrapes successfully

Test Expectations

  • Unit test: /metrics endpoint returns valid Prometheus format
  • Integration test: custom counters increment on relevant operations
  • Run command: pytest tests/

Constraints

  • Follow pal-e-docs pattern: Instrumentator(should_ignore_untemplated=True, excluded_handlers=["/healthz", "/metrics"]).instrument(app)
  • Do not change the ServiceMonitor configuration

Checklist

  • PR opened
  • Tests pass
  • No unrelated changes
  • mcd-tracker -- parent project
### Type Feature ### Lineage Standalone -- mcd-tracker observability buildout ### Repo `forgejo_admin/mcd-tracker-api` ### User Story As a platform operator I want real Prometheus metrics from mcd-tracker-api So that I can monitor API health and business activity ### Context Replace the stub `/metrics` endpoint (hardcoded `up 1`) with real Prometheus instrumentation. Copy the pal-e-docs pattern exactly. Existing ServiceMonitor already scrapes `/metrics` on port 8000 every 30s -- no deployment changes needed. ### File Targets Files to modify: - `requirements.txt` or `pyproject.toml` -- add `prometheus-fastapi-instrumentator` - `src/main.py` (or equivalent) -- wire instrumentator - `src/routes/health.py` -- remove manual `/metrics` stub - Route handlers -- add custom business counters ### Acceptance Criteria - [ ] `prometheus-fastapi-instrumentator` wired into app - [ ] `/metrics` returns real Prometheus metrics (request rate, latency histograms, error rates) - [ ] Custom business counters: `mcd_receipts_uploaded_total`, `mcd_codes_saved_total`, `mcd_codes_redeemed_total`, `mcd_nearby_queries_total` - [ ] Existing ServiceMonitor scrapes successfully ### Test Expectations - [ ] Unit test: `/metrics` endpoint returns valid Prometheus format - [ ] Integration test: custom counters increment on relevant operations - Run command: `pytest tests/` ### Constraints - Follow pal-e-docs pattern: `Instrumentator(should_ignore_untemplated=True, excluded_handlers=["/healthz", "/metrics"]).instrument(app)` - Do not change the ServiceMonitor configuration ### Checklist - [ ] PR opened - [ ] Tests pass - [ ] No unrelated changes ### Related - `mcd-tracker` -- parent project
Commenting is not possible because the repository is archived.
No labels
No milestone
No project
No assignees
1 participant
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
ldraney/mcd-tracker-api#24
No description provided.