Feat/stats prom#74
Conversation
Go coverage report (utils) |
Go coverage report (webserver) |
Go coverage report (api) |
|
Addressed. Changes made:
Regression coverage:
Validation:
|
There was a problem hiding this comment.
Pull request overview
This PR migrates the API stats/metrics pipeline from StatsD-style counters to Prometheus, adding a dedicated /metrics HTTP server and tightening how increment keys are normalized/bucketed to control label cardinality.
Changes:
- Add Prometheus counters for stats hits and increment events, and expose them via a new metrics server (
/metrics) on a configurable listen address. - Update stats recording to increment a hits counter per accepted payload and bucket/allowlist increment keys (with a fallback
otherbucket). - Update docker dev compose and tests to cover the new metrics behavior and configuration.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| docker4dev/docker-compose.yaml | Exposes the Prometheus metrics port and sets AFN_METRICS_LISTEN_ADDR. |
| api/internal/stats/service.go | Changes metrics interface + normalizes/buckets increment keys; always increments “hits”. |
| api/internal/stats/service_test.go | Updates tests for new metrics interface and key bucketing behavior. |
| api/internal/stats/prometheus.go | Adds Prometheus-backed Metrics implementation and counters. |
| api/internal/app/run.go | Runs two HTTP servers (API + Prometheus /metrics) concurrently. |
| api/internal/app/run_test.go | Adds unit tests for URL logging helper used by the servers. |
| api/internal/app/config.go (+ config_test.go) | Adds MetricsListenAddr config/env with default and tests. |
| api/go.mod + api/go.sum | Adds Prometheus deps and updates module metadata (but currently inconsistent). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| require ( | ||
| github.com/julsemaan/anyfile-notepad/utils v0.0.0-20230202010526-481b7f9b59a2 | ||
| github.com/julsemaan/rest-layer-file v0.0.0-20230518012330-1c28ed9eb6a7 | ||
| github.com/patrickmn/go-cache v2.1.0+incompatible | ||
| github.com/prometheus/client_golang v1.23.2 | ||
| github.com/rs/rest-layer v0.0.0-20160505213648-cb84bc79b5b8 |
There was a problem hiding this comment.
Removed the unused github.com/julsemaan/anyfile-notepad/utils requirement from api/go.mod. I also re-ran cd api && go test ./... and confirmed the api module graph no longer includes that dependency.
| for { | ||
| err := <-errCh | ||
| if errors.Is(err, http.ErrServerClosed) { | ||
| continue | ||
| } | ||
|
|
||
| return err | ||
| } |
There was a problem hiding this comment.
Verified this is already addressed in the current branch. Run no longer waits on the old error loop: metrics now run in a goroutine via serveMetrics, and serveAPI returns directly while treating http.ErrServerClosed as a clean shutdown.
No description provided.