Chore: Add alert ctx (#41161)
* Add context for alert * Remove context.TODO * Remove xorm * Remove context.TODO * Fix UsageStatsQuerier interface
This commit is contained in:
@@ -14,40 +14,44 @@ import (
|
||||
// timeNow makes it possible to test usage of time
|
||||
var timeNow = time.Now
|
||||
|
||||
func init() {
|
||||
bus.AddHandler("sql", SaveAlerts)
|
||||
bus.AddHandler("sql", HandleAlertsQuery)
|
||||
bus.AddHandler("sql", GetAlertById)
|
||||
bus.AddHandler("sql", GetAllAlertQueryHandler)
|
||||
bus.AddHandler("sql", SetAlertState)
|
||||
bus.AddHandler("sql", GetAlertStatesForDashboard)
|
||||
bus.AddHandler("sql", PauseAlert)
|
||||
bus.AddHandler("sql", PauseAllAlerts)
|
||||
func (ss *SQLStore) addAlertQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", SaveAlerts)
|
||||
bus.AddHandlerCtx("sql", ss.HandleAlertsQuery)
|
||||
bus.AddHandlerCtx("sql", ss.GetAlertById)
|
||||
bus.AddHandlerCtx("sql", ss.GetAllAlertQueryHandler)
|
||||
bus.AddHandlerCtx("sql", SetAlertState)
|
||||
bus.AddHandlerCtx("sql", ss.GetAlertStatesForDashboard)
|
||||
bus.AddHandlerCtx("sql", PauseAlert)
|
||||
bus.AddHandlerCtx("sql", PauseAllAlerts)
|
||||
}
|
||||
|
||||
func GetAlertById(query *models.GetAlertByIdQuery) error {
|
||||
alert := models.Alert{}
|
||||
has, err := x.ID(query.Id).Get(&alert)
|
||||
if !has {
|
||||
return fmt.Errorf("could not find alert")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (ss *SQLStore) GetAlertById(ctx context.Context, query *models.GetAlertByIdQuery) error {
|
||||
return ss.WithDbSession(ctx, func(sess *DBSession) error {
|
||||
alert := models.Alert{}
|
||||
has, err := sess.ID(query.Id).Get(&alert)
|
||||
if !has {
|
||||
return fmt.Errorf("could not find alert")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
query.Result = &alert
|
||||
return nil
|
||||
query.Result = &alert
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func GetAllAlertQueryHandler(query *models.GetAllAlertsQuery) error {
|
||||
var alerts []*models.Alert
|
||||
err := x.SQL("select * from alert").Find(&alerts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (ss *SQLStore) GetAllAlertQueryHandler(ctx context.Context, query *models.GetAllAlertsQuery) error {
|
||||
return ss.WithDbSession(ctx, func(sess *DBSession) error {
|
||||
var alerts []*models.Alert
|
||||
err := sess.SQL("select * from alert").Find(&alerts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
query.Result = alerts
|
||||
return nil
|
||||
query.Result = alerts
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func deleteAlertByIdInternal(alertId int64, reason string, sess *DBSession) error {
|
||||
@@ -72,10 +76,11 @@ func deleteAlertByIdInternal(alertId int64, reason string, sess *DBSession) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func HandleAlertsQuery(query *models.GetAlertsQuery) error {
|
||||
builder := SQLBuilder{}
|
||||
func (ss *SQLStore) HandleAlertsQuery(ctx context.Context, query *models.GetAlertsQuery) error {
|
||||
return ss.WithDbSession(ctx, func(sess *DBSession) error {
|
||||
builder := SQLBuilder{}
|
||||
|
||||
builder.Write(`SELECT
|
||||
builder.Write(`SELECT
|
||||
alert.id,
|
||||
alert.dashboard_id,
|
||||
alert.panel_id,
|
||||
@@ -90,64 +95,65 @@ func HandleAlertsQuery(query *models.GetAlertsQuery) error {
|
||||
FROM alert
|
||||
INNER JOIN dashboard on dashboard.id = alert.dashboard_id `)
|
||||
|
||||
builder.Write(`WHERE alert.org_id = ?`, query.OrgId)
|
||||
builder.Write(`WHERE alert.org_id = ?`, query.OrgId)
|
||||
|
||||
if len(strings.TrimSpace(query.Query)) > 0 {
|
||||
builder.Write(" AND alert.name "+dialect.LikeStr()+" ?", "%"+query.Query+"%")
|
||||
}
|
||||
|
||||
if len(query.DashboardIDs) > 0 {
|
||||
builder.sql.WriteString(` AND alert.dashboard_id IN (?` + strings.Repeat(",?", len(query.DashboardIDs)-1) + `) `)
|
||||
|
||||
for _, dbID := range query.DashboardIDs {
|
||||
builder.AddParams(dbID)
|
||||
if len(strings.TrimSpace(query.Query)) > 0 {
|
||||
builder.Write(" AND alert.name "+dialect.LikeStr()+" ?", "%"+query.Query+"%")
|
||||
}
|
||||
}
|
||||
|
||||
if query.PanelId != 0 {
|
||||
builder.Write(` AND alert.panel_id = ?`, query.PanelId)
|
||||
}
|
||||
if len(query.DashboardIDs) > 0 {
|
||||
builder.sql.WriteString(` AND alert.dashboard_id IN (?` + strings.Repeat(",?", len(query.DashboardIDs)-1) + `) `)
|
||||
|
||||
if len(query.State) > 0 && query.State[0] != "all" {
|
||||
builder.Write(` AND (`)
|
||||
for i, v := range query.State {
|
||||
if i > 0 {
|
||||
builder.Write(" OR ")
|
||||
for _, dbID := range query.DashboardIDs {
|
||||
builder.AddParams(dbID)
|
||||
}
|
||||
if strings.HasPrefix(v, "not_") {
|
||||
builder.Write("state <> ? ")
|
||||
v = strings.TrimPrefix(v, "not_")
|
||||
} else {
|
||||
builder.Write("state = ? ")
|
||||
}
|
||||
|
||||
if query.PanelId != 0 {
|
||||
builder.Write(` AND alert.panel_id = ?`, query.PanelId)
|
||||
}
|
||||
|
||||
if len(query.State) > 0 && query.State[0] != "all" {
|
||||
builder.Write(` AND (`)
|
||||
for i, v := range query.State {
|
||||
if i > 0 {
|
||||
builder.Write(" OR ")
|
||||
}
|
||||
if strings.HasPrefix(v, "not_") {
|
||||
builder.Write("state <> ? ")
|
||||
v = strings.TrimPrefix(v, "not_")
|
||||
} else {
|
||||
builder.Write("state = ? ")
|
||||
}
|
||||
builder.AddParams(v)
|
||||
}
|
||||
builder.AddParams(v)
|
||||
builder.Write(")")
|
||||
}
|
||||
builder.Write(")")
|
||||
}
|
||||
|
||||
if query.User.OrgRole != models.ROLE_ADMIN {
|
||||
builder.WriteDashboardPermissionFilter(query.User, models.PERMISSION_VIEW)
|
||||
}
|
||||
|
||||
builder.Write(" ORDER BY name ASC")
|
||||
|
||||
if query.Limit != 0 {
|
||||
builder.Write(dialect.Limit(query.Limit))
|
||||
}
|
||||
|
||||
alerts := make([]*models.AlertListItemDTO, 0)
|
||||
if err := x.SQL(builder.GetSQLString(), builder.params...).Find(&alerts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range alerts {
|
||||
if alerts[i].ExecutionError == " " {
|
||||
alerts[i].ExecutionError = ""
|
||||
if query.User.OrgRole != models.ROLE_ADMIN {
|
||||
builder.WriteDashboardPermissionFilter(query.User, models.PERMISSION_VIEW)
|
||||
}
|
||||
}
|
||||
|
||||
query.Result = alerts
|
||||
return nil
|
||||
builder.Write(" ORDER BY name ASC")
|
||||
|
||||
if query.Limit != 0 {
|
||||
builder.Write(dialect.Limit(query.Limit))
|
||||
}
|
||||
|
||||
alerts := make([]*models.AlertListItemDTO, 0)
|
||||
if err := sess.SQL(builder.GetSQLString(), builder.params...).Find(&alerts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range alerts {
|
||||
if alerts[i].ExecutionError == " " {
|
||||
alerts[i].ExecutionError = ""
|
||||
}
|
||||
}
|
||||
|
||||
query.Result = alerts
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func deleteAlertDefinition(dashboardId int64, sess *DBSession) error {
|
||||
@@ -167,7 +173,7 @@ func deleteAlertDefinition(dashboardId int64, sess *DBSession) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ss *SQLStore) SaveAlerts(dashID int64, alerts []*models.Alert) error {
|
||||
func (ss *SQLStore) SaveAlerts(ctx context.Context, dashID int64, alerts []*models.Alert) error {
|
||||
return ss.WithTransactionalDbSession(context.Background(), func(sess *DBSession) error {
|
||||
existingAlerts, err := GetAlertsByDashboardId2(dashID, sess)
|
||||
if err != nil {
|
||||
@@ -186,7 +192,7 @@ func (ss *SQLStore) SaveAlerts(dashID int64, alerts []*models.Alert) error {
|
||||
})
|
||||
}
|
||||
|
||||
func SaveAlerts(cmd *models.SaveAlertsCommand) error {
|
||||
func SaveAlerts(ctx context.Context, cmd *models.SaveAlertsCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
existingAlerts, err := GetAlertsByDashboardId2(cmd.DashboardId, sess)
|
||||
if err != nil {
|
||||
@@ -299,7 +305,7 @@ func GetAlertsByDashboardId2(dashboardId int64, sess *DBSession) ([]*models.Aler
|
||||
return alerts, nil
|
||||
}
|
||||
|
||||
func SetAlertState(cmd *models.SetAlertStateCommand) error {
|
||||
func SetAlertState(ctx context.Context, cmd *models.SetAlertStateCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
alert := models.Alert{}
|
||||
|
||||
@@ -338,7 +344,7 @@ func SetAlertState(cmd *models.SetAlertStateCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func PauseAlert(cmd *models.PauseAlertCommand) error {
|
||||
func PauseAlert(ctx context.Context, cmd *models.PauseAlertCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
if len(cmd.AlertIds) == 0 {
|
||||
return fmt.Errorf("command contains no alertids")
|
||||
@@ -372,7 +378,7 @@ func PauseAlert(cmd *models.PauseAlertCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func PauseAllAlerts(cmd *models.PauseAllAlertCommand) error {
|
||||
func PauseAllAlerts(ctx context.Context, cmd *models.PauseAllAlertCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
var newState string
|
||||
if cmd.Paused {
|
||||
@@ -390,8 +396,9 @@ func PauseAllAlerts(cmd *models.PauseAllAlertCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func GetAlertStatesForDashboard(query *models.GetAlertStatesForDashboardQuery) error {
|
||||
var rawSQL = `SELECT
|
||||
func (ss *SQLStore) GetAlertStatesForDashboard(ctx context.Context, query *models.GetAlertStatesForDashboardQuery) error {
|
||||
return ss.WithDbSession(ctx, func(sess *DBSession) error {
|
||||
var rawSQL = `SELECT
|
||||
id,
|
||||
dashboard_id,
|
||||
panel_id,
|
||||
@@ -400,8 +407,9 @@ func GetAlertStatesForDashboard(query *models.GetAlertStatesForDashboardQuery) e
|
||||
FROM alert
|
||||
WHERE org_id = ? AND dashboard_id = ?`
|
||||
|
||||
query.Result = make([]*models.AlertStateInfoDTO, 0)
|
||||
err := x.SQL(rawSQL, query.OrgId, query.DashboardId).Find(&query.Result)
|
||||
query.Result = make([]*models.AlertStateInfoDTO, 0)
|
||||
err := sess.SQL(rawSQL, query.OrgId, query.DashboardId).Find(&query.Result)
|
||||
|
||||
return err
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
UserId: 1,
|
||||
}
|
||||
|
||||
err = SaveAlerts(&cmd)
|
||||
err = SaveAlerts(context.Background(), &cmd)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
|
||||
// Get alert so we can use its ID in tests
|
||||
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&alertQuery)
|
||||
err2 := sqlStore.HandleAlertsQuery(context.Background(), &alertQuery)
|
||||
require.Nil(t, err2)
|
||||
|
||||
insertedAlert := alertQuery.Result[0]
|
||||
@@ -83,11 +83,11 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
State: models.AlertStateOK,
|
||||
}
|
||||
|
||||
err := SetAlertState(cmd)
|
||||
err := SetAlertState(context.Background(), cmd)
|
||||
require.Nil(t, err)
|
||||
})
|
||||
|
||||
alert, _ := getAlertById(t, insertedAlert.Id)
|
||||
alert, _ := getAlertById(t, insertedAlert.Id, sqlStore)
|
||||
stateDateBeforePause := alert.NewStateDate
|
||||
|
||||
t.Run("can pause all alerts", func(t *testing.T) {
|
||||
@@ -100,18 +100,18 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
State: models.AlertStateOK,
|
||||
}
|
||||
|
||||
err = SetAlertState(cmd)
|
||||
err = SetAlertState(context.Background(), cmd)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("alert is paused", func(t *testing.T) {
|
||||
alert, _ = getAlertById(t, insertedAlert.Id)
|
||||
alert, _ = getAlertById(t, insertedAlert.Id, sqlStore)
|
||||
currentState := alert.State
|
||||
require.Equal(t, models.AlertStatePaused, currentState)
|
||||
})
|
||||
|
||||
t.Run("pausing alerts should update their NewStateDate", func(t *testing.T) {
|
||||
alert, _ = getAlertById(t, insertedAlert.Id)
|
||||
alert, _ = getAlertById(t, insertedAlert.Id, sqlStore)
|
||||
stateDateAfterPause := alert.NewStateDate
|
||||
require.True(t, stateDateBeforePause.Before(stateDateAfterPause))
|
||||
})
|
||||
@@ -119,7 +119,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
t.Run("unpausing alerts should update their NewStateDate again", func(t *testing.T) {
|
||||
err := pauseAllAlerts(t, false)
|
||||
require.Nil(t, err)
|
||||
alert, _ = getAlertById(t, insertedAlert.Id)
|
||||
alert, _ = getAlertById(t, insertedAlert.Id, sqlStore)
|
||||
stateDateAfterUnpause := alert.NewStateDate
|
||||
require.True(t, stateDateBeforePause.Before(stateDateAfterUnpause))
|
||||
})
|
||||
@@ -129,7 +129,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
t.Run("Can read properties", func(t *testing.T) {
|
||||
setup(t)
|
||||
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&alertQuery)
|
||||
err2 := sqlStore.HandleAlertsQuery(context.Background(), &alertQuery)
|
||||
|
||||
alert := alertQuery.Result[0]
|
||||
require.Nil(t, err2)
|
||||
@@ -151,7 +151,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
setup(t)
|
||||
viewerUser := &models.SignedInUser{OrgRole: models.ROLE_VIEWER, OrgId: 1}
|
||||
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: viewerUser}
|
||||
err2 := HandleAlertsQuery(&alertQuery)
|
||||
err2 := sqlStore.HandleAlertsQuery(context.Background(), &alertQuery)
|
||||
|
||||
require.Nil(t, err2)
|
||||
require.Equal(t, 1, len(alertQuery.Result))
|
||||
@@ -169,7 +169,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
Alerts: modifiedItems,
|
||||
}
|
||||
|
||||
err := SaveAlerts(&modifiedCmd)
|
||||
err := SaveAlerts(context.Background(), &modifiedCmd)
|
||||
|
||||
t.Run("Can save alerts with same dashboard and panel id", func(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
@@ -177,7 +177,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("Alerts should be updated", func(t *testing.T) {
|
||||
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&query)
|
||||
err2 := sqlStore.HandleAlertsQuery(context.Background(), &query)
|
||||
|
||||
require.Nil(t, err2)
|
||||
require.Equal(t, 1, len(query.Result))
|
||||
@@ -189,7 +189,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Updates without changes should be ignored", func(t *testing.T) {
|
||||
err3 := SaveAlerts(&modifiedCmd)
|
||||
err3 := SaveAlerts(context.Background(), &modifiedCmd)
|
||||
require.Nil(t, err3)
|
||||
})
|
||||
})
|
||||
@@ -221,13 +221,13 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
}
|
||||
|
||||
cmd.Alerts = multipleItems
|
||||
err := SaveAlerts(&cmd)
|
||||
err := SaveAlerts(context.Background(), &cmd)
|
||||
|
||||
t.Run("Should save 3 dashboards", func(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
queryForDashboard := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&queryForDashboard)
|
||||
err2 := sqlStore.HandleAlertsQuery(context.Background(), &queryForDashboard)
|
||||
|
||||
require.Nil(t, err2)
|
||||
require.Equal(t, 3, len(queryForDashboard.Result))
|
||||
@@ -237,11 +237,11 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
missingOneAlert := multipleItems[:2]
|
||||
|
||||
cmd.Alerts = missingOneAlert
|
||||
err = SaveAlerts(&cmd)
|
||||
err = SaveAlerts(context.Background(), &cmd)
|
||||
|
||||
t.Run("should delete the missing alert", func(t *testing.T) {
|
||||
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&query)
|
||||
err2 := sqlStore.HandleAlertsQuery(context.Background(), &query)
|
||||
require.Nil(t, err2)
|
||||
require.Equal(t, 2, len(query.Result))
|
||||
})
|
||||
@@ -266,7 +266,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
UserId: 1,
|
||||
}
|
||||
|
||||
err := SaveAlerts(&cmd)
|
||||
err := SaveAlerts(context.Background(), &cmd)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = DeleteDashboard(context.Background(), &models.DeleteDashboardCommand{
|
||||
@@ -277,7 +277,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("Alerts should be removed", func(t *testing.T) {
|
||||
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&query)
|
||||
err2 := sqlStore.HandleAlertsQuery(context.Background(), &query)
|
||||
|
||||
require.Nil(t, err2)
|
||||
require.Equal(t, 0, len(query.Result))
|
||||
@@ -301,7 +301,7 @@ func TestPausingAlerts(t *testing.T) {
|
||||
|
||||
// Get alert so we can use its ID in tests
|
||||
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&alertQuery)
|
||||
err2 := sqlStore.HandleAlertsQuery(context.Background(), &alertQuery)
|
||||
require.Nil(t, err2)
|
||||
|
||||
insertedAlert := alertQuery.Result[0]
|
||||
@@ -311,7 +311,7 @@ func TestPausingAlerts(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("the NewStateDate should be updated", func(t *testing.T) {
|
||||
alert, err := getAlertById(t, insertedAlert.Id)
|
||||
alert, err := getAlertById(t, insertedAlert.Id, sqlStore)
|
||||
require.Nil(t, err)
|
||||
|
||||
stateDateAfterPause = alert.NewStateDate
|
||||
@@ -324,7 +324,7 @@ func TestPausingAlerts(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("the NewStateDate should be updated again", func(t *testing.T) {
|
||||
alert, err := getAlertById(t, insertedAlert.Id)
|
||||
alert, err := getAlertById(t, insertedAlert.Id, sqlStore)
|
||||
require.Nil(t, err)
|
||||
|
||||
stateDateAfterUnpause := alert.NewStateDate
|
||||
@@ -339,7 +339,7 @@ func pauseAlert(t *testing.T, orgId int64, alertId int64, pauseState bool) (int6
|
||||
AlertIds: []int64{alertId},
|
||||
Paused: pauseState,
|
||||
}
|
||||
err := PauseAlert(cmd)
|
||||
err := PauseAlert(context.Background(), cmd)
|
||||
require.Nil(t, err)
|
||||
return cmd.ResultCount, err
|
||||
}
|
||||
@@ -363,15 +363,15 @@ func insertTestAlert(title string, message string, orgId int64, dashId int64, se
|
||||
UserId: 1,
|
||||
}
|
||||
|
||||
err := SaveAlerts(&cmd)
|
||||
err := SaveAlerts(context.Background(), &cmd)
|
||||
return cmd.Alerts[0], err
|
||||
}
|
||||
|
||||
func getAlertById(t *testing.T, id int64) (*models.Alert, error) {
|
||||
func getAlertById(t *testing.T, id int64, ss *SQLStore) (*models.Alert, error) {
|
||||
q := &models.GetAlertByIdQuery{
|
||||
Id: id,
|
||||
}
|
||||
err := GetAlertById(q)
|
||||
err := ss.GetAlertById(context.Background(), q)
|
||||
require.Nil(t, err)
|
||||
return q.Result, err
|
||||
}
|
||||
@@ -380,7 +380,7 @@ func pauseAllAlerts(t *testing.T, pauseState bool) error {
|
||||
cmd := &models.PauseAllAlertCommand{
|
||||
Paused: pauseState,
|
||||
}
|
||||
err := PauseAllAlerts(cmd)
|
||||
err := PauseAllAlerts(context.Background(), cmd)
|
||||
require.Nil(t, err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ func newSQLStore(cfg *setting.Cfg, cacheService *localcache.CacheService, bus bu
|
||||
ss.addQuotaQueryAndCommandHandlers()
|
||||
ss.addOrgUsersQueryAndCommandHandlers()
|
||||
ss.addStarQueryAndCommandHandlers()
|
||||
ss.addAlertQueryAndCommandHandlers()
|
||||
|
||||
// if err := ss.Reset(); err != nil {
|
||||
// return nil, err
|
||||
|
||||
Reference in New Issue
Block a user