Expose Prometheus metrics endpoint for monitoring - #113
Closed
kael-developer[bot] wants to merge 1 commit into
Closed
Expose Prometheus metrics endpoint for monitoring#113kael-developer[bot] wants to merge 1 commit into
kael-developer[bot] wants to merge 1 commit into
Conversation
Implemented by Kael AI Agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Problem
The service does not expose any runtime metrics, making it impossible for operators to monitor request latency, error rates, or resource usage via Prometheus/Grafana.
Solution
Add a
/metricsendpoint that registers standard FastAPI‑Prometheus metrics (HTTP request count, duration, process CPU/memory). Integrate theprometheus_clientlibrary and ensure the endpoint is excluded from authentication and rate‑limiting.Value
Operators can set up alerts on latency spikes or error bursts, improving observability and reducing mean‑time‑to‑detect (MTTD) for incidents.
What changed
Files created:
/metricsendpoint with Prometheus metrics.Files modified:
prometheus_clientdependency.REQUEST_COUNTCounter and observeREQUEST_LATENCYHistogram for each request (excluding/metrics), and setinclude_in_schema=Falsefor the metrics endpoint.EXPOSE 8000line is present./metricsreturns status 200 and containsprocess_cpu_seconds_totalmetric.Logic implemented:
REQUEST_COUNTand HistogramREQUEST_LATENCYfor request monitoring./metricspath./metricsendpoint that returnsprometheus_client.generate_latest()with proper media type and is hidden from OpenAPI schema.Build verified:
pytest ./tests && curl -f http://localhost:8000/metrics→ exit code 0, all tests passed and metrics endpoint returned a non‑empty payload containingprocess_cpu_seconds_total.Acceptance criteria:
http_requests_totalandprocess_cpu_seconds_totalmetrics — verified by checking response content in test.http_requests_totalconfirms counting.Acceptance criteria
http_requests_totalandprocess_cpu_seconds_totalmetrics. 3. The endpoint is reachable without authentication headers. 4. Middleware correctly increments request counters for other endpoints (verified by test). 5.go vet ./...equivalent (flake8/pylint) passes with no new warnings.Closes #109
🤖 Implemented automatically by Kael AI Agent