Merge pull request #151 from Random-Liu/improve-cpm

Improve cpm
This commit is contained in:
k8s-ci-robot
2018-06-22 01:10:05 -07:00
committed by GitHub
8 changed files with 100 additions and 19 deletions
+12 -6
View File
@@ -21,13 +21,14 @@ import (
"io/ioutil"
"time"
"github.com/golang/glog"
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers"
watchertypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
systemlogtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
"k8s.io/node-problem-detector/pkg/types"
"github.com/golang/glog"
"k8s.io/node-problem-detector/pkg/util"
"k8s.io/node-problem-detector/pkg/util/tomb"
)
@@ -138,11 +139,17 @@ func (l *logMonitor) generateStatus(logs []*logtypes.Log, rule systemlogtypes.Ru
// Update transition timestamp and message when the condition
// changes. Condition is considered to be changed only when
// status or reason changes.
if !condition.Status || condition.Reason != rule.Reason {
if condition.Status == types.False || condition.Reason != rule.Reason {
condition.Transition = timestamp
condition.Message = message
events = append(events, util.GenerateConditionChangeEvent(
condition.Type,
types.True,
rule.Reason,
timestamp,
))
}
condition.Status = true
condition.Status = types.True
condition.Reason = rule.Reason
break
}
@@ -172,8 +179,7 @@ func initialConditions(defaults []types.Condition) []types.Condition {
conditions := make([]types.Condition, len(defaults))
copy(conditions, defaults)
for i := range conditions {
// TODO(random-liu): Validate default conditions
conditions[i].Status = false
conditions[i].Status = types.False
conditions[i].Transition = time.Now()
}
return conditions
+11 -4
View File
@@ -28,6 +28,7 @@ import (
watchertest "k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/testing"
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
"k8s.io/node-problem-detector/pkg/types"
"k8s.io/node-problem-detector/pkg/util"
)
const (
@@ -40,13 +41,13 @@ func TestGenerateStatus(t *testing.T) {
initConditions := []types.Condition{
{
Type: testConditionA,
Status: true,
Status: types.True,
Transition: time.Unix(500, 500),
Reason: "initial reason",
},
{
Type: testConditionB,
Status: false,
Status: types.False,
Transition: time.Unix(500, 500),
},
}
@@ -73,10 +74,16 @@ func TestGenerateStatus(t *testing.T) {
},
expected: types.Status{
Source: testSource,
Events: []types.Event{util.GenerateConditionChangeEvent(
testConditionA,
types.True,
"test reason",
time.Unix(1000, 1000),
)},
Conditions: []types.Condition{
{
Type: testConditionA,
Status: true,
Status: types.True,
Transition: time.Unix(1000, 1000),
Reason: "test reason",
Message: "test message 1\ntest message 2",
@@ -97,7 +104,7 @@ func TestGenerateStatus(t *testing.T) {
Conditions: []types.Condition{
{
Type: testConditionA,
Status: true,
Status: types.True,
Transition: time.Unix(500, 500),
Reason: "initial reason",
},