Alerting: Limit redis pool size to 5 and make configurable (#74057)
* Limit redis pool size to 5 and expose it in config ini * Coerce negative pool sizes to the default
This commit is contained in:
@@ -93,6 +93,7 @@ func (moa *MultiOrgAlertmanager) setupClustering(cfg *setting.Cfg) error {
|
||||
password: cfg.UnifiedAlerting.HARedisPassword,
|
||||
username: cfg.UnifiedAlerting.HARedisUsername,
|
||||
db: cfg.UnifiedAlerting.HARedisDB,
|
||||
maxConns: cfg.UnifiedAlerting.HARedisMaxConns,
|
||||
}, clusterLogger, moa.metrics.Registerer, cfg.UnifiedAlerting.HAPushPullInterval)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to initialize redis: %w", err)
|
||||
|
||||
@@ -27,6 +27,7 @@ type redisConfig struct {
|
||||
db int
|
||||
name string
|
||||
prefix string
|
||||
maxConns int
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -44,6 +45,7 @@ const (
|
||||
reasonRedisIssue = "redis_issue"
|
||||
heartbeatInterval = time.Second * 5
|
||||
heartbeatTimeout = time.Minute
|
||||
defaultPoolSize = 5
|
||||
// The duration we want to return the members if the network is down.
|
||||
membersValidFor = time.Minute
|
||||
)
|
||||
@@ -84,11 +86,17 @@ func newRedisPeer(cfg redisConfig, logger log.Logger, reg prometheus.Registerer,
|
||||
if cfg.name != "" {
|
||||
name = cfg.name
|
||||
}
|
||||
// Allow zero through, since it'll fall back to go-redis's default.
|
||||
poolSize := defaultPoolSize
|
||||
if cfg.maxConns >= 0 {
|
||||
poolSize = cfg.maxConns
|
||||
}
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: cfg.addr,
|
||||
Username: cfg.username,
|
||||
Password: cfg.password,
|
||||
DB: cfg.db,
|
||||
PoolSize: poolSize,
|
||||
})
|
||||
cmd := rdb.Ping(context.Background())
|
||||
if cmd.Err() != nil {
|
||||
|
||||
Reference in New Issue
Block a user