Skip to content

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions pkg/custompluginmonitor/custom_plugin_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andyxning Address this?

// 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
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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
}
}
Expand Down