diff --git a/config/custom-plugin-monitor.json b/config/custom-plugin-monitor.json index 166cea1e6..caeda5401 100644 --- a/config/custom-plugin-monitor.json +++ b/config/custom-plugin-monitor.json @@ -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": [ diff --git a/pkg/custompluginmonitor/custom_plugin_monitor.go b/pkg/custompluginmonitor/custom_plugin_monitor.go index 6bed9c3e8..bcef091fa 100644 --- a/pkg/custompluginmonitor/custom_plugin_monitor.go +++ b/pkg/custompluginmonitor/custom_plugin_monitor.go @@ -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 diff --git a/pkg/custompluginmonitor/types/config.go b/pkg/custompluginmonitor/types/config.go index 1b3d45470..d1a7ffd02 100644 --- a/pkg/custompluginmonitor/types/config.go +++ b/pkg/custompluginmonitor/types/config.go @@ -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" ) @@ -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. @@ -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 {