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,15 +284,19 @@ func healthHandler(srv *Server, log *slog.Logger) func(w http.ResponseWriter, re
g, ctx := errgroup.WithContext(ctx) g, ctx := errgroup.WithContext(ctx)
stats := srv.db.Stats() stats := srv.db.Stats()
log.InfoContext(ctx, "health requests", "url", req.URL.String(), "stats", 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 != "" {
log.InfoContext(ctx, "db reset request", "err", err, "reset", reset) reset, err := strconv.ParseBool(resetParam)
log.InfoContext(ctx, "db reset request", "err", err, "reset", reset)
if err == nil && reset { if err == nil && reset {
log.InfoContext(ctx, "setting idle db conns to zero") log.InfoContext(ctx, "setting idle db conns to zero")
srv.db.SetMaxIdleConns(0) srv.db.SetMaxIdleConns(0)
srv.db.SetConnMaxLifetime(5 * time.Second) srv.db.SetConnMaxLifetime(5 * time.Second)
}
} }
g.Go(func() error { g.Go(func() error {
@@ -313,7 +317,7 @@ func healthHandler(srv *Server, log *slog.Logger) func(w http.ResponseWriter, re
return nil return nil
}) })
err = g.Wait() err := g.Wait()
if err != nil { if err != nil {
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
_, err = w.Write([]byte("db ping err")) _, err = w.Write([]byte("db ping err"))