mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): renames alert table to alert_rule
This commit is contained in:
parent
8ca7ccae38
commit
c83af353b2
@ -4,7 +4,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
)
|
||||
|
||||
type Alert struct {
|
||||
type AlertRule struct {
|
||||
Id int64
|
||||
DashboardId int64
|
||||
PanelId int64
|
||||
@ -19,8 +19,8 @@ type Alert struct {
|
||||
Aggregator string
|
||||
}
|
||||
|
||||
func (cmd *SaveDashboardCommand) GetAlertModels() *[]Alert {
|
||||
alerts := make([]Alert, 0)
|
||||
func (cmd *SaveDashboardCommand) GetAlertModels() *[]AlertRule {
|
||||
alerts := make([]AlertRule, 0)
|
||||
|
||||
for _, rowObj := range cmd.Dashboard.Get("rows").MustArray() {
|
||||
row := simplejson.NewFromAny(rowObj)
|
||||
@ -29,7 +29,7 @@ func (cmd *SaveDashboardCommand) GetAlertModels() *[]Alert {
|
||||
panel := simplejson.NewFromAny(panelObj)
|
||||
|
||||
alerting := panel.Get("alerting")
|
||||
alert := Alert{
|
||||
alert := AlertRule{
|
||||
DashboardId: cmd.Result.Id,
|
||||
PanelId: panel.Get("id").MustInt64(),
|
||||
Id: alerting.Get("id").MustInt64(),
|
||||
@ -67,5 +67,5 @@ type SaveAlertsCommand struct {
|
||||
UserId int64
|
||||
OrgId int64
|
||||
|
||||
Alerts *[]Alert
|
||||
Alerts *[]AlertRule
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func SaveAlerts(cmd *m.SaveAlertsCommand) error {
|
||||
}
|
||||
|
||||
if missing {
|
||||
_, err = x.Exec("DELETE FROM alert WHERE id = ?", missingAlert.Id)
|
||||
_, err = x.Exec("DELETE FROM alert_rule WHERE id = ?", missingAlert.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -67,30 +67,30 @@ func SaveAlerts(cmd *m.SaveAlertsCommand) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAlertsByDashboardId(dashboardId int64) ([]m.Alert, error) {
|
||||
alerts := make([]m.Alert, 0)
|
||||
func GetAlertsByDashboardId(dashboardId int64) ([]m.AlertRule, error) {
|
||||
alerts := make([]m.AlertRule, 0)
|
||||
err := x.Where("dashboard_id = ?", dashboardId).Find(&alerts)
|
||||
|
||||
if err != nil {
|
||||
return []m.Alert{}, err
|
||||
return []m.AlertRule{}, err
|
||||
}
|
||||
|
||||
return alerts, nil
|
||||
}
|
||||
|
||||
func GetAlertsByDashboardAndPanelId(dashboardId, panelId int64) (m.Alert, error) {
|
||||
func GetAlertsByDashboardAndPanelId(dashboardId, panelId int64) (m.AlertRule, error) {
|
||||
// this code should be refactored!!
|
||||
// uniqueness should be garanted!
|
||||
|
||||
alerts := make([]m.Alert, 0)
|
||||
alerts := make([]m.AlertRule, 0)
|
||||
err := x.Where("dashboard_id = ? and panel_id = ?", dashboardId, panelId).Find(&alerts)
|
||||
|
||||
if err != nil {
|
||||
return m.Alert{}, err
|
||||
return m.AlertRule{}, err
|
||||
}
|
||||
|
||||
if len(alerts) != 1 {
|
||||
return m.Alert{}, err
|
||||
return m.AlertRule{}, err
|
||||
}
|
||||
|
||||
return alerts[0], nil
|
||||
|
@ -14,7 +14,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
|
||||
testDash := insertTestDashboard("dashboard with alerts", 1, "alert")
|
||||
|
||||
items := []m.Alert{
|
||||
items := []m.AlertRule{
|
||||
{
|
||||
PanelId: 1,
|
||||
DashboardId: testDash.Id,
|
||||
@ -85,7 +85,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Multiple alerts per dashboard", func() {
|
||||
multipleItems := []m.Alert{
|
||||
multipleItems := []m.AlertRule{
|
||||
{
|
||||
DashboardId: testDash.Id,
|
||||
PanelId: 1,
|
||||
@ -129,7 +129,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("When dashboard is removed", func() {
|
||||
items := []m.Alert{
|
||||
items := []m.AlertRule{
|
||||
{
|
||||
PanelId: 1,
|
||||
DashboardId: testDash.Id,
|
||||
|
@ -227,7 +227,7 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
|
||||
"DELETE FROM dashboard_tag WHERE dashboard_id = ? ",
|
||||
"DELETE FROM star WHERE dashboard_id = ? ",
|
||||
"DELETE FROM dashboard WHERE id = ?",
|
||||
"DELETE FROM alert WHERE dashboard_id = ?",
|
||||
"DELETE FROM alert_rule WHERE dashboard_id = ?",
|
||||
}
|
||||
|
||||
for _, sql := range deletes {
|
||||
|
@ -3,10 +3,8 @@ package migrations
|
||||
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
|
||||
func addAlertMigrations(mg *Migrator) {
|
||||
mg.AddMigration("Drop old table alert table", NewDropTableMigration("alert"))
|
||||
|
||||
alertV1 := Table{
|
||||
Name: "alert",
|
||||
Name: "alert_rule",
|
||||
Columns: []*Column{
|
||||
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||
{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
|
||||
@ -25,4 +23,16 @@ func addAlertMigrations(mg *Migrator) {
|
||||
|
||||
// create table
|
||||
mg.AddMigration("create alert table v1", NewAddTableMigration(alertV1))
|
||||
|
||||
alert_changes := Table{
|
||||
Name: "alert_rule_updates",
|
||||
Columns: []*Column{
|
||||
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||
{Name: "alert_id", Type: DB_BigInt, Nullable: false},
|
||||
{Name: "org_id", Type: DB_BigInt, Nullable: false},
|
||||
{Name: "created", Type: DB_DateTime, Nullable: false},
|
||||
},
|
||||
}
|
||||
|
||||
mg.AddMigration("create alert_rules_updates table v1", NewAddTableMigration(alert_changes))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user