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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user