Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry backoffs to database config #1068

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type RedisConfig struct {
WriteTimeout string `yaml:"write_timeout"`
// MaxRetries count of retries.
MaxRetries int `yaml:"max_retries"`
// Minimum backoff between retries. Used to calculate exponential backoff. Default value is 0
MinRetryBackoff string `yaml:"min_retry_backoff"`
// Maximum backoff between retries. Used to calculate exponential backoff. Default value is 0
MaxRetryBackoff string `yaml:"max_retry_backoff"`
// Enables read-only commands on slave nodes.
ReadOnly bool `yaml:"read_only"`
// Allows routing read-only commands to the **closest** master or slave node.
Expand All @@ -68,6 +72,8 @@ func (config *RedisConfig) GetSettings() redis.DatabaseConfig {
SentinelUsername: config.SentinelUsername,
SentinelPassword: config.SentinelPassword,
MaxRetries: config.MaxRetries,
MinRetryBackoff: to.Duration(config.MinRetryBackoff),
MaxRetryBackoff: to.Duration(config.MaxRetryBackoff),
MetricsTTL: to.Duration(config.MetricsTTL),
DialTimeout: to.Duration(config.DialTimeout),
ReadTimeout: to.Duration(config.ReadTimeout),
Expand Down
29 changes: 18 additions & 11 deletions database/redis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ import "time"

// DatabaseConfig - Redis database connection config.
type DatabaseConfig struct {
Addrs []string

Username string
Password string

MasterName string
Addrs []string
Username string
Password string
SentinelPassword string
SentinelUsername string
MetricsTTL time.Duration
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
MaxRetries int
ReadOnly bool
RouteByLatency bool
RouteRandomly bool

MetricsTTL time.Duration
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration

MaxRetries int
MinRetryBackoff time.Duration
MaxRetryBackoff time.Duration

ReadOnly bool
RouteByLatency bool
RouteRandomly bool
}

type NotificationHistoryConfig struct {
Expand Down
27 changes: 17 additions & 10 deletions database/redis/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,26 @@ type DbConnector struct {

func NewDatabase(logger moira.Logger, config DatabaseConfig, nh NotificationHistoryConfig, n NotificationConfig, source DBSource) *DbConnector {
client := redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: config.Addrs,

MasterName: config.MasterName,
Addrs: config.Addrs,
Username: config.Username,
Password: config.Password,
SentinelPassword: config.SentinelPassword,
SentinelUsername: config.SentinelUsername,
DialTimeout: config.DialTimeout,
ReadTimeout: config.ReadTimeout,
WriteTimeout: config.WriteTimeout,
MaxRetries: config.MaxRetries,
ReadOnly: config.ReadOnly,
RouteByLatency: config.RouteByLatency,
RouteRandomly: config.RouteRandomly,

Username: config.Username,
Password: config.Password,

DialTimeout: config.DialTimeout,
ReadTimeout: config.ReadTimeout,
WriteTimeout: config.WriteTimeout,

MaxRetries: config.MaxRetries,
MinRetryBackoff: config.MinRetryBackoff,
MaxRetryBackoff: config.MaxRetryBackoff,

ReadOnly: config.ReadOnly,
RouteByLatency: config.RouteByLatency,
RouteRandomly: config.RouteRandomly,
})

ctx := context.Background()
Expand Down
2 changes: 2 additions & 0 deletions local/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
redis:
addrs: "redis:6379"
metrics_ttl: 3h
min_retry_backoff: 1s
max_retry_backoff: 10s
telemetry:
graphite:
enabled: true
Expand Down
Loading