Add prometheus-fastapi-instrumentator for HTTP metrics #167
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/pal-e-api#167
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lineage
plan-pal-e-platform→ Phase 4 (Dashboard) — prerequisite for golden signals dashboardRepo
forgejo_admin/pal-e-docsUser Story
As a platform operator
I want real HTTP request metrics from pal-e-docs
So that the golden signals dashboard can display latency, traffic, errors, and saturation
Context
The current
/metricsendpoint inroutes/health.pyis a stub that returns onlypal_e_docs_up 1. We need real HTTP request instrumentation to power the Grafana dashboard being created in pal-e-platform.prometheus-fastapi-instrumentatoris a well-maintained library that automatically instruments FastAPI apps with:http_request_duration_secondshistogram (method, status, handler labels)http_requests_totalcounterhttp_response_size_byteshistogramThe app already has
prometheus-client>=0.20as a dependency. The instrumentator builds on top of it.File Targets
Files to modify:
src/pal_e_docs/main.py— add instrumentator initialization and middlewaresrc/pal_e_docs/routes/health.py— replace stub/metricsendpoint with prometheus clientgenerate_latest()outputpyproject.toml— addprometheus-fastapi-instrumentatordependencyFiles NOT to touch:
health.pyAcceptance Criteria
/metricsreturns Prometheus text format withhttp_request_duration_secondshistogram/metricsreturnshttp_requests_totalcounter with method/status/handler labels/metricsstill includespal_e_docs_up 1custom gauge/healthzstill returns{"status": "ok"}/healthzand/metricsfrom instrumentation (avoid recursion)Test Expectations
pytest tests/ -vcurl localhost:8000/metricsreturns Prometheus format with HTTP histogramscd ~/pal-e-docs && source .venv/bin/activate && pytest tests/ -vConstraints
prometheus-fastapi-instrumentator(not manual prometheus_client instrumentation) — it's the standard approach for FastAPIpal_e_docs_upgauge as a custom metric alongside the auto-instrumented ones/metricsendpoint must returntext/plaincontent type (Prometheus scrape format)Checklist
Related
plan-pal-e-platform— dashboard depends on these metricsproject-page-pal-e-docs— project page