add context in the alert_notification (#41307)

This commit is contained in:
ying-jeanne
2021-11-05 16:41:24 +08:00
committed by GitHub
parent c19d628ab6
commit a404a311da
10 changed files with 146 additions and 144 deletions
+17 -17
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)
}