[v9.4.x] Alerting: Allow pausing alerts from provisioning (#62492)

Alerting: Allow pausing alerts from provisioning (#62263)

* Allow pausing alerts from provisioning

* Update swagger

* Add IsPaused to provision export endpoints

* Add pause field in sample.yml

* Add exception for reset state in first loop iteration of scheduler if rule is paused

* Update provision definition and swagger docs

* Fix provisioning export tests

* Suggestion: Simplify if condition

* Add more context to a comment

(cherry picked from commit 7a465f42a6)

Co-authored-by: Alex Moreno <alexander.moreno@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2023-01-30 17:01:37 +01:00
committed by GitHub
co-authored by Alex Moreno
parent 992e5d72ff
commit 04dd4e7f7c
9 changed files with 89 additions and 44 deletions
@@ -78,6 +78,7 @@ type AlertRuleV1 struct {
For values.StringValue `json:"for" yaml:"for"`
Annotations values.StringMapValue `json:"annotations" yaml:"annotations"`
Labels values.StringMapValue `json:"labels" yaml:"labels"`
IsPaused values.BoolValue `json:"isPaused" yaml:"isPaused"`
}
func (rule *AlertRuleV1) mapToModel(orgID int64) (models.AlertRule, error) {
@@ -134,6 +135,7 @@ func (rule *AlertRuleV1) mapToModel(orgID int64) (models.AlertRule, error) {
if len(alertRule.Data) == 0 {
return models.AlertRule{}, fmt.Errorf("rule '%s' failed to parse: no data set", alertRule.Title)
}
alertRule.IsPaused = rule.IsPaused.Value()
return alertRule, nil
}
@@ -205,6 +207,7 @@ type AlertRuleExport struct {
For model.Duration `json:"for" yaml:"for"`
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
IsPaused bool `json:"isPaused" yaml:"isPaused"`
}
// AlertQueryExport is the provisioned export of models.AlertQuery.
@@ -281,6 +284,7 @@ func newAlertRuleExport(rule models.AlertRule) (AlertRuleExport, error) {
ExecErrState: rule.ExecErrState,
Annotations: rule.Annotations,
Labels: rule.Labels,
IsPaused: rule.IsPaused,
}, nil
}