package models import ( "encoding/json" "errors" "fmt" "sort" "time" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/grafana/grafana/pkg/util/cmputil" ) var ( // ErrAlertRuleNotFound is an error for an unknown alert rule. ErrAlertRuleNotFound = fmt.Errorf("could not find alert rule") // ErrAlertRuleFailedGenerateUniqueUID is an error for failure to generate alert rule UID ErrAlertRuleFailedGenerateUniqueUID = errors.New("failed to generate alert rule UID") // ErrCannotEditNamespace is an error returned if the user does not have permissions to edit the namespace ErrCannotEditNamespace = errors.New("user does not have permissions to edit the namespace") ErrRuleGroupNamespaceNotFound = errors.New("rule group not found under this namespace") ErrAlertRuleFailedValidation = errors.New("invalid alert rule") ErrAlertRuleUniqueConstraintViolation = errors.New("a conflicting alert rule is found: rule title under the same organisation and folder should be unique") ErrQuotaReached = errors.New("quota has been exceeded") ) // swagger:enum NoDataState type NoDataState string func (noDataState NoDataState) String() string { return string(noDataState) } func NoDataStateFromString(state string) (NoDataState, error) { switch state { case string(Alerting): return Alerting, nil case string(NoData): return NoData, nil case string(OK): return OK, nil default: return "", fmt.Errorf("unknown NoData state option %s", state) } } const ( Alerting NoDataState = "Alerting" NoData NoDataState = "NoData" OK NoDataState = "OK" ) // swagger:enum ExecutionErrorState type ExecutionErrorState string func (executionErrorState ExecutionErrorState) String() string { return string(executionErrorState) } func ErrStateFromString(opt string) (ExecutionErrorState, error) { switch opt { case string(Alerting): return AlertingErrState, nil case string(ErrorErrState): return ErrorErrState, nil case string(OkErrState): return OkErrState, nil default: return "", fmt.Errorf("unknown Error state option %s", opt) } } const ( AlertingErrState ExecutionErrorState = "Alerting" ErrorErrState ExecutionErrorState = "Error" OkErrState ExecutionErrorState = "OK" ) const ( RuleUIDLabel = "__alert_rule_uid__" NamespaceUIDLabel = "__alert_rule_namespace_uid__" // Annotations are actually a set of labels, so technically this is the label name of an annotation. DashboardUIDAnnotation = "__dashboardUid__" PanelIDAnnotation = "__panelId__" // This isn't a hard-coded secret token, hence the nolint. //nolint:gosec ImageTokenAnnotation = "__alertImageToken__" // GrafanaReservedLabelPrefix contains the prefix for Grafana reserved labels. These differ from "__