mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix HCL export for alerts with non-zero "for" field. (#76739)
* Alerting: Fix HCL export for alerts with non-zero "for" field. Fixes #76734 * fix tests --------- Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
parent
8985f79aab
commit
a0476741f2
@ -605,7 +605,7 @@ func TestProvisioningApi(t *testing.T) {
|
||||
|
||||
no_data_state = "Alerting"
|
||||
exec_err_state = "Error"
|
||||
for = 0
|
||||
for = "0s"
|
||||
annotations = {
|
||||
test = "annotation"
|
||||
}
|
||||
@ -632,7 +632,7 @@ func TestProvisioningApi(t *testing.T) {
|
||||
|
||||
no_data_state = "OK"
|
||||
exec_err_state = "OK"
|
||||
for = 0
|
||||
for = "0s"
|
||||
is_paused = false
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ func AlertRuleExportFromAlertRule(rule models.AlertRule) (definitions.AlertRuleE
|
||||
IsPaused: rule.IsPaused,
|
||||
}
|
||||
if rule.For.Seconds() > 0 {
|
||||
result.ForSeconds = util.Pointer(int64(rule.For.Seconds()))
|
||||
result.ForString = util.Pointer(model.Duration(rule.For).String())
|
||||
}
|
||||
if rule.Annotations != nil {
|
||||
result.Annotations = &rule.Annotations
|
||||
|
@ -44,6 +44,7 @@ resource "grafana_rule_group" "rule_group_0000" {
|
||||
|
||||
no_data_state = "NoData"
|
||||
exec_err_state = "Alerting"
|
||||
for = "2m"
|
||||
is_paused = false
|
||||
}
|
||||
rule {
|
||||
|
@ -64,7 +64,7 @@
|
||||
],
|
||||
"noDataState": "NoData",
|
||||
"execErrState": "Alerting",
|
||||
"for": "0s",
|
||||
"for": "2m",
|
||||
"isPaused": false
|
||||
},
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ groups:
|
||||
type: math
|
||||
noDataState: NoData
|
||||
execErrState: Alerting
|
||||
for: 0s
|
||||
for: 2m
|
||||
isPaused: false
|
||||
- title: reduced testdata query - 2
|
||||
condition: B
|
||||
|
@ -3,6 +3,7 @@
|
||||
"interval": "10s",
|
||||
"rules": [
|
||||
{
|
||||
"for": "2m",
|
||||
"grafana_alert": {
|
||||
"title": "prom query with SSE - 2",
|
||||
"condition": "condition",
|
||||
|
@ -243,10 +243,13 @@ type AlertRuleExport struct {
|
||||
NoDataState NoDataState `json:"noDataState" yaml:"noDataState" hcl:"no_data_state"`
|
||||
ExecErrState ExecutionErrorState `json:"execErrState" yaml:"execErrState" hcl:"exec_err_state"`
|
||||
For model.Duration `json:"for" yaml:"for"`
|
||||
ForSeconds *int64 `json:"-" yaml:"-" hcl:"for"`
|
||||
Annotations *map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty" hcl:"annotations"`
|
||||
Labels *map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" hcl:"labels"`
|
||||
IsPaused bool `json:"isPaused" yaml:"isPaused" hcl:"is_paused"`
|
||||
// ForString is used to:
|
||||
// - Only export the for field for HCL if it is non-zero.
|
||||
// - Format the Prometheus model.Duration type properly for HCL.
|
||||
ForString *string `json:"-" yaml:"-" hcl:"for"`
|
||||
Annotations *map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty" hcl:"annotations"`
|
||||
Labels *map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" hcl:"labels"`
|
||||
IsPaused bool `json:"isPaused" yaml:"isPaused" hcl:"is_paused"`
|
||||
}
|
||||
|
||||
// AlertQueryExport is the provisioned export of models.AlertQuery.
|
||||
|
Loading…
Reference in New Issue
Block a user