Skip to content

Commit

Permalink
set driver to unhealthy once if it cannot be detected in periodic check
Browse files Browse the repository at this point in the history
  • Loading branch information
chelseakomlo committed Mar 21, 2018
1 parent 179db0d commit 7ee98af
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions client/fingerprint_manager.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"fmt"
"log"
"strings"
"sync"
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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()
}
}
}
}
}
Expand Down

0 comments on commit 7ee98af

Please sign in to comment.