Private
Public Access
1
0

health: fix noisy logs
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
2024-12-28 00:52:11 -08:00
parent 35ea262b99
commit dc8adc1aea

View File

@@ -284,9 +284,12 @@ func healthHandler(srv *Server, log *slog.Logger) func(w http.ResponseWriter, re
g, ctx := errgroup.WithContext(ctx)
stats := srv.db.Stats()
if stats.OpenConnections > 5 {
log.InfoContext(ctx, "health requests", "url", req.URL.String(), "stats", stats)
}
reset, err := strconv.ParseBool(req.URL.Query().Get("reset"))
if resetParam := req.URL.Query().Get("reset"); resetParam != "" {
reset, err := strconv.ParseBool(resetParam)
log.InfoContext(ctx, "db reset request", "err", err, "reset", reset)
if err == nil && reset {
@@ -294,6 +297,7 @@ func healthHandler(srv *Server, log *slog.Logger) func(w http.ResponseWriter, re
srv.db.SetMaxIdleConns(0)
srv.db.SetConnMaxLifetime(5 * time.Second)
}
}
g.Go(func() error {
err := srv.ch.Scores.Ping(ctx)
@@ -313,7 +317,7 @@ func healthHandler(srv *Server, log *slog.Logger) func(w http.ResponseWriter, re
return nil
})
err = g.Wait()
err := g.Wait()
if err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
_, err = w.Write([]byte("db ping err"))