P1: Expose Prometheus metrics at /metrics (#173)#191
Open
dkijania wants to merge 1 commit into
Open
Conversation
There was no metrics endpoint — only optional Jaeger tracing — so request rate,
errors, latency, and process health were invisible in production.
Add a prom-client registry served at `/metrics`:
- RED HTTP metrics via a Yoga plugin: `http_requests_total{method,route,status}`,
`http_request_duration_seconds` histogram, and `http_requests_in_flight`.
- Standard Node process metrics (CPU, memory, event loop, GC).
- Route labels are normalised to a known set (`other` otherwise) to bound
cardinality; the `/metrics` scrape is not self-counted.
DB pool-saturation gauges are intentionally out of scope here: postgres.js
exposes no pool-introspection API, so that needs a query-instrumentation pass —
tracked as a follow-up.
Unit tests cover the exposition format, per-route/status counting, and that the
scrape endpoint is excluded.
Refs #173.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSuak9smCHbp4N17xjjLF6
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.
What & why
Part of the production-readiness epic (#163). Refs #173.
There was no metrics endpoint — only optional Jaeger tracing — so request rate, errors, latency, and process health were invisible in production.
Changes
/metricsendpoint (prom-client) via a Yoga plugin.http_requests_total{method,route,status},http_request_duration_secondshistogram,http_requests_in_flightgauge./,/healthcheck,/readiness,/metrics; anything else →other) to bound label cardinality; the/metricsscrape is not self-counted.New dependency:
prom-client.On DB pool saturation
The issue also lists DB pool-saturation gauges.
postgres.jsexposes no pool-introspection API, so those need a query-instrumentation pass rather than a simple read of pool state. I scoped that out of this PR and left #173 open for it (this PR isRefs, notCloses) — happy to follow up with an instrumentation approach if you want it.Testing
npm run build— cleannpm run test:unit— all pass; tests cover the exposition format, per-route/status counting (asserts a request count of 2), and exclusion of the scrape endpointnpm run lint/npx prettier --debug-check .— clean🤖 Generated with Claude Code