Skip to content

Commit

Permalink
enable codnition updaet when message change for custom plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
andyxning committed Dec 10, 2018
1 parent 515b854 commit c6c7124
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config/custom-plugin-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"invoke_interval": "30s",
"timeout": "5s",
"max_output_length": 80,
"concurrency": 3
"concurrency": 3,
"enable_message_change_based_condition_update": false
},
"source": "ntp-custom-plugin-monitor",
"conditions": [
Expand Down
2 changes: 1 addition & 1 deletion pkg/custompluginmonitor/custom_plugin_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat

condition.Status = status
condition.Reason = result.Rule.Reason
} else if condition.Status == status && condition.Reason != result.Rule.Reason {
} else if condition.Status == status && (condition.Reason != result.Rule.Reason || (*c.config.PluginGlobalConfig.EnableMessageChangeBasedConditionUpdate && condition.Message != result.Message)) {
// change 4: Condition status do not change. condition reason changes.
condition.Transition = timestamp
condition.Reason = result.Rule.Reason
Expand Down
18 changes: 12 additions & 6 deletions pkg/custompluginmonitor/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (
)

var (
defaultGlobalTimeout = 5 * time.Second
defaultGlobalTimeoutString = defaultGlobalTimeout.String()
defaultInvokeInterval = 30 * time.Second
defaultInvokeIntervalString = defaultInvokeInterval.String()
defaultMaxOutputLength = 80
defaultConcurrency = 3
defaultGlobalTimeout = 5 * time.Second
defaultGlobalTimeoutString = defaultGlobalTimeout.String()
defaultInvokeInterval = 30 * time.Second
defaultInvokeIntervalString = defaultInvokeInterval.String()
defaultMaxOutputLength = 80
defaultConcurrency = 3
defaultMessageChangeBasedConditionUpdate = false

customPluginName = "custom"
)
Expand All @@ -48,6 +49,8 @@ type pluginGlobalConfig struct {
MaxOutputLength *int `json:"max_output_length,omitempty"`
// Concurrency is the number of concurrent running plugins.
Concurrency *int `json:"concurrency,omitempty"`
// EnableMessageChangeBasedConditionUpdate indicates whether NPD should enable message change based condition update.
EnableMessageChangeBasedConditionUpdate *bool `json:"enable_message_change_based_condition_update,omitempty"`
}

// Custom plugin config is the configuration of custom plugin monitor.
Expand Down Expand Up @@ -95,6 +98,9 @@ func (cpc *CustomPluginConfig) ApplyConfiguration() error {
if cpc.PluginGlobalConfig.Concurrency == nil {
cpc.PluginGlobalConfig.Concurrency = &defaultConcurrency
}
if cpc.PluginGlobalConfig.EnableMessageChangeBasedConditionUpdate == nil {
cpc.PluginGlobalConfig.EnableMessageChangeBasedConditionUpdate = &defaultMessageChangeBasedConditionUpdate
}

for _, rule := range cpc.Rules {
if rule.TimeoutString != nil {
Expand Down

0 comments on commit c6c7124

Please sign in to comment.