From 7ee98af31c25af331451a16e861177cde9da4d0f Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Wed, 21 Mar 2018 10:19:07 -0400 Subject: [PATCH] set driver to unhealthy once if it cannot be detected in periodic check --- client/fingerprint_manager.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/client/fingerprint_manager.go b/client/fingerprint_manager.go index d8b94cac022a..b9d863d33636 100644 --- a/client/fingerprint_manager.go +++ b/client/fingerprint_manager.go @@ -1,6 +1,7 @@ package client import ( + "fmt" "log" "strings" "sync" @@ -173,11 +174,16 @@ func (fm *FingerprintManager) setupDrivers(drivers []string) error { return err } - // For all drivers without health checking enabled , create a driver - // info which matches its fingerprint status. Later, for drivers that - // have the health check interface implemented, a periodic health check - // will be run - if _, isHealthCheck := d.(fingerprint.HealthCheck); !isHealthCheck { + // Perform a health check for the driver if it implements the health check + // interface and if the driver is detected + if hc, isHealthCheck := d.(fingerprint.HealthCheck); isHealthCheck && detected { + err := fm.runDriverHealthCheck(name, hc) + if err != nil { + fm.logger.Printf("[DEBUG] client.fingerprint_manager: health checking for %v failed: %v", name, err) + } + } else { + // For all drivers without health checking enabled , create a driver + // info which matches its fingerprint status. healthInfo := &structs.DriverInfo{ Healthy: detected, UpdateTime: time.Now(), @@ -308,6 +314,21 @@ func (fm *FingerprintManager) watchDriver(d driver.Driver, name string) { if err := fm.runDriverHealthCheck(name, hc); err != nil { fm.logger.Printf("[DEBUG] client.fingerprint_manager: health checking for %v failed: %v", name, err) } + } else { + // If the driver is undetected, change the health status to unhealthy + // only once. + if driver.Healthy { + healthInfo := &structs.DriverInfo{ + Healthy: detected, + HealthDescription: fmt.Sprintf("Driver %s is not detected", name), + UpdateTime: time.Now(), + } + if node := fm.updateNodeFromDriver(name, nil, healthInfo); node != nil { + fm.nodeLock.Lock() + fm.node = node + fm.nodeLock.Unlock() + } + } } } }