mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
Use seen more conservatively
This commit is contained in:
@@ -704,10 +704,8 @@ func (a *Agent) setupConsul(consulConfig *config.ConsulConfig) error {
|
||||
}
|
||||
|
||||
// Determine version for TLSSkipVerify
|
||||
seen := false
|
||||
if self, err := client.Agent().Self(); err == nil {
|
||||
a.consulSupportsTLSSkipVerify = consulSupportsTLSSkipVerify(self)
|
||||
seen = true
|
||||
}
|
||||
|
||||
// Create Consul Catalog client for service discovery.
|
||||
@@ -716,12 +714,6 @@ func (a *Agent) setupConsul(consulConfig *config.ConsulConfig) error {
|
||||
// Create Consul Service client for service advertisement and checks.
|
||||
a.consulService = consul.NewServiceClient(client.Agent(), a.consulSupportsTLSSkipVerify, a.logger)
|
||||
|
||||
// If we've seen the Consul agent already, mark it so future Consul
|
||||
// errors are logged
|
||||
if seen {
|
||||
a.consulService.MarkSeen()
|
||||
}
|
||||
|
||||
// Run the Consul service client's sync'ing main loop
|
||||
go a.consulService.Run()
|
||||
return nil
|
||||
|
||||
@@ -147,15 +147,15 @@ func NewServiceClient(consulClient AgentAPI, skipVerifySupport bool, logger *log
|
||||
// seen is used by MarkSeen and Seen
|
||||
const seen = 1
|
||||
|
||||
// MarkSeen marks Consul as having been seen (meaning at least one operation
|
||||
// markSeen marks Consul as having been seen (meaning at least one operation
|
||||
// has succeeded).
|
||||
func (c *ServiceClient) MarkSeen() {
|
||||
func (c *ServiceClient) markSeen() {
|
||||
atomic.StoreInt64(&c.seen, seen)
|
||||
}
|
||||
|
||||
// Seen returns true if any Consul operation has ever succeeded. Useful to
|
||||
// hasSeen returns true if any Consul operation has ever succeeded. Useful to
|
||||
// squelch errors if Consul isn't running.
|
||||
func (c *ServiceClient) Seen() bool {
|
||||
func (c *ServiceClient) hasSeen() bool {
|
||||
return atomic.LoadInt64(&c.seen) == seen
|
||||
}
|
||||
|
||||
@@ -175,11 +175,8 @@ func (c *ServiceClient) Run() {
|
||||
}
|
||||
|
||||
if err := c.sync(); err != nil {
|
||||
// Only log and track failures after Consul has been seen
|
||||
if c.Seen() {
|
||||
if failures == 0 {
|
||||
c.logger.Printf("[WARN] consul.sync: failed to update services in Consul: %v", err)
|
||||
}
|
||||
if failures == 0 {
|
||||
c.logger.Printf("[WARN] consul.sync: failed to update services in Consul: %v", err)
|
||||
}
|
||||
failures++
|
||||
if !retryTimer.Stop() {
|
||||
@@ -264,9 +261,6 @@ func (c *ServiceClient) sync() error {
|
||||
return fmt.Errorf("error querying Consul services: %v", err)
|
||||
}
|
||||
|
||||
// A Consul operation has succeeded, mark Consul as having been seen
|
||||
c.MarkSeen()
|
||||
|
||||
consulChecks, err := c.client.Checks()
|
||||
if err != nil {
|
||||
metrics.IncrCounter([]string{"client", "consul", "sync_failure"}, 1)
|
||||
@@ -362,6 +356,9 @@ func (c *ServiceClient) sync() error {
|
||||
}
|
||||
}
|
||||
|
||||
// A Consul operation has succeeded, mark Consul as having been seen
|
||||
c.markSeen()
|
||||
|
||||
c.logger.Printf("[DEBUG] consul.sync: registered %d services, %d checks; deregistered %d services, %d checks",
|
||||
sreg, creg, sdereg, cdereg)
|
||||
return nil
|
||||
@@ -692,8 +689,8 @@ func (c *ServiceClient) Shutdown() error {
|
||||
// Don't wait forever though
|
||||
}
|
||||
|
||||
// If Consul was never seen, exit early
|
||||
if !c.Seen() {
|
||||
// If Consul was never seen nothing could be written so exit early
|
||||
if !c.hasSeen() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user