@@ -31,6 +31,7 @@ import (
3131)
3232
3333type healthChecker struct {
34+ component string
3435 enableRepair bool
3536 healthCheckFunc func () bool
3637 // The repair is "best-effort" and ignores the error from the underlying actions.
@@ -45,6 +46,7 @@ type healthChecker struct {
4546// NewHealthChecker returns a new health checker configured with the given options.
4647func NewHealthChecker (hco * options.HealthCheckerOptions ) (types.HealthChecker , error ) {
4748 hc := & healthChecker {
49+ component : hco .Component ,
4850 enableRepair : hco .EnableRepair ,
4951 crictlPath : hco .CriCtlPath ,
5052 healthCheckTimeout : hco .HealthCheckTimeout ,
@@ -139,14 +141,14 @@ func (hc *healthChecker) CheckHealth() bool {
139141 // The service is unhealthy.
140142 // Attempt repair based on flag.
141143 if hc .enableRepair {
142- glog .Infof ("health-checker: component is unhealthy, proceeding to repair" )
143144 // repair if the service has been up for the cool down period.
144145 uptime , err := hc .uptimeFunc ()
145146 if err != nil {
146- glog .Infof ("health-checker : %v\n " , err . Error () )
147+ glog .Infof ("error in getting uptime for %v : %v\n " , hc . component , err )
147148 }
148- glog .Infof ("health-checker: component uptime: %v\n " , uptime )
149+ glog .Infof ("%v is unhealthy, component uptime: %v\n " , hc . component , uptime )
149150 if uptime > hc .coolDownTime {
151+ glog .Infof ("%v cooldown period of %v exceeded, repairing" , hc .component , hc .coolDownTime )
150152 hc .repairFunc ()
151153 }
152154 }
@@ -159,10 +161,9 @@ func execCommand(timeout time.Duration, command string, args ...string) (string,
159161 defer cancel ()
160162
161163 cmd := exec .CommandContext (ctx , command , args ... )
162- glog .Infof ("health-checker: executing command : %v\n " , cmd )
163164 out , err := cmd .Output ()
164165 if err != nil {
165- glog .Infof ("health-checker: command failed : %v, %v\n " , err . Error () , out )
166+ glog .Infof ("command %v failed : %v, %v\n " , cmd , err , out )
166167 return "" , err
167168 }
168169 return strings .TrimSuffix (string (out ), "\n " ), nil
0 commit comments