From 5f28890fec089abfd958ad3b879ba1f62668da1a Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Thu, 22 Mar 2018 13:41:17 +0000 Subject: [PATCH 1/3] ksm: Fix typo. Fix typo. Signed-off-by: James O. D. Hunt --- ksm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ksm.go b/ksm.go index a0e1fbd..c55bd55 100644 --- a/ksm.go +++ b/ksm.go @@ -409,7 +409,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 { From 712d846ccfa3b39261c1d5bd0fdcb77a3c3834ca Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Thu, 22 Mar 2018 14:10:41 +0000 Subject: [PATCH 2/3] logging: Ensure errors are logged correctly 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 #26. Signed-off-by: James O. D. Hunt --- ksm.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ksm.go b/ksm.go index c55bd55..4c4e69b 100644 --- a/ksm.go +++ b/ksm.go @@ -270,7 +270,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 } @@ -287,7 +287,7 @@ func (k *ksm) throttle() { // We will enter the aggressive setting until we throttle down. _ = throttleTimer.Stop() if err := k.tune(ksmSettings[ksmAggressive]); err != nil { - throttlerLog.Error(err) + throttlerLog.WithError(err).Error("kick failed to tune") continue } @@ -306,7 +306,7 @@ 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() } @@ -316,7 +316,7 @@ func (k *ksm) throttle() { nextKnob := ksmThrottleIntervals[k.currentKnob].nextKnob interval := ksmThrottleIntervals[k.currentKnob].interval if err := k.tune(ksmSettings[nextKnob]); err != nil { - throttlerLog.Error(err) + throttlerLog.WithError(err).Error("timer failed to tune") continue } @@ -371,7 +371,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 } From 44ccd8f1dfb884f4df683479a169b629a4a52bf6 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Thu, 22 Mar 2018 14:11:56 +0000 Subject: [PATCH 3/3] logging: Add further log fields on error Supplement the existing logs when errors occur with further structured log fields. Signed-off-by: James O. D. Hunt --- ksm.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ksm.go b/ksm.go index 4c4e69b..7ce13c8 100644 --- a/ksm.go +++ b/ksm.go @@ -19,6 +19,8 @@ import ( "sync" "syscall" "time" + + "github.com/sirupsen/logrus" ) type ksmSetting struct { @@ -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.WithError(err).Error("kick failed to tune") + mode := ksmAggressive + if err := k.tune(ksmSettings[mode]); err != nil { + throttlerLog.WithError(err).WithField("ksm-mode", mode).Error("kick failed to tune") continue } @@ -313,10 +316,14 @@ func (k *ksm) throttle() { 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.WithError(err).Error("timer failed to tune") + throttlerLog.WithError(err).WithFields(logrus.Fields{ + "current-ksm-mode": currentKnob, + "next-ksm-mode": nextKnob, + }).Error("timer failed to tune") continue }