diff --git a/discovery/kv/kv.go b/discovery/kv/kv.go index ef420d37f8..cd5f6506cf 100644 --- a/discovery/kv/kv.go +++ b/discovery/kv/kv.go @@ -62,6 +62,7 @@ func (s *Discovery) Initialize(uris string, heartbeat time.Duration, ttl time.Du EphemeralTTL: s.ttl, }, ) + return err } diff --git a/pkg/store/consul.go b/pkg/store/consul.go index d0e8e4f729..e055a03e70 100644 --- a/pkg/store/consul.go +++ b/pkg/store/consul.go @@ -16,6 +16,10 @@ const ( // watched key has changed. This affects the minimum time it takes to // cancel a watch. DefaultWatchWaitTime = 15 * time.Second + + // MinimumTimeToLive is the minimum TTL value allowed by Consul for + // Ephemeral entries + MinimumTimeToLive = 10 * time.Second ) // Consul embeds the client and watches @@ -52,7 +56,9 @@ func InitializeConsul(endpoints []string, options *Config) (Store, error) { s.setTimeout(options.ConnectionTimeout) } if options.EphemeralTTL != 0 { - s.setEphemeralTTL(options.EphemeralTTL) + if err := s.setEphemeralTTL(options.EphemeralTTL); err != nil { + return nil, err + } } } @@ -81,8 +87,12 @@ func (s *Consul) setTimeout(time time.Duration) { } // SetEphemeralTTL sets the ttl for ephemeral nodes -func (s *Consul) setEphemeralTTL(time time.Duration) { - s.ephemeralTTL = time +func (s *Consul) setEphemeralTTL(ttl time.Duration) error { + if ttl < MinimumTimeToLive { + return ErrInvalidTTL + } + s.ephemeralTTL = ttl + return nil } // CreateEphemeralSession creates the a global session diff --git a/pkg/store/store.go b/pkg/store/store.go index 0fc390a232..a372a3dc95 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -23,6 +23,8 @@ const ( ) var ( + // ErrInvalidTTL is a specific error to consul + ErrInvalidTTL = errors.New("Invalid TTL, please change the value to the miminum allowed ttl for the chosen store") // ErrNotSupported is exported ErrNotSupported = errors.New("Backend storage not supported yet, please choose another one") // ErrNotImplemented is exported