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"
|
no_data_state = "Alerting"
|
||||||
exec_err_state = "Error"
|
exec_err_state = "Error"
|
||||||
for = 0
|
for = "0s"
|
||||||
annotations = {
|
annotations = {
|
||||||
test = "annotation"
|
test = "annotation"
|
||||||
}
|
}
|
||||||
@ -632,7 +632,7 @@ func TestProvisioningApi(t *testing.T) {
|
|||||||
|
|
||||||
no_data_state = "OK"
|
no_data_state = "OK"
|
||||||
exec_err_state = "OK"
|
exec_err_state = "OK"
|
||||||
for = 0
|
for = "0s"
|
||||||
is_paused = false
|
is_paused = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ func AlertRuleExportFromAlertRule(rule models.AlertRule) (definitions.AlertRuleE
|
|||||||
IsPaused: rule.IsPaused,
|
IsPaused: rule.IsPaused,
|
||||||
}
|
}
|
||||||
if rule.For.Seconds() > 0 {
|
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 {
|
if rule.Annotations != nil {
|
||||||
result.Annotations = &rule.Annotations
|
result.Annotations = &rule.Annotations
|
||||||
|
@ -44,6 +44,7 @@ resource "grafana_rule_group" "rule_group_0000" {
|
|||||||
|
|
||||||
no_data_state = "NoData"
|
no_data_state = "NoData"
|
||||||
exec_err_state = "Alerting"
|
exec_err_state = "Alerting"
|
||||||
|
for = "2m"
|
||||||
is_paused = false
|
is_paused = false
|
||||||
}
|
}
|
||||||
rule {
|
rule {
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
],
|
],
|
||||||
"noDataState": "NoData",
|
"noDataState": "NoData",
|
||||||
"execErrState": "Alerting",
|
"execErrState": "Alerting",
|
||||||
"for": "0s",
|
"for": "2m",
|
||||||
"isPaused": false
|
"isPaused": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -114,4 +114,4 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ groups:
|
|||||||
type: math
|
type: math
|
||||||
noDataState: NoData
|
noDataState: NoData
|
||||||
execErrState: Alerting
|
execErrState: Alerting
|
||||||
for: 0s
|
for: 2m
|
||||||
isPaused: false
|
isPaused: false
|
||||||
- title: reduced testdata query - 2
|
- title: reduced testdata query - 2
|
||||||
condition: B
|
condition: B
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"interval": "10s",
|
"interval": "10s",
|
||||||
"rules": [
|
"rules": [
|
||||||
{
|
{
|
||||||
|
"for": "2m",
|
||||||
"grafana_alert": {
|
"grafana_alert": {
|
||||||
"title": "prom query with SSE - 2",
|
"title": "prom query with SSE - 2",
|
||||||
"condition": "condition",
|
"condition": "condition",
|
||||||
|
@ -243,10 +243,13 @@ type AlertRuleExport struct {
|
|||||||
NoDataState NoDataState `json:"noDataState" yaml:"noDataState" hcl:"no_data_state"`
|
NoDataState NoDataState `json:"noDataState" yaml:"noDataState" hcl:"no_data_state"`
|
||||||
ExecErrState ExecutionErrorState `json:"execErrState" yaml:"execErrState" hcl:"exec_err_state"`
|
ExecErrState ExecutionErrorState `json:"execErrState" yaml:"execErrState" hcl:"exec_err_state"`
|
||||||
For model.Duration `json:"for" yaml:"for"`
|
For model.Duration `json:"for" yaml:"for"`
|
||||||
ForSeconds *int64 `json:"-" yaml:"-" hcl:"for"`
|
// ForString is used to:
|
||||||
Annotations *map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty" hcl:"annotations"`
|
// - Only export the for field for HCL if it is non-zero.
|
||||||
Labels *map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" hcl:"labels"`
|
// - Format the Prometheus model.Duration type properly for HCL.
|
||||||
IsPaused bool `json:"isPaused" yaml:"isPaused" hcl:"is_paused"`
|
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.
|
// AlertQueryExport is the provisioned export of models.AlertQuery.
|
||||||
|
Loading…
Reference in New Issue
Block a user