make dial timeout configurable
MODIFY
go/src/github.com/xing/beetle/beetle.go
go/src/github.com/xing/beetle/beetle.go
@@ -37,6 +37,7 @@ var opts struct {
GcThreshold int `long:"redis-gc-threshold" description:"Number of seconds to wait until considering an expired redis key eligible for garbage collection. Defaults to 3600 (1 hour)."`
GcDatabases string `long:"redis-gc-databases" description:"Database numbers to collect keys from (e.g. 0,4). Defaults to 4."`
MailTo string `long:"mail-to" description:"Send notifcation mails to this address."`
+ DialTimeout int `long:"dial-timeout" description:"Number of seconds to wait until a connection attempt to the master times out. Defaults to 5."`
}
var Verbose bool
@@ -79,6 +80,7 @@ func (x *CmdRunMailer) Execute(args []string) error {
Server: initialConfig.Server,
Port: initialConfig.Port,
Recipient: initialConfig.MailTo,
+ DialTimeout: initialConfig.DialTimeout,
})
}
@@ -202,6 +204,7 @@ func getProgramParameters() *Config {
GcThreshold: opts.GcThreshold,
GcDatabases: opts.GcDatabases,
MailTo: opts.MailTo,
+ DialTimeout: opts.DialTimeout,
}
}

MODIFY
go/src/github.com/xing/beetle/client.go
go/src/github.com/xing/beetle/client.go
@@ -54,7 +54,7 @@ func (s *ClientState) ServerUrl() string {
func (s *ClientState) Connect() (err error) {
url := s.ServerUrl()
- websocket.DefaultDialer.HandshakeTimeout = 5 * time.Second
+ websocket.DefaultDialer.HandshakeTimeout = time.Duration(s.GetConfig().DialTimeout) * time.Second
logInfo("connecting to %s, timeout: %s", url, websocket.DefaultDialer.HandshakeTimeout)
s.ws, _, err = websocket.DefaultDialer.Dial(url, nil)
if err != nil {

MODIFY
go/src/github.com/xing/beetle/config.go
go/src/github.com/xing/beetle/config.go
@@ -21,6 +21,7 @@ type Config struct {
GcThreshold int `yaml:"redis_gc_threshold"`
GcDatabases string `yaml:"redis_gc_databases"`
MailTo string `yaml:"mail_to"`
+ DialTimeout int `yaml:"dial_timeout"`
}
func (c *Config) Clone() *Config {
@@ -77,6 +78,9 @@ func (c *Config) SetDefaults() *Config {
if c.RedisMasterFile == "" {
c.RedisMasterFile = "/etc/beetle/redis-master"
}
+ if c.DialTimeout == 0 {
+ c.DialTimeout = 5
+ }
c.Sanitize()
return c
}
@@ -121,6 +125,9 @@ func (c *Config) Merge(d *Config) *Config {
if c.MailTo == "" {
c.MailTo = d.MailTo
}
+ if c.DialTimeout == 0 {
+ c.DialTimeout = d.DialTimeout
+ }
c.Sanitize()
return c
}
@@ -178,6 +185,11 @@ func configFromConsulEnv(env consul.Env) *Config {
if v, ok := env["BEETLE_REDIS_SERVER"]; ok {
c.RedisMasterFile = v
}
+ if v, ok := env["BEETLE_DIAL_TIMEOUT"]; ok {
+ if d, err := strconv.Atoi(v); err == nil {
+ c.DialTimeout = d
+ }
+ }
c.Sanitize()
return &c
}

MODIFY
go/src/github.com/xing/beetle/notification_mailer.go
go/src/github.com/xing/beetle/notification_mailer.go
@@ -14,6 +14,7 @@ type MailerOptions struct {
Server string
Port int
Recipient string
+ DialTimeout int
}
type MailerState struct {
@@ -26,7 +27,7 @@ type MailerState struct {
func (s *MailerState) Connect() (err error) {
logInfo("connecting to %s", s.url)
- websocket.DefaultDialer.HandshakeTimeout = 5 * time.Second
+ websocket.DefaultDialer.HandshakeTimeout = time.Duration(s.opts.DialTimeout) * time.Second
s.ws, _, err = websocket.DefaultDialer.Dial(s.url, nil)
if err != nil {
return

make dial timeout configurable