feat(health): add health checking endpoints and logic
Introduce health checking functionality with liveness and readiness endpoints to monitor the application's status. Implement a health checker that verifies database connectivity and provides a simple liveness check. Update service routing to use the new health checker functionality. Add corresponding unit tests for validation.
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"gitlab.com/unboundsoftware/schemas/domain"
|
||||
"gitlab.com/unboundsoftware/schemas/graph"
|
||||
"gitlab.com/unboundsoftware/schemas/graph/generated"
|
||||
"gitlab.com/unboundsoftware/schemas/health"
|
||||
"gitlab.com/unboundsoftware/schemas/logging"
|
||||
"gitlab.com/unboundsoftware/schemas/middleware"
|
||||
"gitlab.com/unboundsoftware/schemas/monitoring"
|
||||
@@ -241,8 +242,12 @@ func start(closeEvents chan error, logger *slog.Logger, connectToAmqpFunc func(u
|
||||
Cache: lru.New[string](100),
|
||||
})
|
||||
|
||||
healthChecker := health.New(db.DB, logger)
|
||||
|
||||
mux.Handle("/", monitoring.Handler(playground.Handler("GraphQL playground", "/query")))
|
||||
mux.Handle("/health", http.HandlerFunc(healthFunc))
|
||||
mux.Handle("/health", http.HandlerFunc(healthChecker.LivenessHandler))
|
||||
mux.Handle("/health/live", http.HandlerFunc(healthChecker.LivenessHandler))
|
||||
mux.Handle("/health/ready", http.HandlerFunc(healthChecker.ReadinessHandler))
|
||||
mux.Handle("/query", cors.AllowAll().Handler(
|
||||
monitoring.Handler(
|
||||
mw.Middleware().CheckJWT(
|
||||
@@ -301,10 +306,6 @@ func loadSubGraphs(ctx context.Context, eventStore eventsourced.EventStore, serv
|
||||
return nil
|
||||
}
|
||||
|
||||
func healthFunc(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = w.Write([]byte("OK"))
|
||||
}
|
||||
|
||||
func ConnectAMQP(url string) (Connection, error) {
|
||||
return goamqp.NewFromURL(serviceName, url)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user