Log all recovered reconnects to backends

... to give the admin the all-clear.

refs #351
This commit is contained in:
Alexander A. Klimov 2021-09-22 16:17:25 +02:00
parent f554fa9dfe
commit b4bfee92d9
2 changed files with 12 additions and 0 deletions

View file

@ -66,6 +66,12 @@ func dialWithLogging(logger *zap.SugaredLogger) func(context.Context, string, st
logger.Warnw("Can't connect to Redis. Retrying", zap.Error(err))
}
},
OnSuccess: func(elapsed time.Duration, attempt uint64, _ error) {
if attempt > 0 {
logger.Infow("Reconnected to Redis",
zap.Duration("after", elapsed), zap.Uint64("attempts", attempt+1))
}
},
},
)

View file

@ -39,6 +39,12 @@ func (c RetryConnector) Connect(ctx context.Context) (driver.Conn, error) {
c.driver.Logger.Warnw("Can't connect to database. Retrying", zap.Error(err))
}
},
OnSuccess: func(elapsed time.Duration, attempt uint64, _ error) {
if attempt > 0 {
c.driver.Logger.Infow("Reconnected to database",
zap.Duration("after", elapsed), zap.Uint64("attempts", attempt+1))
}
},
},
), "can't connect to database")
return conn, err