@@ -31,6 +31,7 @@ import (
31
31
)
32
32
33
33
type healthChecker struct {
34
+ component string
34
35
enableRepair bool
35
36
healthCheckFunc func () bool
36
37
// The repair is "best-effort" and ignores the error from the underlying actions.
@@ -45,6 +46,7 @@ type healthChecker struct {
45
46
// NewHealthChecker returns a new health checker configured with the given options.
46
47
func NewHealthChecker (hco * options.HealthCheckerOptions ) (types.HealthChecker , error ) {
47
48
hc := & healthChecker {
49
+ component : hco .Component ,
48
50
enableRepair : hco .EnableRepair ,
49
51
crictlPath : hco .CriCtlPath ,
50
52
healthCheckTimeout : hco .HealthCheckTimeout ,
@@ -139,14 +141,14 @@ func (hc *healthChecker) CheckHealth() bool {
139
141
// The service is unhealthy.
140
142
// Attempt repair based on flag.
141
143
if hc .enableRepair {
142
- glog .Infof ("health-checker: component is unhealthy, proceeding to repair" )
143
144
// repair if the service has been up for the cool down period.
144
145
uptime , err := hc .uptimeFunc ()
145
146
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 )
147
148
}
148
- glog .Infof ("health-checker: component uptime: %v\n " , uptime )
149
+ glog .Infof ("%v is unhealthy, component uptime: %v\n " , hc . component , uptime )
149
150
if uptime > hc .coolDownTime {
151
+ glog .Infof ("%v cooldown period of %v exceeded, repairing" , hc .component , hc .coolDownTime )
150
152
hc .repairFunc ()
151
153
}
152
154
}
@@ -159,10 +161,9 @@ func execCommand(timeout time.Duration, command string, args ...string) (string,
159
161
defer cancel ()
160
162
161
163
cmd := exec .CommandContext (ctx , command , args ... )
162
- glog .Infof ("health-checker: executing command : %v\n " , cmd )
163
164
out , err := cmd .Output ()
164
165
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 )
166
167
return "" , err
167
168
}
168
169
return strings .TrimSuffix (string (out ), "\n " ), nil
0 commit comments