Skip to content

Commit

Permalink
logging: Ensure errors are logged correctly.
Browse files Browse the repository at this point in the history
Ensure all errors are logged using the `logrus.WithError()` API.
The current `logrus.Error(err)` calls will result in log messages
containing the following fields:

```
level=error msg="..."
```

Whereas using `logrus.WithError()` will result in the expected:

```
level=error error="..."
```

Fixes kata-containers#26.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information
jodh-intel committed Mar 22, 2018
1 parent e8b099e commit 9594e17
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ksm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"sync"
"syscall"
"time"

"github.com/sirupsen/logrus"
)

type ksmSetting struct {
Expand Down Expand Up @@ -270,7 +272,7 @@ func (k *ksm) throttle() {
defer k.Unlock()

if !k.initialized {
throttlerLog.Error(errors.New("KSM is unavailable"))
throttlerLog.WithError(errors.New("KSM is unavailable")).Error()
return
}

Expand All @@ -286,8 +288,9 @@ func (k *ksm) throttle() {
// We got kicked, this means a new VM has been created.
// We will enter the aggressive setting until we throttle down.
_ = throttleTimer.Stop()
if err := k.tune(ksmSettings[ksmAggressive]); err != nil {
throttlerLog.Error(err)
mode := ksmAggressive
if err := k.tune(ksmSettings[mode]); err != nil {
throttlerLog.WithError(err).WithField("ksm-mode", mode).Error("kick failed to tune")
continue
}

Expand All @@ -306,17 +309,21 @@ func (k *ksm) throttle() {
if throttle.nextKnob == ksmInitial {
k.Lock()
if err := k.restoreSysFS(); err != nil {
throttlerLog.Error(err)
throttlerLog.WithError(err).Error("failed to restore sysfs")
}
k.Unlock()
}
continue
}

nextKnob := ksmThrottleIntervals[k.currentKnob].nextKnob
interval := ksmThrottleIntervals[k.currentKnob].interval
currentKnob := k.currentKnob
nextKnob := ksmThrottleIntervals[currentKnob].nextKnob
interval := ksmThrottleIntervals[currentKnob].interval
if err := k.tune(ksmSettings[nextKnob]); err != nil {
throttlerLog.Error(err)
throttlerLog.WithError(err).WithFields(logrus.Fields{
"current-ksm-mode": currentKnob,
"next-ksm-mode": nextKnob,
}).Error("timer failed to tune")
continue
}

Expand Down Expand Up @@ -371,7 +378,7 @@ func (k *ksm) kick() {
k.Lock()

if !k.initialized {
throttlerLog.Error(errors.New("KSM is unavailable"))
throttlerLog.WithError(errors.New("KSM is unavailable")).Error()
k.Unlock()
return
}
Expand Down Expand Up @@ -409,7 +416,7 @@ func startKSM(root string, mode ksmMode) (*ksm, error) {
} else {
setting, ok := ksmSettings[mode]
if !ok {
return k, fmt.Errorf("Invalide KSM mode %v", mode)
return k, fmt.Errorf("Invalid KSM mode %v", mode)
}

if err := k.tune(setting); err != nil {
Expand Down

0 comments on commit 9594e17

Please sign in to comment.