mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Alerting NG: prototype v2 (WIP) * Separate eval package * Modify eval alert definition endpoint * Disable migration if ngalert is not enabled * Remove premature test * Fix lint issues * Delete obsolete struct * Apply suggestions from code review * Update pkg/services/ngalert/ngalert.go Co-authored-by: Kyle Brandt <kyle@grafana.com> * Add API endpoint for listing alert definitions * Introduce index for alert_definition table * make ds object for expression to avoid panic * wrap error * Update pkg/services/ngalert/eval/eval.go * Swith to backend.DataQuery * Export TransformWrapper callback * Fix lint issues * Update pkg/services/ngalert/ngalert.go Co-authored-by: Kyle Brandt <kyle@grafana.com> * Validate alert definitions before storing them * Introduce AlertQuery * Add test * Add QueryType in AlertQuery * Accept only float64 (seconds) durations * Apply suggestions from code review * Get rid of bus * Do not export symbols * Fix failing test * Fix failure due to service initialization order Introduce MediumHigh service priority and assign it to backendplugin service * Fix test * Apply suggestions from code review * Fix renamed reference Co-authored-by: Kyle Brandt <kyle@grafana.com>
93 lines
2.3 KiB
Go
93 lines
2.3 KiB
Go
package ngalert
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
|
)
|
|
|
|
// AlertDefinition is the model for alert definitions in Alerting NG.
|
|
type AlertDefinition struct {
|
|
Id int64
|
|
OrgId int64
|
|
Name string
|
|
Condition string
|
|
Data []eval.AlertQuery
|
|
}
|
|
|
|
var (
|
|
// errAlertDefinitionNotFound is an error for an unknown alert definition.
|
|
errAlertDefinitionNotFound = fmt.Errorf("could not find alert definition")
|
|
)
|
|
|
|
// getAlertDefinitionByIDQuery is the query for retrieving/deleting an alert definition by ID.
|
|
type getAlertDefinitionByIDQuery struct {
|
|
ID int64
|
|
OrgID int64
|
|
|
|
Result *AlertDefinition
|
|
}
|
|
|
|
type deleteAlertDefinitionByIDQuery struct {
|
|
ID int64
|
|
OrgID int64
|
|
|
|
RowsAffected int64
|
|
}
|
|
|
|
// condition is the structure used by storing/updating alert definition commmands
|
|
type condition struct {
|
|
RefID string `json:"refId"`
|
|
|
|
QueriesAndExpressions []eval.AlertQuery `json:"queriesAndExpressions"`
|
|
}
|
|
|
|
// saveAlertDefinitionCommand is the query for saving a new alert definition.
|
|
type saveAlertDefinitionCommand struct {
|
|
Name string `json:"name"`
|
|
OrgID int64 `json:"-"`
|
|
Condition condition `json:"condition"`
|
|
SignedInUser *models.SignedInUser `json:"-"`
|
|
SkipCache bool `json:"-"`
|
|
|
|
Result *AlertDefinition
|
|
}
|
|
|
|
// IsValid validates a SaveAlertDefinitionCommand.
|
|
// Always returns true.
|
|
func (cmd *saveAlertDefinitionCommand) IsValid() bool {
|
|
return true
|
|
}
|
|
|
|
// updateAlertDefinitionCommand is the query for updating an existing alert definition.
|
|
type updateAlertDefinitionCommand struct {
|
|
ID int64 `json:"-"`
|
|
Name string `json:"name"`
|
|
OrgID int64 `json:"-"`
|
|
Condition condition `json:"condition"`
|
|
SignedInUser *models.SignedInUser `json:"-"`
|
|
SkipCache bool `json:"-"`
|
|
|
|
RowsAffected int64
|
|
Result *AlertDefinition
|
|
}
|
|
|
|
// IsValid validates an UpdateAlertDefinitionCommand.
|
|
// Always returns true.
|
|
func (cmd *updateAlertDefinitionCommand) IsValid() bool {
|
|
return true
|
|
}
|
|
|
|
type evalAlertConditionCommand struct {
|
|
Condition eval.Condition `json:"condition"`
|
|
Now time.Time `json:"now"`
|
|
}
|
|
|
|
type listAlertDefinitionsCommand struct {
|
|
OrgID int64 `json:"-"`
|
|
|
|
Result []*AlertDefinition
|
|
}
|