Improve request logging and make health check lightweight

- Log slow requests (>1s) at WARNING level with slow=true flag
- Log request timeouts at WARNING level in TimeoutMiddleware
- Replace heavy GetStatsContext with lightweight Ping in health check
- Add Ping method to database interface (SELECT 1)
This commit is contained in:
2026-01-01 06:06:20 -08:00
parent 8f524485f7
commit a163449a28
6 changed files with 37 additions and 6 deletions

View File

@@ -1997,3 +1997,14 @@ func (d *Database) Checkpoint(ctx context.Context) error {
return nil
}
// Ping checks if the database connection is alive with a lightweight query.
func (d *Database) Ping(ctx context.Context) error {
var result int
err := d.db.QueryRowContext(ctx, "SELECT 1").Scan(&result)
if err != nil {
return fmt.Errorf("database ping failed: %w", err)
}
return nil
}

View File

@@ -88,6 +88,7 @@ type Store interface {
Vacuum(ctx context.Context) error
Analyze(ctx context.Context) error
Checkpoint(ctx context.Context) error
Ping(ctx context.Context) error
}
// Ensure Database implements Store