Standardize driver health description messages for all drivers

This commit is contained in:
Preetha Appan 2019-01-06 22:04:15 -06:00
parent f5b71ee5c9
commit 2fb2de3cef
No known key found for this signature in database
GPG Key ID: 9F7C19990A50EAFC
10 changed files with 24 additions and 18 deletions

View File

@ -34,14 +34,14 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
fp := &drivers.Fingerprint{ fp := &drivers.Fingerprint{
Attributes: map[string]*pstructs.Attribute{}, Attributes: map[string]*pstructs.Attribute{},
Health: drivers.HealthStateHealthy, Health: drivers.HealthStateHealthy,
HealthDescription: "healthy", HealthDescription: drivers.DriverHealthy,
} }
client, _, err := d.dockerClients() client, _, err := d.dockerClients()
if err != nil { if err != nil {
d.logger.Info("failed to initialize client", "error", err) d.logger.Info("failed to initialize client", "error", err)
return &drivers.Fingerprint{ return &drivers.Fingerprint{
Health: drivers.HealthStateUndetected, Health: drivers.HealthStateUndetected,
HealthDescription: "failed to initialize docker client", HealthDescription: "Failed to initialize docker client",
} }
} }
@ -50,7 +50,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
d.logger.Debug("could not connect to docker daemon", "endpoint", client.Endpoint(), "error", err) d.logger.Debug("could not connect to docker daemon", "endpoint", client.Endpoint(), "error", err)
return &drivers.Fingerprint{ return &drivers.Fingerprint{
Health: drivers.HealthStateUnhealthy, Health: drivers.HealthStateUnhealthy,
HealthDescription: "failed to connect to docker daemon", HealthDescription: "Failed to connect to docker daemon",
} }
} }

View File

@ -189,7 +189,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
fp := &drivers.Fingerprint{ fp := &drivers.Fingerprint{
Attributes: map[string]*pstructs.Attribute{}, Attributes: map[string]*pstructs.Attribute{},
Health: drivers.HealthStateHealthy, Health: drivers.HealthStateHealthy,
HealthDescription: "healthy", HealthDescription: drivers.DriverHealthy,
} }
if !utils.IsUnixRoot() { if !utils.IsUnixRoot() {
@ -201,14 +201,14 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
mount, err := fingerprint.FindCgroupMountpointDir() mount, err := fingerprint.FindCgroupMountpointDir()
if err != nil { if err != nil {
fp.Health = drivers.HealthStateUnhealthy fp.Health = drivers.HealthStateUnhealthy
fp.HealthDescription = "failed to discover cgroup mount point" fp.HealthDescription = drivers.NoCgroupMountMessage
d.logger.Warn(fp.HealthDescription, "error", err) d.logger.Warn(fp.HealthDescription, "error", err)
return fp return fp
} }
if mount == "" { if mount == "" {
fp.Health = drivers.HealthStateUnhealthy fp.Health = drivers.HealthStateUnhealthy
fp.HealthDescription = "requires cgroup" fp.HealthDescription = drivers.CgroupMountEmpty
return fp return fp
} }

View File

@ -196,7 +196,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
fp := &drivers.Fingerprint{ fp := &drivers.Fingerprint{
Attributes: map[string]*pstructs.Attribute{}, Attributes: map[string]*pstructs.Attribute{},
Health: drivers.HealthStateHealthy, Health: drivers.HealthStateHealthy,
HealthDescription: "healthy", HealthDescription: drivers.DriverHealthy,
} }
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
@ -210,14 +210,14 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
mount, err := fingerprint.FindCgroupMountpointDir() mount, err := fingerprint.FindCgroupMountpointDir()
if err != nil { if err != nil {
fp.Health = drivers.HealthStateUnhealthy fp.Health = drivers.HealthStateUnhealthy
fp.HealthDescription = "failed to discover cgroup mount point" fp.HealthDescription = drivers.NoCgroupMountMessage
d.logger.Warn(fp.HealthDescription, "error", err) d.logger.Warn(fp.HealthDescription, "error", err)
return fp return fp
} }
if mount == "" { if mount == "" {
fp.Health = drivers.HealthStateUnhealthy fp.Health = drivers.HealthStateUnhealthy
fp.HealthDescription = "cgroups are unavailable" fp.HealthDescription = drivers.CgroupMountEmpty
return fp return fp
} }
} }

View File

@ -279,7 +279,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
} else { } else {
health = drivers.HealthStateHealthy health = drivers.HealthStateHealthy
attrs["driver.mock"] = pstructs.NewBoolAttribute(true) attrs["driver.mock"] = pstructs.NewBoolAttribute(true)
desc = "ready" desc = drivers.DriverHealthy
} }
return &drivers.Fingerprint{ return &drivers.Fingerprint{

View File

@ -207,7 +207,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
fingerprint := &drivers.Fingerprint{ fingerprint := &drivers.Fingerprint{
Attributes: map[string]*pstructs.Attribute{}, Attributes: map[string]*pstructs.Attribute{},
Health: drivers.HealthStateHealthy, Health: drivers.HealthStateHealthy,
HealthDescription: "ready", HealthDescription: drivers.DriverHealthy,
} }
bin := "qemu-system-x86_64" bin := "qemu-system-x86_64"
@ -229,7 +229,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
matches := versionRegex.FindStringSubmatch(out) matches := versionRegex.FindStringSubmatch(out)
if len(matches) != 2 { if len(matches) != 2 {
fingerprint.Health = drivers.HealthStateUndetected fingerprint.Health = drivers.HealthStateUndetected
fingerprint.HealthDescription = fmt.Sprintf("failed to parse qemu version from %v", out) fingerprint.HealthDescription = fmt.Sprintf("Failed to parse qemu version from %v", out)
return fingerprint return fingerprint
} }
currentQemuVersion := matches[1] currentQemuVersion := matches[1]

View File

@ -230,7 +230,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
attrs := map[string]*pstructs.Attribute{} attrs := map[string]*pstructs.Attribute{}
if d.config.Enabled { if d.config.Enabled {
health = drivers.HealthStateHealthy health = drivers.HealthStateHealthy
desc = "ready" desc = drivers.DriverHealthy
attrs["driver.raw_exec"] = pstructs.NewBoolAttribute(true) attrs["driver.raw_exec"] = pstructs.NewBoolAttribute(true)
} else { } else {
health = drivers.HealthStateUndetected health = drivers.HealthStateUndetected

View File

@ -121,7 +121,7 @@ func TestRawExecDriver_Fingerprint(t *testing.T) {
Expected: drivers.Fingerprint{ Expected: drivers.Fingerprint{
Attributes: map[string]*pstructs.Attribute{"driver.raw_exec": pstructs.NewBoolAttribute(true)}, Attributes: map[string]*pstructs.Attribute{"driver.raw_exec": pstructs.NewBoolAttribute(true)},
Health: drivers.HealthStateHealthy, Health: drivers.HealthStateHealthy,
HealthDescription: "ready", HealthDescription: drivers.DriverHealthy,
}, },
}, },
} }

View File

@ -265,7 +265,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
fingerprint := &drivers.Fingerprint{ fingerprint := &drivers.Fingerprint{
Attributes: map[string]*pstructs.Attribute{}, Attributes: map[string]*pstructs.Attribute{},
Health: drivers.HealthStateHealthy, Health: drivers.HealthStateHealthy,
HealthDescription: "ready", HealthDescription: drivers.DriverHealthy,
} }
// Only enable if we are root // Only enable if we are root
@ -278,7 +278,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
outBytes, err := exec.Command(rktCmd, "version").Output() outBytes, err := exec.Command(rktCmd, "version").Output()
if err != nil { if err != nil {
fingerprint.Health = drivers.HealthStateUndetected fingerprint.Health = drivers.HealthStateUndetected
fingerprint.HealthDescription = fmt.Sprintf("failed to executor %s version: %v", rktCmd, err) fingerprint.HealthDescription = fmt.Sprintf("Failed to execute %s version: %v", rktCmd, err)
return fingerprint return fingerprint
} }
out := strings.TrimSpace(string(outBytes)) out := strings.TrimSpace(string(outBytes))
@ -287,7 +287,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
appcMatches := reAppcVersion.FindStringSubmatch(out) appcMatches := reAppcVersion.FindStringSubmatch(out)
if len(rktMatches) != 2 || len(appcMatches) != 2 { if len(rktMatches) != 2 || len(appcMatches) != 2 {
fingerprint.Health = drivers.HealthStateUndetected fingerprint.Health = drivers.HealthStateUndetected
fingerprint.HealthDescription = "unable to parse rkt version string" fingerprint.HealthDescription = "Unable to parse rkt version string"
return fingerprint return fingerprint
} }
@ -296,7 +296,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
if currentVersion.LessThan(minVersion) { if currentVersion.LessThan(minVersion) {
// Do not allow ancient rkt versions // Do not allow ancient rkt versions
fingerprint.Health = drivers.HealthStateUndetected fingerprint.Health = drivers.HealthStateUndetected
fingerprint.HealthDescription = fmt.Sprintf("unsuported rkt version %s", currentVersion) fingerprint.HealthDescription = fmt.Sprintf("Unsuported rkt version %s", currentVersion)
return fingerprint return fingerprint
} }

View File

@ -18,6 +18,8 @@ import (
"github.com/zclconf/go-cty/cty/msgpack" "github.com/zclconf/go-cty/cty/msgpack"
) )
const DriverHealthy = "Healthy"
// DriverPlugin is the interface with drivers will implement. It is also // DriverPlugin is the interface with drivers will implement. It is also
// implemented by a plugin client which proxies the calls to go-plugin. See // implemented by a plugin client which proxies the calls to go-plugin. See
// the proto/driver.proto file for detailed information about each RPC and // the proto/driver.proto file for detailed information about each RPC and

View File

@ -5,3 +5,7 @@ import "fmt"
var ErrTaskNotFound = fmt.Errorf("task not found for given id") var ErrTaskNotFound = fmt.Errorf("task not found for given id")
var DriverRequiresRootMessage = "Driver must run as root" var DriverRequiresRootMessage = "Driver must run as root"
var NoCgroupMountMessage = "Failed to discover cgroup mount point"
var CgroupMountEmpty = "Cgroup mount point unavailable"