diff --git a/client/client.go b/client/client.go index 744bad87691..2d466a7841b 100644 --- a/client/client.go +++ b/client/client.go @@ -443,11 +443,35 @@ func (c *Client) fingerprint() error { if applies { applied = append(applied, name) } + p, period := f.Periodic() + if p { + // TODO: If more periodic fingerprinters are added, then + // fingerprintPeriodic should be used to handle all the periodic + // fingerprinters by using a priority queue. + go c.fingerprintPeriodic(name, f, period) + } } c.logger.Printf("[DEBUG] client: applied fingerprints %v", applied) return nil } +// fingerprintPeriodic runs a fingerprinter at the specified duration. If the +// fingerprinter returns an error, the function exits. +func (c *Client) fingerprintPeriodic(name string, f fingerprint.Fingerprint, d time.Duration) { + c.logger.Printf("[DEBUG] client: periodically fingerprinting %v at duration %v", name, d) + for { + select { + case <-time.After(d): + if _, err := f.Fingerprint(c.config, c.config.Node); err != nil { + c.logger.Printf("[DEBUG] client: disabling periodic fingerprinting for %v: %v", name, err) + return + } + case <-c.shutdownCh: + return + } + } +} + // setupDrivers is used to find the available drivers func (c *Client) setupDrivers() error { var avail []string diff --git a/client/fingerprint/consul.go b/client/fingerprint/consul.go index 01e3a658b60..9ae81faf6a0 100644 --- a/client/fingerprint/consul.go +++ b/client/fingerprint/consul.go @@ -65,5 +65,5 @@ func (f *ConsulFingerprint) Fingerprint(config *client.Config, node *structs.Nod } func (f *ConsulFingerprint) Periodic() (bool, time.Duration) { - return false, 15 * time.Second + return true, 15 * time.Second }