Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(server): log health check errors #190

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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