add context in the alert_notification (#41307)

This commit is contained in:
ying-jeanne 2021-11-05 09:41:24 +01:00 committed by GitHub
parent c19d628ab6
commit a404a311da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 146 additions and 144 deletions

View File

@ -23,7 +23,7 @@ func ValidateOrgAlert(c *models.ReqContext) {
id := c.ParamsInt64(":alertId")
query := models.GetAlertByIdQuery{Id: id}
if err := bus.Dispatch(&query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
c.JsonApiErr(404, "Alert not found", nil)
return
}
@ -46,7 +46,7 @@ func GetAlertStatesForDashboard(c *models.ReqContext) response.Response {
DashboardId: c.QueryInt64("dashboardId"),
}
if err := bus.Dispatch(&query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to fetch alert states", err)
}
@ -120,7 +120,7 @@ func GetAlerts(c *models.ReqContext) response.Response {
query.State = states
}
if err := bus.Dispatch(&query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
return response.Error(500, "List alerts failed", err)
}
@ -176,7 +176,7 @@ func GetAlert(c *models.ReqContext) response.Response {
id := c.ParamsInt64(":alertId")
query := models.GetAlertByIdQuery{Id: id}
if err := bus.Dispatch(&query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
return response.Error(500, "List alerts failed", err)
}
@ -227,7 +227,7 @@ func GetAlertNotifications(c *models.ReqContext) response.Response {
func getAlertNotificationsInternal(c *models.ReqContext) ([]*models.AlertNotification, error) {
query := &models.GetAllAlertNotificationsQuery{OrgId: c.OrgId}
if err := bus.Dispatch(query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), query); err != nil {
return nil, err
}
@ -244,7 +244,7 @@ func GetAlertNotificationByID(c *models.ReqContext) response.Response {
return response.Error(404, "Alert notification not found", nil)
}
if err := bus.Dispatch(query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), query); err != nil {
return response.Error(500, "Failed to get alert notifications", err)
}
@ -265,7 +265,7 @@ func GetAlertNotificationByUID(c *models.ReqContext) response.Response {
return response.Error(404, "Alert notification not found", nil)
}
if err := bus.Dispatch(query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), query); err != nil {
return response.Error(500, "Failed to get alert notifications", err)
}
@ -279,7 +279,7 @@ func GetAlertNotificationByUID(c *models.ReqContext) response.Response {
func CreateAlertNotification(c *models.ReqContext, cmd models.CreateAlertNotificationCommand) response.Response {
cmd.OrgId = c.OrgId
if err := bus.Dispatch(&cmd); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationWithSameNameExists) || errors.Is(err, models.ErrAlertNotificationWithSameUIDExists) {
return response.Error(409, "Failed to create alert notification", err)
}
@ -301,7 +301,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext, cmd models.U
return response.Error(500, "Failed to update alert notification", err)
}
if err := bus.Dispatch(&cmd); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), err)
}
@ -317,7 +317,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext, cmd models.U
Id: cmd.Id,
}
if err := bus.Dispatch(&query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to get alert notification", err)
}
@ -333,7 +333,7 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext, cmd mod
return response.Error(500, "Failed to update alert notification", err)
}
if err := bus.Dispatch(&cmd); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), nil)
}
@ -345,7 +345,7 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext, cmd mod
Uid: cmd.Uid,
}
if err := bus.Dispatch(&query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to get alert notification", err)
}
@ -414,7 +414,7 @@ func DeleteAlertNotification(c *models.ReqContext) response.Response {
Id: c.ParamsInt64(":notificationId"),
}
if err := bus.Dispatch(&cmd); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), nil)
}
@ -430,7 +430,7 @@ func DeleteAlertNotificationByUID(c *models.ReqContext) response.Response {
Uid: web.Params(c.Req)[":uid"],
}
if err := bus.Dispatch(&cmd); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), nil)
}
@ -476,7 +476,7 @@ func PauseAlert(c *models.ReqContext, dto dtos.PauseAlertCommand) response.Respo
result["alertId"] = alertID
query := models.GetAlertByIdQuery{Id: alertID}
if err := bus.Dispatch(&query); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
return response.Error(500, "Get Alert failed", err)
}
@ -506,7 +506,7 @@ func PauseAlert(c *models.ReqContext, dto dtos.PauseAlertCommand) response.Respo
Paused: dto.Paused,
}
if err := bus.Dispatch(&cmd); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "", err)
}
@ -528,7 +528,7 @@ func PauseAllAlerts(c *models.ReqContext, dto dtos.PauseAllAlertsCommand) respon
Paused: dto.Paused,
}
if err := bus.Dispatch(&updateCmd); err != nil {
if err := bus.DispatchCtx(c.Req.Context(), &updateCmd); err != nil {
return response.Error(500, "Failed to pause alerts", err)
}

View File

@ -1,6 +1,7 @@
package alerting
import (
"context"
"io/ioutil"
"testing"
"time"
@ -184,11 +185,11 @@ func TestAlertRuleExtraction(t *testing.T) {
sqlStore := sqlstore.InitTestDB(t)
firstNotification := models.CreateAlertNotificationCommand{Uid: "notifier1", OrgId: 1, Name: "1"}
err = sqlStore.CreateAlertNotificationCommand(&firstNotification)
err = sqlStore.CreateAlertNotificationCommand(context.Background(), &firstNotification)
require.Nil(t, err)
secondNotification := models.CreateAlertNotificationCommand{Uid: "notifier2", OrgId: 1, Name: "2"}
err = sqlStore.CreateAlertNotificationCommand(&secondNotification)
err = sqlStore.CreateAlertNotificationCommand(context.Background(), &secondNotification)
require.Nil(t, err)
json, err := ioutil.ReadFile("./testdata/influxdb-alert.json")

View File

@ -246,7 +246,7 @@ func (n *notificationService) renderAndUploadImage(evalCtx *EvalContext, timeout
func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) {
query := &models.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids}
if err := bus.Dispatch(query); err != nil {
if err := bus.DispatchCtx(evalContext.Ctx, query); err != nil {
return nil, err
}

View File

@ -1,6 +1,7 @@
package alerting
import (
"context"
"fmt"
"testing"
"time"
@ -89,10 +90,10 @@ func TestAlertRuleModel(t *testing.T) {
})
firstNotification := models.CreateAlertNotificationCommand{Uid: "notifier1", OrgId: 1, Name: "1"}
err := sqlStore.CreateAlertNotificationCommand(&firstNotification)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), &firstNotification)
require.Nil(t, err)
secondNotification := models.CreateAlertNotificationCommand{Uid: "notifier2", OrgId: 1, Name: "2"}
err = sqlStore.CreateAlertNotificationCommand(&secondNotification)
err = sqlStore.CreateAlertNotificationCommand(context.Background(), &secondNotification)
require.Nil(t, err)
t.Run("Testing alert rule with notification id and uid", func(t *testing.T) {

View File

@ -24,25 +24,25 @@ func ProvideService(bus bus.Bus, store *sqlstore.SQLStore, encryptionService enc
EncryptionService: encryptionService,
}
s.Bus.AddHandler(s.GetAlertNotifications)
s.Bus.AddHandlerCtx(s.GetAlertNotifications)
s.Bus.AddHandlerCtx(s.CreateAlertNotificationCommand)
s.Bus.AddHandlerCtx(s.UpdateAlertNotification)
s.Bus.AddHandler(s.DeleteAlertNotification)
s.Bus.AddHandler(s.GetAllAlertNotifications)
s.Bus.AddHandlerCtx(s.DeleteAlertNotification)
s.Bus.AddHandlerCtx(s.GetAllAlertNotifications)
s.Bus.AddHandlerCtx(s.GetOrCreateAlertNotificationState)
s.Bus.AddHandlerCtx(s.SetAlertNotificationStateToCompleteCommand)
s.Bus.AddHandlerCtx(s.SetAlertNotificationStateToPendingCommand)
s.Bus.AddHandler(s.GetAlertNotificationsWithUid)
s.Bus.AddHandler(s.UpdateAlertNotificationWithUid)
s.Bus.AddHandler(s.DeleteAlertNotificationWithUid)
s.Bus.AddHandler(s.GetAlertNotificationsWithUidToSend)
s.Bus.AddHandlerCtx(s.GetAlertNotificationsWithUid)
s.Bus.AddHandlerCtx(s.UpdateAlertNotificationWithUid)
s.Bus.AddHandlerCtx(s.DeleteAlertNotificationWithUid)
s.Bus.AddHandlerCtx(s.GetAlertNotificationsWithUidToSend)
s.Bus.AddHandlerCtx(s.HandleNotificationTestCommand)
return s
}
func (s *AlertNotificationService) GetAlertNotifications(query *models.GetAlertNotificationsQuery) error {
return s.SQLStore.GetAlertNotifications(query)
func (s *AlertNotificationService) GetAlertNotifications(ctx context.Context, query *models.GetAlertNotificationsQuery) error {
return s.SQLStore.GetAlertNotifications(ctx, query)
}
func (s *AlertNotificationService) CreateAlertNotificationCommand(ctx context.Context, cmd *models.CreateAlertNotificationCommand) error {
@ -62,7 +62,7 @@ func (s *AlertNotificationService) CreateAlertNotificationCommand(ctx context.Co
return err
}
return s.SQLStore.CreateAlertNotificationCommand(cmd)
return s.SQLStore.CreateAlertNotificationCommand(ctx, cmd)
}
func (s *AlertNotificationService) UpdateAlertNotification(ctx context.Context, cmd *models.UpdateAlertNotificationCommand) error {
@ -83,15 +83,15 @@ func (s *AlertNotificationService) UpdateAlertNotification(ctx context.Context,
return err
}
return s.SQLStore.UpdateAlertNotification(cmd)
return s.SQLStore.UpdateAlertNotification(ctx, cmd)
}
func (s *AlertNotificationService) DeleteAlertNotification(cmd *models.DeleteAlertNotificationCommand) error {
return s.SQLStore.DeleteAlertNotification(cmd)
func (s *AlertNotificationService) DeleteAlertNotification(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
return s.SQLStore.DeleteAlertNotification(ctx, cmd)
}
func (s *AlertNotificationService) GetAllAlertNotifications(query *models.GetAllAlertNotificationsQuery) error {
return s.SQLStore.GetAllAlertNotifications(query)
func (s *AlertNotificationService) GetAllAlertNotifications(ctx context.Context, query *models.GetAllAlertNotificationsQuery) error {
return s.SQLStore.GetAllAlertNotifications(ctx, query)
}
func (s *AlertNotificationService) GetOrCreateAlertNotificationState(ctx context.Context, cmd *models.GetOrCreateNotificationStateQuery) error {
@ -106,20 +106,20 @@ func (s *AlertNotificationService) SetAlertNotificationStateToPendingCommand(ctx
return s.SQLStore.SetAlertNotificationStateToPendingCommand(ctx, cmd)
}
func (s *AlertNotificationService) GetAlertNotificationsWithUid(query *models.GetAlertNotificationsWithUidQuery) error {
return s.SQLStore.GetAlertNotificationsWithUid(query)
func (s *AlertNotificationService) GetAlertNotificationsWithUid(ctx context.Context, query *models.GetAlertNotificationsWithUidQuery) error {
return s.SQLStore.GetAlertNotificationsWithUid(ctx, query)
}
func (s *AlertNotificationService) UpdateAlertNotificationWithUid(cmd *models.UpdateAlertNotificationWithUidCommand) error {
return s.SQLStore.UpdateAlertNotificationWithUid(cmd)
func (s *AlertNotificationService) UpdateAlertNotificationWithUid(ctx context.Context, cmd *models.UpdateAlertNotificationWithUidCommand) error {
return s.SQLStore.UpdateAlertNotificationWithUid(ctx, cmd)
}
func (s *AlertNotificationService) DeleteAlertNotificationWithUid(cmd *models.DeleteAlertNotificationWithUidCommand) error {
return s.SQLStore.DeleteAlertNotificationWithUid(cmd)
func (s *AlertNotificationService) DeleteAlertNotificationWithUid(ctx context.Context, cmd *models.DeleteAlertNotificationWithUidCommand) error {
return s.SQLStore.DeleteAlertNotificationWithUid(ctx, cmd)
}
func (s *AlertNotificationService) GetAlertNotificationsWithUidToSend(query *models.GetAlertNotificationsWithUidToSendQuery) error {
return s.SQLStore.GetAlertNotificationsWithUidToSend(query)
func (s *AlertNotificationService) GetAlertNotificationsWithUidToSend(ctx context.Context, query *models.GetAlertNotificationsWithUidToSendQuery) error {
return s.SQLStore.GetAlertNotificationsWithUidToSend(ctx, query)
}
func (s *AlertNotificationService) createNotifier(ctx context.Context, model *models.AlertNotification, secureSettings map[string]string) (Notifier, error) {
@ -130,7 +130,7 @@ func (s *AlertNotificationService) createNotifier(ctx context.Context, model *mo
OrgId: model.OrgId,
Id: model.Id,
}
if err := s.SQLStore.GetAlertNotifications(query); err != nil {
if err := s.SQLStore.GetAlertNotifications(ctx, query); err != nil {
return nil, err
}

View File

@ -57,7 +57,7 @@ func TestService(t *testing.T) {
Id: cmd.Result.Id,
OrgId: cmd.Result.OrgId,
}
err = s.DeleteAlertNotification(&delCmd)
err = s.DeleteAlertNotification(context.Background(), &delCmd)
require.NoError(t, err)
})
@ -81,7 +81,7 @@ func TestService(t *testing.T) {
Id: createCmd.Result.Id,
OrgId: createCmd.Result.OrgId,
}
err = s.DeleteAlertNotification(&delCmd)
err = s.DeleteAlertNotification(context.Background(), &delCmd)
require.NoError(t, err)
})
@ -109,7 +109,7 @@ func TestService(t *testing.T) {
Id: createCmd.Result.Id,
OrgId: createCmd.Result.OrgId,
}
err = s.DeleteAlertNotification(&delCmd)
err = s.DeleteAlertNotification(context.Background(), &delCmd)
require.NoError(t, err)
})
}

View File

@ -30,8 +30,8 @@ func newNotificationProvisioner(encryptionService encryption.Service, log log.Lo
}
}
func (dc *NotificationProvisioner) apply(cfg *notificationsAsConfig) error {
if err := dc.deleteNotifications(cfg.DeleteNotifications); err != nil {
func (dc *NotificationProvisioner) apply(ctx context.Context, cfg *notificationsAsConfig) error {
if err := dc.deleteNotifications(ctx, cfg.DeleteNotifications); err != nil {
return err
}
@ -42,7 +42,7 @@ func (dc *NotificationProvisioner) apply(cfg *notificationsAsConfig) error {
return nil
}
func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*deleteNotificationConfig) error {
func (dc *NotificationProvisioner) deleteNotifications(ctx context.Context, notificationToDelete []*deleteNotificationConfig) error {
for _, notification := range notificationToDelete {
dc.log.Info("Deleting alert notification", "name", notification.Name, "uid", notification.UID)
@ -58,13 +58,13 @@ func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*d
getNotification := &models.GetAlertNotificationsWithUidQuery{Uid: notification.UID, OrgId: notification.OrgID}
if err := bus.Dispatch(getNotification); err != nil {
if err := bus.DispatchCtx(ctx, getNotification); err != nil {
return err
}
if getNotification.Result != nil {
cmd := &models.DeleteAlertNotificationWithUidCommand{Uid: getNotification.Result.Uid, OrgId: getNotification.OrgId}
if err := bus.Dispatch(cmd); err != nil {
if err := bus.DispatchCtx(ctx, cmd); err != nil {
return err
}
}
@ -140,7 +140,7 @@ func (dc *NotificationProvisioner) applyChanges(ctx context.Context, configPath
}
for _, cfg := range configs {
if err := dc.apply(cfg); err != nil {
if err := dc.apply(ctx, cfg); err != nil {
return err
}
}

View File

@ -146,7 +146,7 @@ func TestNotificationAsConfig(t *testing.T) {
t.Fatalf("applyChanges return an error %v", err)
}
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: 1}
err = sqlStore.GetAllAlertNotifications(&notificationsQuery)
err = sqlStore.GetAllAlertNotifications(context.Background(), &notificationsQuery)
require.NoError(t, err)
require.NotNil(t, notificationsQuery.Result)
require.Equal(t, len(notificationsQuery.Result), 2)
@ -160,11 +160,11 @@ func TestNotificationAsConfig(t *testing.T) {
Uid: "notifier1",
Type: "slack",
}
err := sqlStore.CreateAlertNotificationCommand(&existingNotificationCmd)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
require.NoError(t, err)
require.NotNil(t, existingNotificationCmd.Result)
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: 1}
err = sqlStore.GetAllAlertNotifications(&notificationsQuery)
err = sqlStore.GetAllAlertNotifications(context.Background(), &notificationsQuery)
require.NoError(t, err)
require.NotNil(t, notificationsQuery.Result)
require.Equal(t, len(notificationsQuery.Result), 1)
@ -175,7 +175,7 @@ func TestNotificationAsConfig(t *testing.T) {
if err != nil {
t.Fatalf("applyChanges return an error %v", err)
}
err = sqlStore.GetAllAlertNotifications(&notificationsQuery)
err = sqlStore.GetAllAlertNotifications(context.Background(), &notificationsQuery)
require.NoError(t, err)
require.NotNil(t, notificationsQuery.Result)
require.Equal(t, len(notificationsQuery.Result), 2)
@ -199,7 +199,7 @@ func TestNotificationAsConfig(t *testing.T) {
t.Run("should both be inserted", func(t *testing.T) {
require.NoError(t, err)
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: 1}
err = sqlStore.GetAllAlertNotifications(&notificationsQuery)
err = sqlStore.GetAllAlertNotifications(context.Background(), &notificationsQuery)
require.NoError(t, err)
require.NotNil(t, notificationsQuery.Result)
require.Equal(t, len(notificationsQuery.Result), 2)
@ -219,7 +219,7 @@ func TestNotificationAsConfig(t *testing.T) {
Uid: "notifier0",
Type: "slack",
}
err := sqlStore.CreateAlertNotificationCommand(&existingNotificationCmd)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
require.NoError(t, err)
existingNotificationCmd = models.CreateAlertNotificationCommand{
Name: "channel3",
@ -227,11 +227,11 @@ func TestNotificationAsConfig(t *testing.T) {
Uid: "notifier3",
Type: "slack",
}
err = sqlStore.CreateAlertNotificationCommand(&existingNotificationCmd)
err = sqlStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
require.NoError(t, err)
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: 1}
err = sqlStore.GetAllAlertNotifications(&notificationsQuery)
err = sqlStore.GetAllAlertNotifications(context.Background(), &notificationsQuery)
require.NoError(t, err)
require.NotNil(t, notificationsQuery.Result)
require.Equal(t, len(notificationsQuery.Result), 2)
@ -243,7 +243,7 @@ func TestNotificationAsConfig(t *testing.T) {
t.Fatalf("applyChanges return an error %v", err)
}
notificationsQuery = models.GetAllAlertNotificationsQuery{OrgId: 1}
err = sqlStore.GetAllAlertNotifications(&notificationsQuery)
err = sqlStore.GetAllAlertNotifications(context.Background(), &notificationsQuery)
require.NoError(t, err)
require.NotNil(t, notificationsQuery.Result)
require.Equal(t, len(notificationsQuery.Result), 4)
@ -268,7 +268,7 @@ func TestNotificationAsConfig(t *testing.T) {
Uid: "notifier2",
Type: "slack",
}
err = sqlStore.CreateAlertNotificationCommand(&existingNotificationCmd)
err = sqlStore.CreateAlertNotificationCommand(context.Background(), &existingNotificationCmd)
require.NoError(t, err)
dc := newNotificationProvisioner(ossencryption.ProvideService(), logger)
@ -278,7 +278,7 @@ func TestNotificationAsConfig(t *testing.T) {
}
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: existingOrg2.Result.Id}
err = sqlStore.GetAllAlertNotifications(&notificationsQuery)
err = sqlStore.GetAllAlertNotifications(context.Background(), &notificationsQuery)
require.NoError(t, err)
require.NotNil(t, notificationsQuery.Result)
require.Equal(t, len(notificationsQuery.Result), 1)
@ -310,7 +310,7 @@ func TestNotificationAsConfig(t *testing.T) {
t.Fatalf("applyChanges return an error %v", err)
}
notificationsQuery := models.GetAllAlertNotificationsQuery{OrgId: 1}
err = sqlStore.GetAllAlertNotifications(&notificationsQuery)
err = sqlStore.GetAllAlertNotifications(context.Background(), &notificationsQuery)
require.NoError(t, err)
require.Empty(t, notificationsQuery.Result)
})
@ -362,31 +362,31 @@ func TestNotificationAsConfig(t *testing.T) {
}
func setupBusHandlers(sqlStore *sqlstore.SQLStore) {
bus.AddHandler("getOrg", func(q *models.GetOrgByNameQuery) error {
return sqlstore.GetOrgByName(context.Background(), q)
bus.AddHandlerCtx("getOrg", func(ctx context.Context, q *models.GetOrgByNameQuery) error {
return sqlstore.GetOrgByName(ctx, q)
})
bus.AddHandler("getAlertNotifications", func(q *models.GetAlertNotificationsWithUidQuery) error {
return sqlStore.GetAlertNotificationsWithUid(q)
bus.AddHandlerCtx("getAlertNotifications", func(ctx context.Context, q *models.GetAlertNotificationsWithUidQuery) error {
return sqlStore.GetAlertNotificationsWithUid(ctx, q)
})
bus.AddHandler("createAlertNotification", func(cmd *models.CreateAlertNotificationCommand) error {
return sqlStore.CreateAlertNotificationCommand(cmd)
bus.AddHandlerCtx("createAlertNotification", func(ctx context.Context, cmd *models.CreateAlertNotificationCommand) error {
return sqlStore.CreateAlertNotificationCommand(ctx, cmd)
})
bus.AddHandler("updateAlertNotification", func(cmd *models.UpdateAlertNotificationCommand) error {
return sqlStore.UpdateAlertNotification(cmd)
bus.AddHandlerCtx("updateAlertNotification", func(ctx context.Context, cmd *models.UpdateAlertNotificationCommand) error {
return sqlStore.UpdateAlertNotification(ctx, cmd)
})
bus.AddHandler("updateAlertNotification", func(cmd *models.UpdateAlertNotificationWithUidCommand) error {
return sqlStore.UpdateAlertNotificationWithUid(cmd)
bus.AddHandlerCtx("updateAlertNotification", func(ctx context.Context, cmd *models.UpdateAlertNotificationWithUidCommand) error {
return sqlStore.UpdateAlertNotificationWithUid(ctx, cmd)
})
bus.AddHandler("deleteAlertNotification", func(cmd *models.DeleteAlertNotificationCommand) error {
return sqlStore.DeleteAlertNotification(cmd)
bus.AddHandlerCtx("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
return sqlStore.DeleteAlertNotification(ctx, cmd)
})
bus.AddHandler("deleteAlertNotification", func(cmd *models.DeleteAlertNotificationWithUidCommand) error {
return sqlStore.DeleteAlertNotificationWithUid(cmd)
bus.AddHandlerCtx("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationWithUidCommand) error {
return sqlStore.DeleteAlertNotificationWithUid(ctx, cmd)
})
}

View File

@ -13,7 +13,7 @@ import (
"github.com/grafana/grafana/pkg/util"
)
func (ss *SQLStore) DeleteAlertNotification(cmd *models.DeleteAlertNotificationCommand) error {
func (ss *SQLStore) DeleteAlertNotification(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
return inTransaction(func(sess *DBSession) error {
sql := "DELETE FROM alert_notification WHERE alert_notification.org_id = ? AND alert_notification.id = ?"
res, err := sess.Exec(sql, cmd.OrgId, cmd.Id)
@ -37,9 +37,9 @@ func (ss *SQLStore) DeleteAlertNotification(cmd *models.DeleteAlertNotificationC
})
}
func (ss *SQLStore) DeleteAlertNotificationWithUid(cmd *models.DeleteAlertNotificationWithUidCommand) error {
func (ss *SQLStore) DeleteAlertNotificationWithUid(ctx context.Context, cmd *models.DeleteAlertNotificationWithUidCommand) error {
existingNotification := &models.GetAlertNotificationsWithUidQuery{OrgId: cmd.OrgId, Uid: cmd.Uid}
if err := getAlertNotificationWithUidInternal(existingNotification, newSession(context.Background())); err != nil {
if err := getAlertNotificationWithUidInternal(ctx, existingNotification, newSession(context.Background())); err != nil {
return err
}
@ -52,22 +52,22 @@ func (ss *SQLStore) DeleteAlertNotificationWithUid(cmd *models.DeleteAlertNotifi
Id: existingNotification.Result.Id,
OrgId: existingNotification.Result.OrgId,
}
if err := bus.Dispatch(deleteCommand); err != nil {
if err := bus.DispatchCtx(ctx, deleteCommand); err != nil {
return err
}
return nil
}
func (ss *SQLStore) GetAlertNotifications(query *models.GetAlertNotificationsQuery) error {
return getAlertNotificationInternal(query, newSession(context.Background()))
func (ss *SQLStore) GetAlertNotifications(ctx context.Context, query *models.GetAlertNotificationsQuery) error {
return getAlertNotificationInternal(ctx, query, newSession(context.Background()))
}
func (ss *SQLStore) addAlertNotificationUidByIdHandler() {
bus.AddHandler("sql", ss.GetAlertNotificationUidWithId)
bus.AddHandlerCtx("sql", ss.GetAlertNotificationUidWithId)
}
func (ss *SQLStore) GetAlertNotificationUidWithId(query *models.GetAlertNotificationUidQuery) error {
func (ss *SQLStore) GetAlertNotificationUidWithId(ctx context.Context, query *models.GetAlertNotificationUidQuery) error {
cacheKey := newAlertNotificationUidCacheKey(query.OrgId, query.Id)
if cached, found := ss.CacheService.Get(cacheKey); found {
@ -75,7 +75,7 @@ func (ss *SQLStore) GetAlertNotificationUidWithId(query *models.GetAlertNotifica
return nil
}
err := getAlertNotificationUidInternal(query, newSession(context.Background()))
err := getAlertNotificationUidInternal(ctx, query, newSession(context.Background()))
if err != nil {
return err
}
@ -89,11 +89,11 @@ func newAlertNotificationUidCacheKey(orgID, notificationId int64) string {
return fmt.Sprintf("notification-uid-by-org-%d-and-id-%d", orgID, notificationId)
}
func (ss *SQLStore) GetAlertNotificationsWithUid(query *models.GetAlertNotificationsWithUidQuery) error {
return getAlertNotificationWithUidInternal(query, newSession(context.Background()))
func (ss *SQLStore) GetAlertNotificationsWithUid(ctx context.Context, query *models.GetAlertNotificationsWithUidQuery) error {
return getAlertNotificationWithUidInternal(ctx, query, newSession(context.Background()))
}
func (ss *SQLStore) GetAllAlertNotifications(query *models.GetAllAlertNotificationsQuery) error {
func (ss *SQLStore) GetAllAlertNotifications(ctx context.Context, query *models.GetAllAlertNotificationsQuery) error {
results := make([]*models.AlertNotification, 0)
if err := x.Where("org_id = ?", query.OrgId).Asc("name").Find(&results); err != nil {
return err
@ -103,7 +103,7 @@ func (ss *SQLStore) GetAllAlertNotifications(query *models.GetAllAlertNotificati
return nil
}
func (ss *SQLStore) GetAlertNotificationsWithUidToSend(query *models.GetAlertNotificationsWithUidToSendQuery) error {
func (ss *SQLStore) GetAlertNotificationsWithUidToSend(ctx context.Context, query *models.GetAlertNotificationsWithUidToSendQuery) error {
var sql bytes.Buffer
params := make([]interface{}, 0)
@ -147,7 +147,7 @@ func (ss *SQLStore) GetAlertNotificationsWithUidToSend(query *models.GetAlertNot
return nil
}
func getAlertNotificationUidInternal(query *models.GetAlertNotificationUidQuery, sess *DBSession) error {
func getAlertNotificationUidInternal(ctx context.Context, query *models.GetAlertNotificationUidQuery, sess *DBSession) error {
var sql bytes.Buffer
params := make([]interface{}, 0)
@ -176,7 +176,7 @@ func getAlertNotificationUidInternal(query *models.GetAlertNotificationUidQuery,
return nil
}
func getAlertNotificationInternal(query *models.GetAlertNotificationsQuery, sess *DBSession) error {
func getAlertNotificationInternal(ctx context.Context, query *models.GetAlertNotificationsQuery, sess *DBSession) error {
var sql bytes.Buffer
params := make([]interface{}, 0)
@ -226,7 +226,7 @@ func getAlertNotificationInternal(query *models.GetAlertNotificationsQuery, sess
return nil
}
func getAlertNotificationWithUidInternal(query *models.GetAlertNotificationsWithUidQuery, sess *DBSession) error {
func getAlertNotificationWithUidInternal(ctx context.Context, query *models.GetAlertNotificationsWithUidQuery, sess *DBSession) error {
var sql bytes.Buffer
params := make([]interface{}, 0)
@ -264,10 +264,10 @@ func getAlertNotificationWithUidInternal(query *models.GetAlertNotificationsWith
return nil
}
func (ss *SQLStore) CreateAlertNotificationCommand(cmd *models.CreateAlertNotificationCommand) error {
func (ss *SQLStore) CreateAlertNotificationCommand(ctx context.Context, cmd *models.CreateAlertNotificationCommand) error {
return inTransaction(func(sess *DBSession) error {
if cmd.Uid == "" {
uid, uidGenerationErr := generateNewAlertNotificationUid(sess, cmd.OrgId)
uid, uidGenerationErr := generateNewAlertNotificationUid(ctx, sess, cmd.OrgId)
if uidGenerationErr != nil {
return uidGenerationErr
}
@ -275,7 +275,7 @@ func (ss *SQLStore) CreateAlertNotificationCommand(cmd *models.CreateAlertNotifi
cmd.Uid = uid
}
existingQuery := &models.GetAlertNotificationsWithUidQuery{OrgId: cmd.OrgId, Uid: cmd.Uid}
err := getAlertNotificationWithUidInternal(existingQuery, sess)
err := getAlertNotificationWithUidInternal(ctx, existingQuery, sess)
if err != nil {
return err
@ -287,7 +287,7 @@ func (ss *SQLStore) CreateAlertNotificationCommand(cmd *models.CreateAlertNotifi
// check if name exists
sameNameQuery := &models.GetAlertNotificationsQuery{OrgId: cmd.OrgId, Name: cmd.Name}
if err := getAlertNotificationInternal(sameNameQuery, sess); err != nil {
if err := getAlertNotificationInternal(ctx, sameNameQuery, sess); err != nil {
return err
}
@ -338,7 +338,7 @@ func (ss *SQLStore) CreateAlertNotificationCommand(cmd *models.CreateAlertNotifi
})
}
func generateNewAlertNotificationUid(sess *DBSession, orgId int64) (string, error) {
func generateNewAlertNotificationUid(ctx context.Context, sess *DBSession, orgId int64) (string, error) {
for i := 0; i < 3; i++ {
uid := util.GenerateShortUID()
exists, err := sess.Where("org_id=? AND uid=?", orgId, uid).Get(&models.AlertNotification{})
@ -354,7 +354,7 @@ func generateNewAlertNotificationUid(sess *DBSession, orgId int64) (string, erro
return "", models.ErrAlertNotificationFailedGenerateUniqueUid
}
func (ss *SQLStore) UpdateAlertNotification(cmd *models.UpdateAlertNotificationCommand) error {
func (ss *SQLStore) UpdateAlertNotification(ctx context.Context, cmd *models.UpdateAlertNotificationCommand) error {
return inTransaction(func(sess *DBSession) (err error) {
current := models.AlertNotification{}
@ -368,7 +368,7 @@ func (ss *SQLStore) UpdateAlertNotification(cmd *models.UpdateAlertNotificationC
// check if name exists
sameNameQuery := &models.GetAlertNotificationsQuery{OrgId: cmd.OrgId, Name: cmd.Name}
if err := getAlertNotificationInternal(sameNameQuery, sess); err != nil {
if err := getAlertNotificationInternal(ctx, sameNameQuery, sess); err != nil {
return err
}
@ -422,10 +422,10 @@ func (ss *SQLStore) UpdateAlertNotification(cmd *models.UpdateAlertNotificationC
})
}
func (ss *SQLStore) UpdateAlertNotificationWithUid(cmd *models.UpdateAlertNotificationWithUidCommand) error {
func (ss *SQLStore) UpdateAlertNotificationWithUid(ctx context.Context, cmd *models.UpdateAlertNotificationWithUidCommand) error {
getAlertNotificationWithUidQuery := &models.GetAlertNotificationsWithUidQuery{OrgId: cmd.OrgId, Uid: cmd.Uid}
if err := getAlertNotificationWithUidInternal(getAlertNotificationWithUidQuery, newSession(context.Background())); err != nil {
if err := getAlertNotificationWithUidInternal(ctx, getAlertNotificationWithUidQuery, newSession(context.Background())); err != nil {
return err
}
@ -454,7 +454,7 @@ func (ss *SQLStore) UpdateAlertNotificationWithUid(cmd *models.UpdateAlertNotifi
OrgId: cmd.OrgId,
}
if err := bus.Dispatch(updateNotification); err != nil {
if err := bus.DispatchCtx(ctx, updateNotification); err != nil {
return err
}
@ -532,7 +532,7 @@ func (ss *SQLStore) GetOrCreateAlertNotificationState(ctx context.Context, cmd *
return inTransactionCtx(ctx, func(sess *DBSession) error {
nj := &models.AlertNotificationState{}
exist, err := getAlertNotificationState(sess, cmd, nj)
exist, err := getAlertNotificationState(ctx, sess, cmd, nj)
// if exists, return it, otherwise create it with default values
if err != nil {
@ -554,7 +554,7 @@ func (ss *SQLStore) GetOrCreateAlertNotificationState(ctx context.Context, cmd *
if _, err := sess.Insert(notificationState); err != nil {
if dialect.IsUniqueConstraintViolation(err) {
exist, err = getAlertNotificationState(sess, cmd, nj)
exist, err = getAlertNotificationState(ctx, sess, cmd, nj)
if err != nil {
return err
@ -576,7 +576,7 @@ func (ss *SQLStore) GetOrCreateAlertNotificationState(ctx context.Context, cmd *
})
}
func getAlertNotificationState(sess *DBSession, cmd *models.GetOrCreateNotificationStateQuery, nj *models.AlertNotificationState) (bool, error) {
func getAlertNotificationState(ctx context.Context, sess *DBSession, cmd *models.GetOrCreateNotificationStateQuery, nj *models.AlertNotificationState) (bool, error) {
return sess.
Where("alert_notification_state.org_id = ?", cmd.OrgId).
Where("alert_notification_state.alert_id = ?", cmd.AlertId).

View File

@ -23,8 +23,8 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
sqlStore := InitTestDB(t)
// Set up bus handlers
bus.AddHandler("deleteAlertNotification", func(cmd *models.DeleteAlertNotificationCommand) error {
return sqlStore.DeleteAlertNotification(cmd)
bus.AddHandlerCtx("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
return sqlStore.DeleteAlertNotification(ctx, cmd)
})
}
@ -159,7 +159,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Name: "email",
}
err := sqlStore.GetAlertNotifications(cmd)
err := sqlStore.GetAlertNotifications(context.Background(), cmd)
require.Nil(t, err)
require.Nil(t, cmd.Result)
})
@ -175,14 +175,14 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
}
t.Run("and missing frequency", func(t *testing.T) {
err := sqlStore.CreateAlertNotificationCommand(cmd)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
require.Equal(t, models.ErrNotificationFrequencyNotFound, err)
})
t.Run("invalid frequency", func(t *testing.T) {
cmd.Frequency = "invalid duration"
err := sqlStore.CreateAlertNotificationCommand(cmd)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
require.True(t, regexp.MustCompile(`^time: invalid duration "?invalid duration"?$`).MatchString(
err.Error()))
})
@ -198,7 +198,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Settings: simplejson.New(),
}
err := sqlStore.CreateAlertNotificationCommand(cmd)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
require.Nil(t, err)
updateCmd := &models.UpdateAlertNotificationCommand{
@ -207,14 +207,14 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
}
t.Run("and missing frequency", func(t *testing.T) {
err := sqlStore.UpdateAlertNotification(updateCmd)
err := sqlStore.UpdateAlertNotification(context.Background(), updateCmd)
require.Equal(t, models.ErrNotificationFrequencyNotFound, err)
})
t.Run("invalid frequency", func(t *testing.T) {
updateCmd.Frequency = "invalid duration"
err := sqlStore.UpdateAlertNotification(updateCmd)
err := sqlStore.UpdateAlertNotification(context.Background(), updateCmd)
require.Error(t, err)
require.True(t, regexp.MustCompile(`^time: invalid duration "?invalid duration"?$`).MatchString(
err.Error()))
@ -232,7 +232,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Settings: simplejson.New(),
}
err := sqlStore.CreateAlertNotificationCommand(cmd)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
require.Nil(t, err)
require.NotEqual(t, 0, cmd.Result.Id)
require.NotEqual(t, 0, cmd.Result.OrgId)
@ -242,7 +242,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
require.NotEmpty(t, cmd.Result.Uid)
t.Run("Cannot save Alert Notification with the same name", func(t *testing.T) {
err = sqlStore.CreateAlertNotificationCommand(cmd)
err = sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
require.Error(t, err)
})
t.Run("Cannot save Alert Notification with the same name and another uid", func(t *testing.T) {
@ -255,7 +255,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Settings: cmd.Settings,
Uid: "notifier1",
}
err = sqlStore.CreateAlertNotificationCommand(anotherUidCmd)
err = sqlStore.CreateAlertNotificationCommand(context.Background(), anotherUidCmd)
require.Error(t, err)
})
t.Run("Can save Alert Notification with another name and another uid", func(t *testing.T) {
@ -268,7 +268,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Settings: cmd.Settings,
Uid: "notifier2",
}
err = sqlStore.CreateAlertNotificationCommand(anotherUidCmd)
err = sqlStore.CreateAlertNotificationCommand(context.Background(), anotherUidCmd)
require.Nil(t, err)
})
@ -283,7 +283,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Settings: simplejson.New(),
Id: cmd.Result.Id,
}
err := sqlStore.UpdateAlertNotification(newCmd)
err := sqlStore.UpdateAlertNotification(context.Background(), newCmd)
require.Nil(t, err)
require.Equal(t, "NewName", newCmd.Result.Name)
require.Equal(t, 60*time.Second, newCmd.Result.Frequency)
@ -299,7 +299,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Settings: simplejson.New(),
Id: cmd.Result.Id,
}
err := sqlStore.UpdateAlertNotification(newCmd)
err := sqlStore.UpdateAlertNotification(context.Background(), newCmd)
require.Nil(t, err)
require.False(t, newCmd.Result.SendReminder)
})
@ -314,11 +314,11 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
otherOrg := models.CreateAlertNotificationCommand{Name: "default", Type: "email", OrgId: 2, SendReminder: true, Frequency: "10s", Settings: simplejson.New()}
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&cmd1))
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&cmd2))
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&cmd3))
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&cmd4))
require.Nil(t, sqlStore.CreateAlertNotificationCommand(&otherOrg))
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &cmd1))
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &cmd2))
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &cmd3))
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &cmd4))
require.Nil(t, sqlStore.CreateAlertNotificationCommand(context.Background(), &otherOrg))
t.Run("search", func(t *testing.T) {
query := &models.GetAlertNotificationsWithUidToSendQuery{
@ -326,7 +326,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
OrgId: 1,
}
err := sqlStore.GetAlertNotificationsWithUidToSend(query)
err := sqlStore.GetAlertNotificationsWithUidToSend(context.Background(), query)
require.Nil(t, err)
require.Equal(t, 3, len(query.Result))
})
@ -336,7 +336,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
OrgId: 1,
}
err := sqlStore.GetAllAlertNotifications(query)
err := sqlStore.GetAllAlertNotifications(context.Background(), query)
require.Nil(t, err)
require.Equal(t, 4, len(query.Result))
require.Equal(t, cmd4.Name, query.Result[0].Name)
@ -351,7 +351,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
ss := InitTestDB(t)
notification := &models.CreateAlertNotificationCommand{Uid: "aNotificationUid", OrgId: 1, Name: "aNotificationUid"}
err := sqlStore.CreateAlertNotificationCommand(notification)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), notification)
require.Nil(t, err)
byUidQuery := &models.GetAlertNotificationsWithUidQuery{
@ -359,7 +359,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
OrgId: notification.OrgId,
}
notificationByUidErr := sqlStore.GetAlertNotificationsWithUid(byUidQuery)
notificationByUidErr := sqlStore.GetAlertNotificationsWithUid(context.Background(), byUidQuery)
require.Nil(t, notificationByUidErr)
t.Run("Can cache notification Uid", func(t *testing.T) {
@ -374,7 +374,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
require.False(t, foundBeforeCaching)
require.Nil(t, resultBeforeCaching)
notificationByIdErr := ss.GetAlertNotificationUidWithId(byIdQuery)
notificationByIdErr := ss.GetAlertNotificationUidWithId(context.Background(), byIdQuery)
require.Nil(t, notificationByIdErr)
resultAfterCaching, foundAfterCaching := ss.CacheService.Get(cacheKey)
@ -390,7 +390,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
cacheKey := newAlertNotificationUidCacheKey(query.OrgId, query.Id)
ss.CacheService.Set(cacheKey, "a-cached-uid", -1)
err := ss.GetAlertNotificationUidWithId(query)
err := ss.GetAlertNotificationUidWithId(context.Background(), query)
require.Nil(t, err)
require.Equal(t, "a-cached-uid", query.Result)
})
@ -401,7 +401,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
OrgId: 100,
}
err := ss.GetAlertNotificationUidWithId(query)
err := ss.GetAlertNotificationUidWithId(context.Background(), query)
require.Equal(t, "", query.Result)
require.Error(t, err)
require.True(t, errors.Is(err, models.ErrAlertNotificationFailedTranslateUniqueID))
@ -425,7 +425,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Settings: simplejson.New(),
Id: 1,
}
err := sqlStore.UpdateAlertNotification(updateCmd)
err := sqlStore.UpdateAlertNotification(context.Background(), updateCmd)
require.Equal(t, models.ErrAlertNotificationNotFound, err)
t.Run("using UID", func(t *testing.T) {
@ -440,7 +440,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Uid: "uid",
NewUid: "newUid",
}
err := sqlStore.UpdateAlertNotificationWithUid(updateWithUidCmd)
err := sqlStore.UpdateAlertNotificationWithUid(context.Background(), updateWithUidCmd)
require.Equal(t, models.ErrAlertNotificationNotFound, err)
})
})
@ -455,18 +455,18 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Settings: simplejson.New(),
}
err := sqlStore.CreateAlertNotificationCommand(cmd)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
require.Nil(t, err)
deleteCmd := &models.DeleteAlertNotificationCommand{
Id: cmd.Result.Id,
OrgId: 1,
}
err = sqlStore.DeleteAlertNotification(deleteCmd)
err = sqlStore.DeleteAlertNotification(context.Background(), deleteCmd)
require.Nil(t, err)
t.Run("using UID", func(t *testing.T) {
err := sqlStore.CreateAlertNotificationCommand(cmd)
err := sqlStore.CreateAlertNotificationCommand(context.Background(), cmd)
require.Nil(t, err)
deleteWithUidCmd := &models.DeleteAlertNotificationWithUidCommand{
@ -474,7 +474,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
OrgId: 1,
}
err = sqlStore.DeleteAlertNotificationWithUid(deleteWithUidCmd)
err = sqlStore.DeleteAlertNotificationWithUid(context.Background(), deleteWithUidCmd)
require.Nil(t, err)
require.Equal(t, cmd.Result.Id, deleteWithUidCmd.DeletedAlertNotificationId)
})
@ -486,7 +486,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Id: 1,
OrgId: 1,
}
err := sqlStore.DeleteAlertNotification(deleteCmd)
err := sqlStore.DeleteAlertNotification(context.Background(), deleteCmd)
require.Equal(t, models.ErrAlertNotificationNotFound, err)
t.Run("using UID", func(t *testing.T) {
@ -494,7 +494,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Uid: "uid",
OrgId: 1,
}
err = sqlStore.DeleteAlertNotificationWithUid(deleteWithUidCmd)
err = sqlStore.DeleteAlertNotificationWithUid(context.Background(), deleteWithUidCmd)
require.Equal(t, models.ErrAlertNotificationNotFound, err)
})
})