mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add missing option "OK" for Error state (#45262)
* Add missing OK option to models * add ok to legacy legacy UI does not support it but it is possible to do so via provisioning. * use enums in migration so linter would catch missing cases
This commit is contained in:
parent
b58f3c8a05
commit
016d9e14ed
@ -28,6 +28,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
ExecutionErrorSetOk ExecutionErrorOption = "ok"
|
||||||
ExecutionErrorSetAlerting ExecutionErrorOption = "alerting"
|
ExecutionErrorSetAlerting ExecutionErrorOption = "alerting"
|
||||||
ExecutionErrorKeepState ExecutionErrorOption = "keep_state"
|
ExecutionErrorKeepState ExecutionErrorOption = "keep_state"
|
||||||
)
|
)
|
||||||
@ -55,7 +56,7 @@ func (s NoDataOption) ToAlertState() AlertStateType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s ExecutionErrorOption) IsValid() bool {
|
func (s ExecutionErrorOption) IsValid() bool {
|
||||||
return s == ExecutionErrorSetAlerting || s == ExecutionErrorKeepState
|
return s == ExecutionErrorSetAlerting || s == ExecutionErrorKeepState || s == ExecutionErrorSetOk
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s ExecutionErrorOption) ToAlertState() AlertStateType {
|
func (s ExecutionErrorOption) ToAlertState() AlertStateType {
|
||||||
|
@ -354,6 +354,7 @@ const (
|
|||||||
type ExecutionErrorState string
|
type ExecutionErrorState string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
OkErrState ExecutionErrorState = "OK"
|
||||||
AlertingErrState ExecutionErrorState = "Alerting"
|
AlertingErrState ExecutionErrorState = "Alerting"
|
||||||
ErrorErrState ExecutionErrorState = "Error"
|
ErrorErrState ExecutionErrorState = "Error"
|
||||||
)
|
)
|
||||||
|
@ -874,11 +874,12 @@
|
|||||||
},
|
},
|
||||||
"exec_err_state": {
|
"exec_err_state": {
|
||||||
"enum": [
|
"enum": [
|
||||||
|
"OK",
|
||||||
"Alerting",
|
"Alerting",
|
||||||
"Error"
|
"Error"
|
||||||
],
|
],
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-enum-desc": "Alerting AlertingErrState\nError ErrorErrState",
|
"x-go-enum-desc": "OK OkErrState\nAlerting AlertingErrState\nError ErrorErrState",
|
||||||
"x-go-name": "ExecErrState"
|
"x-go-name": "ExecErrState"
|
||||||
},
|
},
|
||||||
"id": {
|
"id": {
|
||||||
@ -1836,11 +1837,12 @@
|
|||||||
},
|
},
|
||||||
"exec_err_state": {
|
"exec_err_state": {
|
||||||
"enum": [
|
"enum": [
|
||||||
|
"OK",
|
||||||
"Alerting",
|
"Alerting",
|
||||||
"Error"
|
"Error"
|
||||||
],
|
],
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-enum-desc": "Alerting AlertingErrState\nError ErrorErrState",
|
"x-go-enum-desc": "OK OkErrState\nAlerting AlertingErrState\nError ErrorErrState",
|
||||||
"x-go-name": "ExecErrState"
|
"x-go-name": "ExecErrState"
|
||||||
},
|
},
|
||||||
"no_data_state": {
|
"no_data_state": {
|
||||||
|
@ -2627,10 +2627,11 @@
|
|||||||
"exec_err_state": {
|
"exec_err_state": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
"OK",
|
||||||
"Alerting",
|
"Alerting",
|
||||||
"Error"
|
"Error"
|
||||||
],
|
],
|
||||||
"x-go-enum-desc": "Alerting AlertingErrState\nError ErrorErrState",
|
"x-go-enum-desc": "OK OkErrState\nAlerting AlertingErrState\nError ErrorErrState",
|
||||||
"x-go-name": "ExecErrState"
|
"x-go-name": "ExecErrState"
|
||||||
},
|
},
|
||||||
"id": {
|
"id": {
|
||||||
@ -3590,10 +3591,11 @@
|
|||||||
"exec_err_state": {
|
"exec_err_state": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
"OK",
|
||||||
"Alerting",
|
"Alerting",
|
||||||
"Error"
|
"Error"
|
||||||
],
|
],
|
||||||
"x-go-enum-desc": "Alerting AlertingErrState\nError ErrorErrState",
|
"x-go-enum-desc": "OK OkErrState\nAlerting AlertingErrState\nError ErrorErrState",
|
||||||
"x-go-name": "ExecErrState"
|
"x-go-name": "ExecErrState"
|
||||||
},
|
},
|
||||||
"no_data_state": {
|
"no_data_state": {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/expr"
|
"github.com/grafana/grafana/pkg/expr"
|
||||||
|
legacymodels "github.com/grafana/grafana/pkg/models"
|
||||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||||
"github.com/grafana/grafana/pkg/tsdb/graphite"
|
"github.com/grafana/grafana/pkg/tsdb/graphite"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
@ -241,29 +242,29 @@ func ruleAdjustInterval(freq int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func transNoData(s string) (string, error) {
|
func transNoData(s string) (string, error) {
|
||||||
switch s {
|
switch legacymodels.NoDataOption(s) {
|
||||||
case "ok":
|
case legacymodels.NoDataSetOK:
|
||||||
return "OK", nil // values from ngalert/models/rule
|
return string(ngmodels.OK), nil // values from ngalert/models/rule
|
||||||
case "", "no_data":
|
case "", legacymodels.NoDataSetNoData:
|
||||||
return "NoData", nil
|
return string(ngmodels.NoData), nil
|
||||||
case "alerting":
|
case legacymodels.NoDataSetAlerting:
|
||||||
return "Alerting", nil
|
return string(ngmodels.Alerting), nil
|
||||||
case "keep_state":
|
case legacymodels.NoDataKeepState:
|
||||||
return "NoData", nil // "keep last state" translates to no data because we now emit a special alert when the state is "noData". The result is that the evaluation will not return firing and instead we'll raise the special alert.
|
return string(ngmodels.NoData), nil // "keep last state" translates to no data because we now emit a special alert when the state is "noData". The result is that the evaluation will not return firing and instead we'll raise the special alert.
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("unrecognized No Data setting %v", s)
|
return "", fmt.Errorf("unrecognized No Data setting %v", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func transExecErr(s string) (string, error) {
|
func transExecErr(s string) (string, error) {
|
||||||
switch s {
|
switch legacymodels.ExecutionErrorOption(s) {
|
||||||
case "", "alerting":
|
case "", legacymodels.ExecutionErrorSetAlerting:
|
||||||
return "Alerting", nil
|
return string(ngmodels.AlertingErrState), nil
|
||||||
case "keep_state":
|
case legacymodels.ExecutionErrorKeepState:
|
||||||
// Keep last state is translated to error as we now emit a
|
// Keep last state is translated to error as we now emit a
|
||||||
// DatasourceError alert when the state is error
|
// DatasourceError alert when the state is error
|
||||||
return "Error", nil
|
return string(ngmodels.ErrorErrState), nil
|
||||||
case "ok":
|
case legacymodels.ExecutionErrorSetOk:
|
||||||
return "OK", nil
|
return string(ngmodels.OkErrState), nil
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("unrecognized Execution Error setting %v", s)
|
return "", fmt.Errorf("unrecognized Execution Error setting %v", s)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user