-
Notifications
You must be signed in to change notification settings - Fork 655
fix custom plugin monitor condition change #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,45 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat | |
condition := &c.conditions[i] | ||
if condition.Type == result.Rule.Condition { | ||
status := toConditionStatus(result.ExitStatus) | ||
if condition.Status != status || condition.Reason != result.Rule.Reason { | ||
// change 1: Condition status change from True to False/Unknown | ||
if condition.Status == types.True && status != types.True { | ||
condition.Transition = timestamp | ||
var defaultConditionReason string | ||
var defaultConditionMessage string | ||
for j := range c.config.DefaultConditions { | ||
defaultCondition := &c.config.DefaultConditions[j] | ||
if defaultCondition.Type == result.Rule.Condition { | ||
defaultConditionReason = defaultCondition.Reason | ||
defaultConditionMessage = defaultCondition.Message | ||
break | ||
} | ||
} | ||
|
||
events = append(events, util.GenerateConditionChangeEvent( | ||
condition.Type, | ||
status, | ||
defaultConditionReason, | ||
timestamp, | ||
)) | ||
|
||
condition.Status = status | ||
condition.Message = defaultConditionMessage | ||
condition.Reason = defaultConditionReason | ||
} else if condition.Status != types.True && status == types.True { | ||
// change 2: Condition status change from False/Unknown to True | ||
condition.Transition = timestamp | ||
condition.Message = result.Message | ||
events = append(events, util.GenerateConditionChangeEvent( | ||
condition.Type, | ||
status, | ||
result.Rule.Reason, | ||
timestamp, | ||
)) | ||
|
||
condition.Status = status | ||
condition.Reason = result.Rule.Reason | ||
} else if condition.Status != status { | ||
// change 3: Condition status change from False to Unknown or vice versa | ||
condition.Transition = timestamp | ||
condition.Message = result.Message | ||
events = append(events, util.GenerateConditionChangeEvent( | ||
|
@@ -135,9 +173,21 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat | |
result.Rule.Reason, | ||
timestamp, | ||
)) | ||
|
||
condition.Status = status | ||
condition.Reason = result.Rule.Reason | ||
} else if condition.Status == status && condition.Message != result.Message { | ||
// change 4: Condition status do not change. condition message changes. | ||
condition.Transition = timestamp | ||
condition.Message = result.Message | ||
events = append(events, util.GenerateConditionChangeEvent( | ||
condition.Type, | ||
status, | ||
condition.Reason, | ||
timestamp, | ||
)) | ||
} | ||
condition.Status = status | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like most code in the if-else clause can be extracted out. At least event generation can be extracted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Some code refactor needs to be done. But i prefer we do little refactor on this to make the code more clear for others. |
||
condition.Reason = result.Rule.Reason | ||
|
||
break | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WE should only update condition when reason changes.
Message could be spammy and change a lot. See https://github.com/kubernetes/node-problem-detector/blob/master/pkg/systemlogmonitor/log_monitor.go#L142
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andyxning Address this?