feat: implement observability and metrics (Task 22)
- Add metrics package tracking cache hit-rate, API quota, circuit breaker trips, search time - Integrate metrics with cache layer, yandex client, and API handlers - Add /metrics HTTP endpoint for Prometheus-compatible metrics exposure - Write tests for metrics functionality across cache, yandex, and API handlers - Update test files to support new metrics infrastructure
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
|
||||
"trip-planner/internal/cache"
|
||||
"trip-planner/internal/metrics"
|
||||
"trip-planner/internal/routing"
|
||||
"trip-planner/internal/yandex"
|
||||
)
|
||||
@@ -15,9 +16,10 @@ import (
|
||||
func main() {
|
||||
redisClient := initRedis()
|
||||
router := routing.NewGraph()
|
||||
yandexClient := yandex.NewClient("default-key")
|
||||
m := metrics.New()
|
||||
yandexClient := yandex.NewClient("default-key", yandex.WithMetrics(m))
|
||||
|
||||
handlerCtx := NewHandlerContext(redisClient, router, yandexClient)
|
||||
handlerCtx := NewHandlerContext(redisClient, router, yandexClient, m)
|
||||
|
||||
// Cache warm-up: load city directory into Redis cache
|
||||
// ensures the API functions correctly on cold start and after cache expiry
|
||||
@@ -29,6 +31,7 @@ func main() {
|
||||
http.HandleFunc("/v1/routes/", makeHandler(RouteGeoJSON, handlerCtx))
|
||||
http.HandleFunc("/v1/stations/", makeHandler(StationStatus, handlerCtx))
|
||||
http.HandleFunc("/internal/admin/stations/", makeHandler(AdminStationStatus, handlerCtx))
|
||||
http.HandleFunc("/metrics", makeHandler(MetricsHandler, handlerCtx))
|
||||
|
||||
log.Println("Trip Planner API starting on :8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
|
||||
Reference in New Issue
Block a user