Skip to content

Commit

Permalink
log health check errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-bourque committed Aug 7, 2024
1 parent 70d0aac commit 29105b4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func handleUX() http.Handler {

// handleHealthz exposes an HTTP health check endpoint that responds with '200 OK' if the service is
// healthy (can connect to the Perseus database) and '500 Internal Server Error' if not
func handleHealthz(db store.Store, timeout time.Duration) http.Handler {
func handleHealthz(db store.Store, timeout time.Duration, log Logger) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), timeout)
defer cancel()
if err := db.Ping(ctx); err != nil {
log.Error(err, "Failing health check due to ping timeout", "timeout", timeout.String())
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "a connection to the database is unavailable")
return
}
w.WriteHeader(http.StatusOK)
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func runServer(opts ...serverOption) error {
mux := http.NewServeMux()
mux.Handle("/", vt)
mux.Handle("/ui/", handleUX())
mux.Handle("/healthz", handleHealthz(db, conf.healthzTimeout))
mux.Handle("/healthz", handleHealthz(db, conf.healthzTimeout, log))
mux.Handle("/metrics", promhttp.Handler())
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
Expand Down

0 comments on commit 29105b4

Please sign in to comment.