chore: move alert-related models (#61716)

* chore: move alert notification models into the alerting service (alerting/models)
This commit is contained in:
Kristin Laemmert
2023-01-23 08:19:25 -05:00
committed by GitHub
parent 2b0de82aa9
commit 40feee0d17
76 changed files with 277 additions and 270 deletions
+42 -41
View File
@@ -11,6 +11,7 @@ import (
"github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/guardian" "github.com/grafana/grafana/pkg/services/guardian"
@@ -28,7 +29,7 @@ func (hs *HTTPServer) ValidateOrgAlert(c *models.ReqContext) {
c.JsonApiErr(http.StatusBadRequest, "alertId is invalid", nil) c.JsonApiErr(http.StatusBadRequest, "alertId is invalid", nil)
return return
} }
query := models.GetAlertByIdQuery{Id: id} query := alertmodels.GetAlertByIdQuery{Id: id}
if err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query); err != nil { if err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query); err != nil {
c.JsonApiErr(404, "Alert not found", nil) c.JsonApiErr(404, "Alert not found", nil)
@@ -57,7 +58,7 @@ func (hs *HTTPServer) GetAlertStatesForDashboard(c *models.ReqContext) response.
return response.Error(400, "Missing query parameter dashboardId", nil) return response.Error(400, "Missing query parameter dashboardId", nil)
} }
query := models.GetAlertStatesForDashboardQuery{ query := alertmodels.GetAlertStatesForDashboardQuery{
OrgId: c.OrgID, OrgId: c.OrgID,
DashboardId: c.QueryInt64("dashboardId"), DashboardId: c.QueryInt64("dashboardId"),
} }
@@ -125,11 +126,11 @@ func (hs *HTTPServer) GetAlerts(c *models.ReqContext) response.Response {
// if we didn't find any dashboards, return empty result // if we didn't find any dashboards, return empty result
if len(dashboardIDs) == 0 { if len(dashboardIDs) == 0 {
return response.JSON(http.StatusOK, []*models.AlertListItemDTO{}) return response.JSON(http.StatusOK, []*alertmodels.AlertListItemDTO{})
} }
} }
query := models.GetAlertsQuery{ query := alertmodels.GetAlertsQuery{
OrgId: c.OrgID, OrgId: c.OrgID,
DashboardIDs: dashboardIDs, DashboardIDs: dashboardIDs,
PanelId: c.QueryInt64("panelId"), PanelId: c.QueryInt64("panelId"),
@@ -223,7 +224,7 @@ func (hs *HTTPServer) GetAlert(c *models.ReqContext) response.Response {
if err != nil { if err != nil {
return response.Error(http.StatusBadRequest, "alertId is invalid", err) return response.Error(http.StatusBadRequest, "alertId is invalid", err)
} }
query := models.GetAlertByIdQuery{Id: id} query := alertmodels.GetAlertByIdQuery{Id: id}
if err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query); err != nil { if err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query); err != nil {
return response.Error(500, "List alerts failed", err) return response.Error(500, "List alerts failed", err)
@@ -295,8 +296,8 @@ func (hs *HTTPServer) GetAlertNotifications(c *models.ReqContext) response.Respo
return response.JSON(http.StatusOK, result) return response.JSON(http.StatusOK, result)
} }
func (hs *HTTPServer) getAlertNotificationsInternal(c *models.ReqContext) ([]*models.AlertNotification, error) { func (hs *HTTPServer) getAlertNotificationsInternal(c *models.ReqContext) ([]*alertmodels.AlertNotification, error) {
query := &models.GetAllAlertNotificationsQuery{OrgId: c.OrgID} query := &alertmodels.GetAllAlertNotificationsQuery{OrgId: c.OrgID}
if err := hs.AlertNotificationService.GetAllAlertNotifications(c.Req.Context(), query); err != nil { if err := hs.AlertNotificationService.GetAllAlertNotifications(c.Req.Context(), query); err != nil {
return nil, err return nil, err
@@ -322,7 +323,7 @@ func (hs *HTTPServer) GetAlertNotificationByID(c *models.ReqContext) response.Re
if err != nil { if err != nil {
return response.Error(http.StatusBadRequest, "notificationId is invalid", err) return response.Error(http.StatusBadRequest, "notificationId is invalid", err)
} }
query := &models.GetAlertNotificationsQuery{ query := &alertmodels.GetAlertNotificationsQuery{
OrgId: c.OrgID, OrgId: c.OrgID,
Id: notificationId, Id: notificationId,
} }
@@ -355,7 +356,7 @@ func (hs *HTTPServer) GetAlertNotificationByID(c *models.ReqContext) response.Re
// 404: notFoundError // 404: notFoundError
// 500: internalServerError // 500: internalServerError
func (hs *HTTPServer) GetAlertNotificationByUID(c *models.ReqContext) response.Response { func (hs *HTTPServer) GetAlertNotificationByUID(c *models.ReqContext) response.Response {
query := &models.GetAlertNotificationsWithUidQuery{ query := &alertmodels.GetAlertNotificationsWithUidQuery{
OrgId: c.OrgID, OrgId: c.OrgID,
Uid: web.Params(c.Req)[":uid"], Uid: web.Params(c.Req)[":uid"],
} }
@@ -388,14 +389,14 @@ func (hs *HTTPServer) GetAlertNotificationByUID(c *models.ReqContext) response.R
// 409: conflictError // 409: conflictError
// 500: internalServerError // 500: internalServerError
func (hs *HTTPServer) CreateAlertNotification(c *models.ReqContext) response.Response { func (hs *HTTPServer) CreateAlertNotification(c *models.ReqContext) response.Response {
cmd := models.CreateAlertNotificationCommand{} cmd := alertmodels.CreateAlertNotificationCommand{}
if err := web.Bind(c.Req, &cmd); err != nil { if err := web.Bind(c.Req, &cmd); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err) return response.Error(http.StatusBadRequest, "bad request data", err)
} }
cmd.OrgId = c.OrgID cmd.OrgId = c.OrgID
if err := hs.AlertNotificationService.CreateAlertNotificationCommand(c.Req.Context(), &cmd); err != nil { if err := hs.AlertNotificationService.CreateAlertNotificationCommand(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationWithSameNameExists) || errors.Is(err, models.ErrAlertNotificationWithSameUIDExists) { if errors.Is(err, alertmodels.ErrAlertNotificationWithSameNameExists) || errors.Is(err, alertmodels.ErrAlertNotificationWithSameUIDExists) {
return response.Error(409, "Failed to create alert notification", err) return response.Error(409, "Failed to create alert notification", err)
} }
var alertingErr alerting.ValidationError var alertingErr alerting.ValidationError
@@ -421,7 +422,7 @@ func (hs *HTTPServer) CreateAlertNotification(c *models.ReqContext) response.Res
// 404: notFoundError // 404: notFoundError
// 500: internalServerError // 500: internalServerError
func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Response { func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Response {
cmd := models.UpdateAlertNotificationCommand{} cmd := alertmodels.UpdateAlertNotificationCommand{}
if err := web.Bind(c.Req, &cmd); err != nil { if err := web.Bind(c.Req, &cmd); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err) return response.Error(http.StatusBadRequest, "bad request data", err)
} }
@@ -433,7 +434,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Res
} }
if err := hs.AlertNotificationService.UpdateAlertNotification(c.Req.Context(), &cmd); err != nil { if err := hs.AlertNotificationService.UpdateAlertNotification(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) { if errors.Is(err, alertmodels.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), err) return response.Error(404, err.Error(), err)
} }
var alertingErr alerting.ValidationError var alertingErr alerting.ValidationError
@@ -443,7 +444,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Res
return response.Error(500, "Failed to update alert notification", err) return response.Error(500, "Failed to update alert notification", err)
} }
query := models.GetAlertNotificationsQuery{ query := alertmodels.GetAlertNotificationsQuery{
OrgId: c.OrgID, OrgId: c.OrgID,
Id: cmd.Id, Id: cmd.Id,
} }
@@ -468,7 +469,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Res
// 404: notFoundError // 404: notFoundError
// 500: internalServerError // 500: internalServerError
func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) response.Response { func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) response.Response {
cmd := models.UpdateAlertNotificationWithUidCommand{} cmd := alertmodels.UpdateAlertNotificationWithUidCommand{}
if err := web.Bind(c.Req, &cmd); err != nil { if err := web.Bind(c.Req, &cmd); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err) return response.Error(http.StatusBadRequest, "bad request data", err)
} }
@@ -481,13 +482,13 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) respons
} }
if err := hs.AlertNotificationService.UpdateAlertNotificationWithUid(c.Req.Context(), &cmd); err != nil { if err := hs.AlertNotificationService.UpdateAlertNotificationWithUid(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) { if errors.Is(err, alertmodels.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), nil) return response.Error(404, err.Error(), nil)
} }
return response.Error(500, "Failed to update alert notification", err) return response.Error(500, "Failed to update alert notification", err)
} }
query := models.GetAlertNotificationsWithUidQuery{ query := alertmodels.GetAlertNotificationsWithUidQuery{
OrgId: cmd.OrgId, OrgId: cmd.OrgId,
Uid: cmd.Uid, Uid: cmd.Uid,
} }
@@ -499,12 +500,12 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) respons
return response.JSON(http.StatusOK, dtos.NewAlertNotification(query.Result)) return response.JSON(http.StatusOK, dtos.NewAlertNotification(query.Result))
} }
func (hs *HTTPServer) fillWithSecureSettingsData(ctx context.Context, cmd *models.UpdateAlertNotificationCommand) error { func (hs *HTTPServer) fillWithSecureSettingsData(ctx context.Context, cmd *alertmodels.UpdateAlertNotificationCommand) error {
if len(cmd.SecureSettings) == 0 { if len(cmd.SecureSettings) == 0 {
return nil return nil
} }
query := &models.GetAlertNotificationsQuery{ query := &alertmodels.GetAlertNotificationsQuery{
OrgId: cmd.OrgId, OrgId: cmd.OrgId,
Id: cmd.Id, Id: cmd.Id,
} }
@@ -527,12 +528,12 @@ func (hs *HTTPServer) fillWithSecureSettingsData(ctx context.Context, cmd *model
return nil return nil
} }
func (hs *HTTPServer) fillWithSecureSettingsDataByUID(ctx context.Context, cmd *models.UpdateAlertNotificationWithUidCommand) error { func (hs *HTTPServer) fillWithSecureSettingsDataByUID(ctx context.Context, cmd *alertmodels.UpdateAlertNotificationWithUidCommand) error {
if len(cmd.SecureSettings) == 0 { if len(cmd.SecureSettings) == 0 {
return nil return nil
} }
query := &models.GetAlertNotificationsWithUidQuery{ query := &alertmodels.GetAlertNotificationsWithUidQuery{
OrgId: cmd.OrgId, OrgId: cmd.OrgId,
Uid: cmd.Uid, Uid: cmd.Uid,
} }
@@ -573,13 +574,13 @@ func (hs *HTTPServer) DeleteAlertNotification(c *models.ReqContext) response.Res
return response.Error(http.StatusBadRequest, "notificationId is invalid", err) return response.Error(http.StatusBadRequest, "notificationId is invalid", err)
} }
cmd := models.DeleteAlertNotificationCommand{ cmd := alertmodels.DeleteAlertNotificationCommand{
OrgId: c.OrgID, OrgId: c.OrgID,
Id: notificationId, Id: notificationId,
} }
if err := hs.AlertNotificationService.DeleteAlertNotification(c.Req.Context(), &cmd); err != nil { if err := hs.AlertNotificationService.DeleteAlertNotification(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) { if errors.Is(err, alertmodels.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), nil) return response.Error(404, err.Error(), nil)
} }
return response.Error(500, "Failed to delete alert notification", err) return response.Error(500, "Failed to delete alert notification", err)
@@ -601,13 +602,13 @@ func (hs *HTTPServer) DeleteAlertNotification(c *models.ReqContext) response.Res
// 404: notFoundError // 404: notFoundError
// 500: internalServerError // 500: internalServerError
func (hs *HTTPServer) DeleteAlertNotificationByUID(c *models.ReqContext) response.Response { func (hs *HTTPServer) DeleteAlertNotificationByUID(c *models.ReqContext) response.Response {
cmd := models.DeleteAlertNotificationWithUidCommand{ cmd := alertmodels.DeleteAlertNotificationWithUidCommand{
OrgId: c.OrgID, OrgId: c.OrgID,
Uid: web.Params(c.Req)[":uid"], Uid: web.Params(c.Req)[":uid"],
} }
if err := hs.AlertNotificationService.DeleteAlertNotificationWithUid(c.Req.Context(), &cmd); err != nil { if err := hs.AlertNotificationService.DeleteAlertNotificationWithUid(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) { if errors.Is(err, alertmodels.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), nil) return response.Error(404, err.Error(), nil)
} }
return response.Error(500, "Failed to delete alert notification", err) return response.Error(500, "Failed to delete alert notification", err)
@@ -690,7 +691,7 @@ func (hs *HTTPServer) PauseAlert(legacyAlertingEnabled *bool) func(c *models.Req
result := make(map[string]interface{}) result := make(map[string]interface{})
result["alertId"] = alertID result["alertId"] = alertID
query := models.GetAlertByIdQuery{Id: alertID} query := alertmodels.GetAlertByIdQuery{Id: alertID}
if err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query); err != nil { if err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query); err != nil {
return response.Error(500, "Get Alert failed", err) return response.Error(500, "Get Alert failed", err)
} }
@@ -708,17 +709,17 @@ func (hs *HTTPServer) PauseAlert(legacyAlertingEnabled *bool) func(c *models.Req
} }
// Alert state validation // Alert state validation
if query.Result.State != models.AlertStatePaused && !dto.Paused { if query.Result.State != alertmodels.AlertStatePaused && !dto.Paused {
result["state"] = "un-paused" result["state"] = "un-paused"
result["message"] = "Alert is already un-paused" result["message"] = "Alert is already un-paused"
return response.JSON(http.StatusOK, result) return response.JSON(http.StatusOK, result)
} else if query.Result.State == models.AlertStatePaused && dto.Paused { } else if query.Result.State == alertmodels.AlertStatePaused && dto.Paused {
result["state"] = models.AlertStatePaused result["state"] = alertmodels.AlertStatePaused
result["message"] = "Alert is already paused" result["message"] = "Alert is already paused"
return response.JSON(http.StatusOK, result) return response.JSON(http.StatusOK, result)
} }
cmd := models.PauseAlertCommand{ cmd := alertmodels.PauseAlertCommand{
OrgId: c.OrgID, OrgId: c.OrgID,
AlertIds: []int64{alertID}, AlertIds: []int64{alertID},
Paused: dto.Paused, Paused: dto.Paused,
@@ -728,10 +729,10 @@ func (hs *HTTPServer) PauseAlert(legacyAlertingEnabled *bool) func(c *models.Req
return response.Error(500, "", err) return response.Error(500, "", err)
} }
resp := models.AlertStateUnknown resp := alertmodels.AlertStateUnknown
pausedState := "un-paused" pausedState := "un-paused"
if cmd.Paused { if cmd.Paused {
resp = models.AlertStatePaused resp = alertmodels.AlertStatePaused
pausedState = "paused" pausedState = "paused"
} }
@@ -765,7 +766,7 @@ func (hs *HTTPServer) PauseAllAlerts(legacyAlertingEnabled *bool) func(c *models
if err := web.Bind(c.Req, &dto); err != nil { if err := web.Bind(c.Req, &dto); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err) return response.Error(http.StatusBadRequest, "bad request data", err)
} }
updateCmd := models.PauseAllAlertCommand{ updateCmd := alertmodels.PauseAllAlertCommand{
Paused: dto.Paused, Paused: dto.Paused,
} }
@@ -773,10 +774,10 @@ func (hs *HTTPServer) PauseAllAlerts(legacyAlertingEnabled *bool) func(c *models
return response.Error(500, "Failed to pause alerts", err) return response.Error(500, "Failed to pause alerts", err)
} }
resp := models.AlertStatePending resp := alertmodels.AlertStatePending
pausedState := "un paused" pausedState := "un paused"
if updateCmd.Paused { if updateCmd.Paused {
resp = models.AlertStatePaused resp = alertmodels.AlertStatePaused
pausedState = "paused" pausedState = "paused"
} }
@@ -836,14 +837,14 @@ type NotificationChannelTestParams struct {
type CreateAlertNotificationChannelParams struct { type CreateAlertNotificationChannelParams struct {
// in:body // in:body
// required:true // required:true
Body models.CreateAlertNotificationCommand `json:"body"` Body alertmodels.CreateAlertNotificationCommand `json:"body"`
} }
// swagger:parameters updateAlertNotificationChannel // swagger:parameters updateAlertNotificationChannel
type UpdateAlertNotificationChannelParams struct { type UpdateAlertNotificationChannelParams struct {
// in:body // in:body
// required:true // required:true
Body models.UpdateAlertNotificationCommand `json:"body"` Body alertmodels.UpdateAlertNotificationCommand `json:"body"`
// in:path // in:path
// required:true // required:true
NotificationID int64 `json:"notification_channel_id"` NotificationID int64 `json:"notification_channel_id"`
@@ -853,7 +854,7 @@ type UpdateAlertNotificationChannelParams struct {
type UpdateAlertNotificationChannelByUIDParams struct { type UpdateAlertNotificationChannelByUIDParams struct {
// in:body // in:body
// required:true // required:true
Body models.UpdateAlertNotificationWithUidCommand `json:"body"` Body alertmodels.UpdateAlertNotificationWithUidCommand `json:"body"`
// in:path // in:path
// required:true // required:true
NotificationUID string `json:"notification_channel_uid"` NotificationUID string `json:"notification_channel_uid"`
@@ -997,14 +998,14 @@ type SMTPNotEnabledError PreconditionFailedError
type GetAlertsResponse struct { type GetAlertsResponse struct {
// The response message // The response message
// in: body // in: body
Body []*models.AlertListItemDTO `json:"body"` Body []*alertmodels.AlertListItemDTO `json:"body"`
} }
// swagger:response getAlertResponse // swagger:response getAlertResponse
type GetAlertResponse struct { type GetAlertResponse struct {
// The response message // The response message
// in: body // in: body
Body *models.Alert `json:"body"` Body *alertmodels.Alert `json:"body"`
} }
// swagger:response pauseAlertResponse // swagger:response pauseAlertResponse
@@ -1032,5 +1033,5 @@ type TestAlertResponse struct {
type GetDashboardStatesResponse struct { type GetDashboardStatesResponse struct {
// The response message // The response message
// in: body // in: body
Body []*models.AlertStateInfoDTO `json:"body"` Body []*alertmodels.AlertStateInfoDTO `json:"body"`
} }
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"github.com/grafana/grafana/pkg/components/null" "github.com/grafana/grafana/pkg/components/null"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
) )
func formatShort(interval time.Duration) string { func formatShort(interval time.Duration) string {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
) )
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
fd "github.com/grafana/grafana/pkg/services/datasources/fakes" fd "github.com/grafana/grafana/pkg/services/datasources/fakes"
) )
+3 -2
View File
@@ -7,11 +7,13 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/infra/tracing" "github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/infra/usagestats" "github.com/grafana/grafana/pkg/infra/usagestats"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
@@ -19,7 +21,6 @@ import (
encryptionprovider "github.com/grafana/grafana/pkg/services/encryption/provider" encryptionprovider "github.com/grafana/grafana/pkg/services/encryption/provider"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/require"
) )
type FakeEvalHandler struct { type FakeEvalHandler struct {
+18 -17
View File
@@ -8,6 +8,7 @@ import (
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations" "github.com/grafana/grafana/pkg/services/annotations"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
@@ -34,7 +35,7 @@ type EvalContext struct {
ImagePublicURL string ImagePublicURL string
ImageOnDiskPath string ImageOnDiskPath string
NoDataFound bool NoDataFound bool
PrevAlertState models.AlertStateType PrevAlertState alertmodels.AlertStateType
RequestValidator models.PluginRequestValidator RequestValidator models.PluginRequestValidator
@@ -76,22 +77,22 @@ type StateDescription struct {
// GetStateModel returns the `StateDescription` based on current state. // GetStateModel returns the `StateDescription` based on current state.
func (c *EvalContext) GetStateModel() *StateDescription { func (c *EvalContext) GetStateModel() *StateDescription {
switch c.Rule.State { switch c.Rule.State {
case models.AlertStateOK: case alertmodels.AlertStateOK:
return &StateDescription{ return &StateDescription{
Color: "#36a64f", Color: "#36a64f",
Text: "OK", Text: "OK",
} }
case models.AlertStateNoData: case alertmodels.AlertStateNoData:
return &StateDescription{ return &StateDescription{
Color: "#888888", Color: "#888888",
Text: "No Data", Text: "No Data",
} }
case models.AlertStateAlerting: case alertmodels.AlertStateAlerting:
return &StateDescription{ return &StateDescription{
Color: "#D63232", Color: "#D63232",
Text: "Alerting", Text: "Alerting",
} }
case models.AlertStateUnknown: case alertmodels.AlertStateUnknown:
return &StateDescription{ return &StateDescription{
Color: "#888888", Color: "#888888",
Text: "Unknown", Text: "Unknown",
@@ -146,25 +147,25 @@ func (c *EvalContext) GetRuleURL() (string, error) {
} }
// GetNewState returns the new state from the alert rule evaluation. // GetNewState returns the new state from the alert rule evaluation.
func (c *EvalContext) GetNewState() models.AlertStateType { func (c *EvalContext) GetNewState() alertmodels.AlertStateType {
ns := getNewStateInternal(c) ns := getNewStateInternal(c)
if ns != models.AlertStateAlerting || c.Rule.For == 0 { if ns != alertmodels.AlertStateAlerting || c.Rule.For == 0 {
return ns return ns
} }
since := time.Since(c.Rule.LastStateChange) since := time.Since(c.Rule.LastStateChange)
if c.PrevAlertState == models.AlertStatePending && since > c.Rule.For { if c.PrevAlertState == alertmodels.AlertStatePending && since > c.Rule.For {
return models.AlertStateAlerting return alertmodels.AlertStateAlerting
} }
if c.PrevAlertState == models.AlertStateAlerting { if c.PrevAlertState == alertmodels.AlertStateAlerting {
return models.AlertStateAlerting return alertmodels.AlertStateAlerting
} }
return models.AlertStatePending return alertmodels.AlertStatePending
} }
func getNewStateInternal(c *EvalContext) models.AlertStateType { func getNewStateInternal(c *EvalContext) alertmodels.AlertStateType {
if c.Error != nil { if c.Error != nil {
c.Log.Error("Alert Rule Result Error", c.Log.Error("Alert Rule Result Error",
"ruleId", c.Rule.ID, "ruleId", c.Rule.ID,
@@ -172,14 +173,14 @@ func getNewStateInternal(c *EvalContext) models.AlertStateType {
"error", c.Error, "error", c.Error,
"changing state to", c.Rule.ExecutionErrorState.ToAlertState()) "changing state to", c.Rule.ExecutionErrorState.ToAlertState())
if c.Rule.ExecutionErrorState == models.ExecutionErrorKeepState { if c.Rule.ExecutionErrorState == alertmodels.ExecutionErrorKeepState {
return c.PrevAlertState return c.PrevAlertState
} }
return c.Rule.ExecutionErrorState.ToAlertState() return c.Rule.ExecutionErrorState.ToAlertState()
} }
if c.Firing { if c.Firing {
return models.AlertStateAlerting return alertmodels.AlertStateAlerting
} }
if c.NoDataFound { if c.NoDataFound {
@@ -188,13 +189,13 @@ func getNewStateInternal(c *EvalContext) models.AlertStateType {
"name", c.Rule.Name, "name", c.Rule.Name,
"changing state to", c.Rule.NoDataState.ToAlertState()) "changing state to", c.Rule.NoDataState.ToAlertState())
if c.Rule.NoDataState == models.NoDataKeepState { if c.Rule.NoDataState == alertmodels.NoDataKeepState {
return c.PrevAlertState return c.PrevAlertState
} }
return c.Rule.NoDataState.ToAlertState() return c.Rule.NoDataState.ToAlertState()
} }
return models.AlertStateOK return alertmodels.AlertStateOK
} }
// evaluateNotificationTemplateFields will treat the alert evaluation rule's name and message fields as // evaluateNotificationTemplateFields will treat the alert evaluation rule's name and message fields as
+2 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
"github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/services/validations"
) )
@@ -93,7 +93,7 @@ func TestGetStateFromEvalContext(t *testing.T) {
name: "alerting -> alerting. should not update regardless of FOR", name: "alerting -> alerting. should not update regardless of FOR",
expected: models.AlertStateAlerting, expected: models.AlertStateAlerting,
applyFn: func(ec *EvalContext) { applyFn: func(ec *EvalContext) {
ec.PrevAlertState = models.AlertStateAlerting ec.PrevAlertState = models.AlertStatePending
ec.Firing = true ec.Firing = true
ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 5) ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 5)
ec.Rule.For = time.Minute * 2 ec.Rule.For = time.Minute * 2
+5 -5
View File
@@ -8,7 +8,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/datasources/permissions" "github.com/grafana/grafana/pkg/services/datasources/permissions"
) )
@@ -107,7 +107,7 @@ func UAEnabled(ctx context.Context) bool {
} }
func (e *DashAlertExtractorService) getAlertFromPanels(ctx context.Context, jsonWithPanels *simplejson.Json, validateAlertFunc func(*models.Alert) bool, logTranslationFailures bool, dashAlertInfo DashAlertInfo) ([]*models.Alert, error) { func (e *DashAlertExtractorService) getAlertFromPanels(ctx context.Context, jsonWithPanels *simplejson.Json, validateAlertFunc func(*models.Alert) bool, logTranslationFailures bool, dashAlertInfo DashAlertInfo) ([]*models.Alert, error) {
alerts := make([]*models.Alert, 0) ret := make([]*models.Alert, 0)
for _, panelObj := range jsonWithPanels.Get("panels").MustArray() { for _, panelObj := range jsonWithPanels.Get("panels").MustArray() {
panel := simplejson.NewFromAny(panelObj) panel := simplejson.NewFromAny(panelObj)
@@ -121,7 +121,7 @@ func (e *DashAlertExtractorService) getAlertFromPanels(ctx context.Context, json
return nil, err return nil, err
} }
alerts = append(alerts, alertSlice...) ret = append(ret, alertSlice...)
continue continue
} }
@@ -242,10 +242,10 @@ func (e *DashAlertExtractorService) getAlertFromPanels(ctx context.Context, json
return nil, ValidationError{Reason: fmt.Sprintf("Panel id is not correct, alertName=%v, panelId=%v", alert.Name, alert.PanelId)} return nil, ValidationError{Reason: fmt.Sprintf("Panel id is not correct, alertName=%v, panelId=%v", alert.Name, alert.PanelId)}
} }
alerts = append(alerts, alert) ret = append(ret, alert)
} }
return alerts, nil return ret, nil
} }
func validateAlertRule(alert *models.Alert) bool { func validateAlertRule(alert *models.Alert) bool {
+1 -1
View File
@@ -13,7 +13,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/db/dbtest" "github.com/grafana/grafana/pkg/infra/db/dbtest"
"github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/datasources/permissions" "github.com/grafana/grafana/pkg/services/datasources/permissions"
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"context" "context"
"time" "time"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/tsdb/legacydata" "github.com/grafana/grafana/pkg/tsdb/legacydata"
) )
@@ -3,10 +3,11 @@ package models
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/tag"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/tag"
) )
func TestAlert_ContainsUpdates(t *testing.T) { func TestAlert_ContainsUpdates(t *testing.T) {
+8 -7
View File
@@ -10,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/rendering" "github.com/grafana/grafana/pkg/services/rendering"
@@ -154,7 +155,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
return nil return nil
} }
cmd := &models.SetAlertNotificationStateToCompleteCommand{ cmd := &alertmodels.SetAlertNotificationStateToCompleteCommand{
Id: notifierState.state.Id, Id: notifierState.state.Id,
Version: notifierState.state.Version, Version: notifierState.state.Version,
} }
@@ -164,7 +165,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error { func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error {
if !evalContext.IsTestRun { if !evalContext.IsTestRun {
setPendingCmd := &models.SetAlertNotificationStateToPendingCommand{ setPendingCmd := &alertmodels.SetAlertNotificationStateToPendingCommand{
Id: notifierState.state.Id, Id: notifierState.state.Id,
Version: notifierState.state.Version, Version: notifierState.state.Version,
AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges, AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges,
@@ -172,7 +173,7 @@ func (n *notificationService) sendNotification(evalContext *EvalContext, notifie
err := n.sqlStore.SetAlertNotificationStateToPendingCommand(evalContext.Ctx, setPendingCmd) err := n.sqlStore.SetAlertNotificationStateToPendingCommand(evalContext.Ctx, setPendingCmd)
if err != nil { if err != nil {
if errors.Is(err, models.ErrAlertNotificationStateVersionConflict) { if errors.Is(err, alertmodels.ErrAlertNotificationStateVersionConflict) {
return nil return nil
} }
@@ -256,7 +257,7 @@ func (n *notificationService) renderAndUploadImage(evalCtx *EvalContext, timeout
} }
func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) { func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) {
query := &models.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids} query := &alertmodels.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids}
if err := n.sqlStore.GetAlertNotificationsWithUidToSend(evalContext.Ctx, query); err != nil { if err := n.sqlStore.GetAlertNotificationsWithUidToSend(evalContext.Ctx, query); err != nil {
return nil, err return nil, err
@@ -270,7 +271,7 @@ func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids [
continue continue
} }
query := &models.GetOrCreateNotificationStateQuery{ query := &alertmodels.GetOrCreateNotificationStateQuery{
NotifierId: notification.Id, NotifierId: notification.Id,
AlertId: evalContext.Rule.ID, AlertId: evalContext.Rule.ID,
OrgId: evalContext.Rule.OrgID, OrgId: evalContext.Rule.OrgID,
@@ -294,7 +295,7 @@ func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids [
} }
// InitNotifier instantiate a new notifier based on the model. // InitNotifier instantiate a new notifier based on the model.
func InitNotifier(model *models.AlertNotification, fn GetDecryptedValueFn, notificationService *notifications.NotificationService) (Notifier, error) { func InitNotifier(model *alertmodels.AlertNotification, fn GetDecryptedValueFn, notificationService *notifications.NotificationService) (Notifier, error) {
notifierPlugin, found := notifierFactories[model.Type] notifierPlugin, found := notifierFactories[model.Type]
if !found { if !found {
return nil, fmt.Errorf("unsupported notification type %q", model.Type) return nil, fmt.Errorf("unsupported notification type %q", model.Type)
@@ -308,7 +309,7 @@ func InitNotifier(model *models.AlertNotification, fn GetDecryptedValueFn, notif
type GetDecryptedValueFn func(ctx context.Context, sjd map[string][]byte, key string, fallback string, secret string) string type GetDecryptedValueFn func(ctx context.Context, sjd map[string][]byte, key string, fallback string, secret string) string
// NotifierFactory is a signature for creating notifiers. // NotifierFactory is a signature for creating notifiers.
type NotifierFactory func(*models.AlertNotification, GetDecryptedValueFn, notifications.Service) (Notifier, error) type NotifierFactory func(*alertmodels.AlertNotification, GetDecryptedValueFn, notifications.Service) (Notifier, error)
var notifierFactories = make(map[string]*NotifierPlugin) var notifierFactories = make(map[string]*NotifierPlugin)
+8 -7
View File
@@ -11,6 +11,7 @@ import (
"github.com/grafana/grafana/pkg/components/imguploader" "github.com/grafana/grafana/pkg/components/imguploader"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
@@ -181,8 +182,8 @@ func notificationServiceScenario(t *testing.T, name string, evalCtx *EvalContext
store := evalCtx.Store.(*AlertStoreMock) store := evalCtx.Store.(*AlertStoreMock)
store.getAlertNotificationsWithUidToSend = func(ctx context.Context, query *models.GetAlertNotificationsWithUidToSendQuery) error { store.getAlertNotificationsWithUidToSend = func(ctx context.Context, query *alertmodels.GetAlertNotificationsWithUidToSendQuery) error {
query.Result = []*models.AlertNotification{ query.Result = []*alertmodels.AlertNotification{
{ {
Id: 1, Id: 1,
Type: "test", Type: "test",
@@ -194,13 +195,13 @@ func notificationServiceScenario(t *testing.T, name string, evalCtx *EvalContext
return nil return nil
} }
store.getOrCreateNotificationState = func(ctx context.Context, query *models.GetOrCreateNotificationStateQuery) error { store.getOrCreateNotificationState = func(ctx context.Context, query *alertmodels.GetOrCreateNotificationStateQuery) error {
query.Result = &models.AlertNotificationState{ query.Result = &alertmodels.AlertNotificationState{
AlertId: evalCtx.Rule.ID, AlertId: evalCtx.Rule.ID,
AlertRuleStateUpdatedVersion: 1, AlertRuleStateUpdatedVersion: 1,
Id: 1, Id: 1,
OrgId: evalCtx.Rule.OrgID, OrgId: evalCtx.Rule.OrgID,
State: models.AlertNotificationStateUnknown, State: alertmodels.AlertNotificationStateUnknown,
} }
return nil return nil
} }
@@ -275,7 +276,7 @@ type testNotifier struct {
Frequency time.Duration Frequency time.Duration
} }
func newTestNotifier(model *models.AlertNotification, _ GetDecryptedValueFn, ns notifications.Service) (Notifier, error) { func newTestNotifier(model *alertmodels.AlertNotification, _ GetDecryptedValueFn, ns notifications.Service) (Notifier, error) {
uploadImage := true uploadImage := true
value, exist := model.Settings.CheckGet("uploadImage") value, exist := model.Settings.CheckGet("uploadImage")
if exist { if exist {
@@ -301,7 +302,7 @@ func (n *testNotifier) Notify(evalCtx *EvalContext) error {
return nil return nil
} }
func (n *testNotifier) ShouldNotify(ctx context.Context, evalCtx *EvalContext, notifierState *models.AlertNotificationState) bool { func (n *testNotifier) ShouldNotify(ctx context.Context, evalCtx *EvalContext, notifierState *alertmodels.AlertNotificationState) bool {
return true return true
} }
@@ -9,8 +9,8 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -93,7 +93,7 @@ func (am *AlertmanagerNotifier) ShouldNotify(ctx context.Context, evalContext *a
return false return false
} }
// Notify on Alerting -> OK to resolve before alertmanager timeout. // Notify on Alerting -> OK to resolve before alertmanager timeout.models.AlertStateOK
if (evalContext.PrevAlertState == models.AlertStateAlerting) && (evalContext.Rule.State == models.AlertStateOK) { if (evalContext.PrevAlertState == models.AlertStateAlerting) && (evalContext.Rule.State == models.AlertStateOK) {
return true return true
} }
@@ -4,16 +4,16 @@ import (
"context" "context"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/services/validations"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestReplaceIllegalCharswithUnderscore(t *testing.T) { func TestReplaceIllegalCharswithUnderscore(t *testing.T) {
+1 -1
View File
@@ -5,8 +5,8 @@ import (
"time" "time"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
) )
+6 -6
View File
@@ -5,14 +5,14 @@ import (
"testing" "testing"
"time" "time"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest"
"github.com/grafana/grafana/pkg/services/validations"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest"
"github.com/grafana/grafana/pkg/services/validations"
) )
func TestShouldSendAlertNotification(t *testing.T) { func TestShouldSendAlertNotification(t *testing.T) {
+1 -1
View File
@@ -6,8 +6,8 @@ import (
"net/url" "net/url"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
) )
@@ -4,14 +4,14 @@ import (
"context" "context"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/services/validations"
"github.com/stretchr/testify/require"
) )
func TestDingDingNotifier(t *testing.T) { func TestDingDingNotifier(t *testing.T) {
+1 -1
View File
@@ -11,8 +11,8 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -3,11 +3,11 @@ package notifiers
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
func TestDiscordNotifier(t *testing.T) { func TestDiscordNotifier(t *testing.T) {
+2 -3
View File
@@ -4,12 +4,11 @@ import (
"os" "os"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
) )
func init() { func init() {
@@ -3,11 +3,11 @@ package notifiers
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
func TestEmailNotifier(t *testing.T) { func TestEmailNotifier(t *testing.T) {
@@ -7,8 +7,8 @@ import (
"time" "time"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -3,11 +3,11 @@ package notifiers
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
func TestGoogleChatNotifier(t *testing.T) { func TestGoogleChatNotifier(t *testing.T) {
+2 -3
View File
@@ -2,14 +2,13 @@ package notifiers
import ( import (
"encoding/json" "encoding/json"
"fmt"
"strconv" "strconv"
"strings" "strings"
"fmt"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
) )
@@ -3,11 +3,11 @@ package notifiers
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
//nolint:goconst //nolint:goconst
+2 -3
View File
@@ -1,14 +1,13 @@
package notifiers package notifiers
import ( import (
"strconv"
"fmt" "fmt"
"strconv"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
) )
@@ -3,11 +3,11 @@ package notifiers
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
func TestKafkaNotifier(t *testing.T) { func TestKafkaNotifier(t *testing.T) {
+1 -1
View File
@@ -6,8 +6,8 @@ import (
"net/url" "net/url"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
+4 -4
View File
@@ -3,11 +3,11 @@ package notifiers
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
func TestLineNotifier(t *testing.T) { func TestLineNotifier(t *testing.T) {
+1 -1
View File
@@ -7,8 +7,8 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -6,16 +6,16 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/services/tag"
"github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/services/validations"
"github.com/stretchr/testify/require"
) )
func TestOpsGenieNotifier(t *testing.T) { func TestOpsGenieNotifier(t *testing.T) {
+1 -1
View File
@@ -9,8 +9,8 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -6,17 +6,16 @@ import (
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/null" "github.com/grafana/grafana/pkg/components/null"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/services/tag"
"github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/services/validations"
"github.com/stretchr/testify/require"
) )
func presenceComparer(a, b string) bool { func presenceComparer(a, b string) bool {
+2 -3
View File
@@ -9,12 +9,11 @@ import (
"os" "os"
"strconv" "strconv"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting"
) )
const pushoverEndpoint = "https://api.pushover.net/1/messages.json" const pushoverEndpoint = "https://api.pushover.net/1/messages.json"
@@ -5,14 +5,14 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/services/validations"
"github.com/stretchr/testify/require"
) )
func TestPushoverNotifier(t *testing.T) { func TestPushoverNotifier(t *testing.T) {
+1 -1
View File
@@ -7,8 +7,8 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -4,7 +4,7 @@ import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
+1 -1
View File
@@ -9,8 +9,8 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -3,12 +3,12 @@ package notifiers
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
func TestSensuGoNotifier(t *testing.T) { func TestSensuGoNotifier(t *testing.T) {
+1 -1
View File
@@ -17,8 +17,8 @@ import (
"time" "time"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -7,12 +7,13 @@ import (
"net/http/httptest" "net/http/httptest"
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/setting"
) )
func TestSlackNotifier(t *testing.T) { func TestSlackNotifier(t *testing.T) {
+1 -1
View File
@@ -4,8 +4,8 @@ import (
"encoding/json" "encoding/json"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
) )
@@ -3,11 +3,11 @@ package notifiers
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
func TestTeamsNotifier(t *testing.T) { func TestTeamsNotifier(t *testing.T) {
+1 -1
View File
@@ -9,8 +9,8 @@ import (
"os" "os"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -4,14 +4,14 @@ import (
"context" "context"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/services/validations"
"github.com/stretchr/testify/require"
) )
func TestTelegramNotifier(t *testing.T) { func TestTelegramNotifier(t *testing.T) {
+1 -1
View File
@@ -7,8 +7,8 @@ import (
"strings" "strings"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -4,12 +4,12 @@ import (
"errors" "errors"
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
func TestThreemaNotifier(t *testing.T) { func TestThreemaNotifier(t *testing.T) {
+1 -1
View File
@@ -6,8 +6,8 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -5,16 +5,15 @@ import (
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/services/tag"
"github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/services/validations"
"github.com/stretchr/testify/require"
) )
func presenceComparerInt(a, b int64) bool { func presenceComparerInt(a, b int64) bool {
+1 -1
View File
@@ -5,8 +5,8 @@ import (
"encoding/json" "encoding/json"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@@ -3,12 +3,12 @@ package notifiers
import ( import (
"testing" "testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/models"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
) )
func TestWebhookNotifier_parsingFromSettings(t *testing.T) { func TestWebhookNotifier_parsingFromSettings(t *testing.T) {
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
) )
type ruleReader interface { type ruleReader interface {
+1 -2
View File
@@ -8,8 +8,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations" "github.com/grafana/grafana/pkg/services/annotations"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/services/rendering" "github.com/grafana/grafana/pkg/services/rendering"
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"time" "time"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/services/tag"
) )
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/tsdb/legacydata" "github.com/grafana/grafana/pkg/tsdb/legacydata"
) )
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/encryption" "github.com/grafana/grafana/pkg/services/encryption"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
+1 -1
View File
@@ -13,7 +13,7 @@ import (
"github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/usagestats" "github.com/grafana/grafana/pkg/infra/usagestats"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
encryptionprovider "github.com/grafana/grafana/pkg/services/encryption/provider" encryptionprovider "github.com/grafana/grafana/pkg/services/encryption/provider"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
+40 -39
View File
@@ -10,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/services/tag"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
@@ -18,18 +19,18 @@ import (
// AlertStore is a subset of SQLStore API to satisfy the needs of the alerting service. // AlertStore is a subset of SQLStore API to satisfy the needs of the alerting service.
// A subset is needed to make it easier to mock during the tests. // A subset is needed to make it easier to mock during the tests.
type AlertStore interface { type AlertStore interface {
GetAlertById(context.Context, *models.GetAlertByIdQuery) error GetAlertById(context.Context, *alertmodels.GetAlertByIdQuery) error
GetAllAlertQueryHandler(context.Context, *models.GetAllAlertsQuery) error GetAllAlertQueryHandler(context.Context, *alertmodels.GetAllAlertsQuery) error
GetAlertStatesForDashboard(context.Context, *models.GetAlertStatesForDashboardQuery) error GetAlertStatesForDashboard(context.Context, *alertmodels.GetAlertStatesForDashboardQuery) error
HandleAlertsQuery(context.Context, *models.GetAlertsQuery) error HandleAlertsQuery(context.Context, *alertmodels.GetAlertsQuery) error
SetAlertNotificationStateToCompleteCommand(context.Context, *models.SetAlertNotificationStateToCompleteCommand) error SetAlertNotificationStateToCompleteCommand(context.Context, *alertmodels.SetAlertNotificationStateToCompleteCommand) error
SetAlertNotificationStateToPendingCommand(context.Context, *models.SetAlertNotificationStateToPendingCommand) error SetAlertNotificationStateToPendingCommand(context.Context, *alertmodels.SetAlertNotificationStateToPendingCommand) error
GetAlertNotificationUidWithId(context.Context, *models.GetAlertNotificationUidQuery) error GetAlertNotificationUidWithId(context.Context, *alertmodels.GetAlertNotificationUidQuery) error
GetAlertNotificationsWithUidToSend(context.Context, *models.GetAlertNotificationsWithUidToSendQuery) error GetAlertNotificationsWithUidToSend(context.Context, *alertmodels.GetAlertNotificationsWithUidToSendQuery) error
GetOrCreateAlertNotificationState(context.Context, *models.GetOrCreateNotificationStateQuery) error GetOrCreateAlertNotificationState(context.Context, *alertmodels.GetOrCreateNotificationStateQuery) error
SetAlertState(context.Context, *models.SetAlertStateCommand) error SetAlertState(context.Context, *alertmodels.SetAlertStateCommand) error
PauseAlert(context.Context, *models.PauseAlertCommand) error PauseAlert(context.Context, *alertmodels.PauseAlertCommand) error
PauseAllAlerts(context.Context, *models.PauseAllAlertCommand) error PauseAllAlerts(context.Context, *alertmodels.PauseAllAlertCommand) error
} }
type sqlStore struct { type sqlStore struct {
@@ -52,9 +53,9 @@ func ProvideAlertStore(
} }
} }
func (ss *sqlStore) GetAlertById(ctx context.Context, query *models.GetAlertByIdQuery) error { func (ss *sqlStore) GetAlertById(ctx context.Context, query *alertmodels.GetAlertByIdQuery) error {
return ss.db.WithDbSession(ctx, func(sess *db.Session) error { return ss.db.WithDbSession(ctx, func(sess *db.Session) error {
alert := models.Alert{} alert := alertmodels.Alert{}
has, err := sess.ID(query.Id).Get(&alert) has, err := sess.ID(query.Id).Get(&alert)
if !has { if !has {
return fmt.Errorf("could not find alert") return fmt.Errorf("could not find alert")
@@ -68,9 +69,9 @@ func (ss *sqlStore) GetAlertById(ctx context.Context, query *models.GetAlertById
}) })
} }
func (ss *sqlStore) GetAllAlertQueryHandler(ctx context.Context, query *models.GetAllAlertsQuery) error { func (ss *sqlStore) GetAllAlertQueryHandler(ctx context.Context, query *alertmodels.GetAllAlertsQuery) error {
return ss.db.WithDbSession(ctx, func(sess *db.Session) error { return ss.db.WithDbSession(ctx, func(sess *db.Session) error {
var alerts []*models.Alert var alerts []*alertmodels.Alert
err := sess.SQL("select * from alert").Find(&alerts) err := sess.SQL("select * from alert").Find(&alerts)
if err != nil { if err != nil {
return err return err
@@ -103,7 +104,7 @@ func deleteAlertByIdInternal(alertId int64, reason string, sess *db.Session, log
return nil return nil
} }
func (ss *sqlStore) HandleAlertsQuery(ctx context.Context, query *models.GetAlertsQuery) error { func (ss *sqlStore) HandleAlertsQuery(ctx context.Context, query *alertmodels.GetAlertsQuery) error {
return ss.db.WithDbSession(ctx, func(sess *db.Session) error { return ss.db.WithDbSession(ctx, func(sess *db.Session) error {
builder := db.NewSqlBuilder(ss.cfg, ss.db.GetDialect()) builder := db.NewSqlBuilder(ss.cfg, ss.db.GetDialect())
@@ -167,7 +168,7 @@ func (ss *sqlStore) HandleAlertsQuery(ctx context.Context, query *models.GetAler
builder.Write(ss.db.GetDialect().Limit(query.Limit)) builder.Write(ss.db.GetDialect().Limit(query.Limit))
} }
alerts := make([]*models.AlertListItemDTO, 0) alerts := make([]*alertmodels.AlertListItemDTO, 0)
if err := sess.SQL(builder.GetSQLString(), builder.GetParams()...).Find(&alerts); err != nil { if err := sess.SQL(builder.GetSQLString(), builder.GetParams()...).Find(&alerts); err != nil {
return err return err
} }
@@ -183,7 +184,7 @@ func (ss *sqlStore) HandleAlertsQuery(ctx context.Context, query *models.GetAler
}) })
} }
func (ss *sqlStore) SaveAlerts(ctx context.Context, dashID int64, alerts []*models.Alert) error { func (ss *sqlStore) SaveAlerts(ctx context.Context, dashID int64, alerts []*alertmodels.Alert) error {
return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error { return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
existingAlerts, err := GetAlertsByDashboardId2(dashID, sess) existingAlerts, err := GetAlertsByDashboardId2(dashID, sess)
if err != nil { if err != nil {
@@ -202,10 +203,10 @@ func (ss *sqlStore) SaveAlerts(ctx context.Context, dashID int64, alerts []*mode
}) })
} }
func (ss *sqlStore) UpdateAlerts(ctx context.Context, existingAlerts []*models.Alert, alerts []*models.Alert, sess *db.Session, log *log.ConcreteLogger) error { func (ss *sqlStore) UpdateAlerts(ctx context.Context, existingAlerts []*alertmodels.Alert, alerts []*alertmodels.Alert, sess *db.Session, log *log.ConcreteLogger) error {
for _, alert := range alerts { for _, alert := range alerts {
update := false update := false
var alertToUpdate *models.Alert var alertToUpdate *alertmodels.Alert
for _, k := range existingAlerts { for _, k := range existingAlerts {
if alert.PanelId == k.PanelId { if alert.PanelId == k.PanelId {
@@ -232,7 +233,7 @@ func (ss *sqlStore) UpdateAlerts(ctx context.Context, existingAlerts []*models.A
} else { } else {
alert.Updated = timeNow() alert.Updated = timeNow()
alert.Created = timeNow() alert.Created = timeNow()
alert.State = models.AlertStateUnknown alert.State = alertmodels.AlertStateUnknown
alert.NewStateDate = timeNow() alert.NewStateDate = timeNow()
_, err := sess.Insert(alert) _, err := sess.Insert(alert)
@@ -262,7 +263,7 @@ func (ss *sqlStore) UpdateAlerts(ctx context.Context, existingAlerts []*models.A
return nil return nil
} }
func deleteMissingAlerts(alerts []*models.Alert, existingAlerts []*models.Alert, sess *db.Session, log *log.ConcreteLogger) error { func deleteMissingAlerts(alerts []*alertmodels.Alert, existingAlerts []*alertmodels.Alert, sess *db.Session, log *log.ConcreteLogger) error {
for _, missingAlert := range alerts { for _, missingAlert := range alerts {
missing := true missing := true
@@ -285,20 +286,20 @@ func deleteMissingAlerts(alerts []*models.Alert, existingAlerts []*models.Alert,
return nil return nil
} }
func GetAlertsByDashboardId2(dashboardId int64, sess *db.Session) ([]*models.Alert, error) { func GetAlertsByDashboardId2(dashboardId int64, sess *db.Session) ([]*alertmodels.Alert, error) {
alerts := make([]*models.Alert, 0) alerts := make([]*alertmodels.Alert, 0)
err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts) err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts)
if err != nil { if err != nil {
return []*models.Alert{}, err return []*alertmodels.Alert{}, err
} }
return alerts, nil return alerts, nil
} }
func (ss *sqlStore) SetAlertState(ctx context.Context, cmd *models.SetAlertStateCommand) error { func (ss *sqlStore) SetAlertState(ctx context.Context, cmd *alertmodels.SetAlertStateCommand) error {
return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error { return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
alert := models.Alert{} alert := alertmodels.Alert{}
if has, err := sess.ID(cmd.AlertId).Get(&alert); err != nil { if has, err := sess.ID(cmd.AlertId).Get(&alert); err != nil {
return err return err
@@ -306,12 +307,12 @@ func (ss *sqlStore) SetAlertState(ctx context.Context, cmd *models.SetAlertState
return fmt.Errorf("could not find alert") return fmt.Errorf("could not find alert")
} }
if alert.State == models.AlertStatePaused { if alert.State == alertmodels.AlertStatePaused {
return models.ErrCannotChangeStateOnPausedAlert return alertmodels.ErrCannotChangeStateOnPausedAlert
} }
if alert.State == cmd.State { if alert.State == cmd.State {
return models.ErrRequiresNewState return alertmodels.ErrRequiresNewState
} }
alert.State = cmd.State alert.State = cmd.State
@@ -335,7 +336,7 @@ func (ss *sqlStore) SetAlertState(ctx context.Context, cmd *models.SetAlertState
}) })
} }
func (ss *sqlStore) PauseAlert(ctx context.Context, cmd *models.PauseAlertCommand) error { func (ss *sqlStore) PauseAlert(ctx context.Context, cmd *alertmodels.PauseAlertCommand) error {
return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error { return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
if len(cmd.AlertIds) == 0 { if len(cmd.AlertIds) == 0 {
return fmt.Errorf("command contains no alertids") return fmt.Errorf("command contains no alertids")
@@ -346,10 +347,10 @@ func (ss *sqlStore) PauseAlert(ctx context.Context, cmd *models.PauseAlertComman
buffer.WriteString(`UPDATE alert SET state = ?, new_state_date = ?`) buffer.WriteString(`UPDATE alert SET state = ?, new_state_date = ?`)
if cmd.Paused { if cmd.Paused {
params = append(params, string(models.AlertStatePaused)) params = append(params, string(alertmodels.AlertStatePaused))
params = append(params, timeNow().UTC()) params = append(params, timeNow().UTC())
} else { } else {
params = append(params, string(models.AlertStateUnknown)) params = append(params, string(alertmodels.AlertStateUnknown))
params = append(params, timeNow().UTC()) params = append(params, timeNow().UTC())
} }
@@ -369,13 +370,13 @@ func (ss *sqlStore) PauseAlert(ctx context.Context, cmd *models.PauseAlertComman
}) })
} }
func (ss *sqlStore) PauseAllAlerts(ctx context.Context, cmd *models.PauseAllAlertCommand) error { func (ss *sqlStore) PauseAllAlerts(ctx context.Context, cmd *alertmodels.PauseAllAlertCommand) error {
return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error { return ss.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
var newState string var newState string
if cmd.Paused { if cmd.Paused {
newState = string(models.AlertStatePaused) newState = string(alertmodels.AlertStatePaused)
} else { } else {
newState = string(models.AlertStateUnknown) newState = string(alertmodels.AlertStateUnknown)
} }
res, err := sess.Exec(`UPDATE alert SET state = ?, new_state_date = ?`, newState, timeNow().UTC()) res, err := sess.Exec(`UPDATE alert SET state = ?, new_state_date = ?`, newState, timeNow().UTC())
@@ -387,7 +388,7 @@ func (ss *sqlStore) PauseAllAlerts(ctx context.Context, cmd *models.PauseAllAler
}) })
} }
func (ss *sqlStore) GetAlertStatesForDashboard(ctx context.Context, query *models.GetAlertStatesForDashboardQuery) error { func (ss *sqlStore) GetAlertStatesForDashboard(ctx context.Context, query *alertmodels.GetAlertStatesForDashboardQuery) error {
return ss.db.WithDbSession(ctx, func(sess *db.Session) error { return ss.db.WithDbSession(ctx, func(sess *db.Session) error {
var rawSQL = `SELECT var rawSQL = `SELECT
id, id,
@@ -398,7 +399,7 @@ func (ss *sqlStore) GetAlertStatesForDashboard(ctx context.Context, query *model
FROM alert FROM alert
WHERE org_id = ? AND dashboard_id = ?` WHERE org_id = ? AND dashboard_id = ?`
query.Result = make([]*models.AlertStateInfoDTO, 0) query.Result = make([]*alertmodels.AlertStateInfoDTO, 0)
err := sess.SQL(rawSQL, query.OrgId, query.DashboardId).Find(&query.Result) err := sess.SQL(rawSQL, query.OrgId, query.DashboardId).Find(&query.Result)
return err return err
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"time" "time"
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/util"
) )
@@ -7,13 +7,13 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/stretchr/testify/require"
) )
func TestIntegrationAlertNotificationSQLAccess(t *testing.T) { func TestIntegrationAlertNotificationSQLAccess(t *testing.T) {
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
dashver "github.com/grafana/grafana/pkg/services/dashboardversion" dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
"github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org"
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"github.com/grafana/grafana/pkg/components/null" "github.com/grafana/grafana/pkg/components/null"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/annotations/annotationstest" "github.com/grafana/grafana/pkg/services/annotations/annotationstest"
) )
+3 -2
View File
@@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/folder"
"github.com/grafana/grafana/pkg/services/quota" "github.com/grafana/grafana/pkg/services/quota"
) )
@@ -69,8 +70,8 @@ type Store interface {
GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*DashboardProvisioning, error) GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*DashboardProvisioning, error)
HasAdminPermissionInDashboardsOrFolders(ctx context.Context, query *models.HasAdminPermissionInDashboardsOrFoldersQuery) error HasAdminPermissionInDashboardsOrFolders(ctx context.Context, query *models.HasAdminPermissionInDashboardsOrFoldersQuery) error
HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error
// SaveAlerts saves dashboard alerts. // SaveAlerts saves dashboard alertmodels.
SaveAlerts(ctx context.Context, dashID int64, alerts []*models.Alert) error SaveAlerts(ctx context.Context, dashID int64, alerts []*alertmodels.Alert) error
SaveDashboard(ctx context.Context, cmd SaveDashboardCommand) (*Dashboard, error) SaveDashboard(ctx context.Context, cmd SaveDashboardCommand) (*Dashboard, error)
SaveProvisionedDashboard(ctx context.Context, cmd SaveDashboardCommand, provisioning *DashboardProvisioning) (*Dashboard, error) SaveProvisionedDashboard(ctx context.Context, cmd SaveDashboardCommand, provisioning *DashboardProvisioning) (*Dashboard, error)
UnprovisionDashboard(ctx context.Context, id int64) error UnprovisionDashboard(ctx context.Context, id int64) error
+11 -10
View File
@@ -13,6 +13,7 @@ import (
"github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
ac "github.com/grafana/grafana/pkg/services/accesscontrol" ac "github.com/grafana/grafana/pkg/services/accesscontrol"
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
dashver "github.com/grafana/grafana/pkg/services/dashboardversion" dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
"github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/featuremgmt"
@@ -257,7 +258,7 @@ func (d *DashboardStore) UpdateDashboardACL(ctx context.Context, dashboardID int
}) })
} }
func (d *DashboardStore) SaveAlerts(ctx context.Context, dashID int64, alerts []*models.Alert) error { func (d *DashboardStore) SaveAlerts(ctx context.Context, dashID int64, alerts []*alertmodels.Alert) error {
return d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error { return d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
existingAlerts, err := GetAlertsByDashboardId2(dashID, sess) existingAlerts, err := GetAlertsByDashboardId2(dashID, sess)
if err != nil { if err != nil {
@@ -632,22 +633,22 @@ func saveProvisionedData(sess *db.Session, provisioning *dashboards.DashboardPro
return err return err
} }
func GetAlertsByDashboardId2(dashboardId int64, sess *db.Session) ([]*models.Alert, error) { func GetAlertsByDashboardId2(dashboardId int64, sess *db.Session) ([]*alertmodels.Alert, error) {
alerts := make([]*models.Alert, 0) alerts := make([]*alertmodels.Alert, 0)
err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts) err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts)
if err != nil { if err != nil {
return []*models.Alert{}, err return []*alertmodels.Alert{}, err
} }
return alerts, nil return alerts, nil
} }
func (d *DashboardStore) updateAlerts(ctx context.Context, existingAlerts []*models.Alert, alerts []*models.Alert, log log.Logger) error { func (d *DashboardStore) updateAlerts(ctx context.Context, existingAlerts []*alertmodels.Alert, alertsIn []*alertmodels.Alert, log log.Logger) error {
return d.store.WithDbSession(ctx, func(sess *db.Session) error { return d.store.WithDbSession(ctx, func(sess *db.Session) error {
for _, alert := range alerts { for _, alert := range alertsIn {
update := false update := false
var alertToUpdate *models.Alert var alertToUpdate *alertmodels.Alert
for _, k := range existingAlerts { for _, k := range existingAlerts {
if alert.PanelId == k.PanelId { if alert.PanelId == k.PanelId {
@@ -674,7 +675,7 @@ func (d *DashboardStore) updateAlerts(ctx context.Context, existingAlerts []*mod
} else { } else {
alert.Updated = time.Now() alert.Updated = time.Now()
alert.Created = time.Now() alert.Created = time.Now()
alert.State = models.AlertStateUnknown alert.State = alertmodels.AlertStateUnknown
alert.NewStateDate = time.Now() alert.NewStateDate = time.Now()
_, err := sess.Insert(alert) _, err := sess.Insert(alert)
@@ -704,7 +705,7 @@ func (d *DashboardStore) updateAlerts(ctx context.Context, existingAlerts []*mod
}) })
} }
func (d *DashboardStore) deleteMissingAlerts(alerts []*models.Alert, existingAlerts []*models.Alert, sess *db.Session) error { func (d *DashboardStore) deleteMissingAlerts(alerts []*alertmodels.Alert, existingAlerts []*alertmodels.Alert, sess *db.Session) error {
for _, missingAlert := range alerts { for _, missingAlert := range alerts {
missing := true missing := true
@@ -906,7 +907,7 @@ func createEntityEvent(dashboard *dashboards.Dashboard, eventType store.EntityEv
} }
func (d *DashboardStore) deleteAlertDefinition(dashboardId int64, sess *db.Session) error { func (d *DashboardStore) deleteAlertDefinition(dashboardId int64, sess *db.Session) error {
alerts := make([]*models.Alert, 0) alerts := make([]*alertmodels.Alert, 0)
if err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts); err != nil { if err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts); err != nil {
return err return err
} }
@@ -9,9 +9,9 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/models"
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/dashboards/database" "github.com/grafana/grafana/pkg/services/dashboards/database"
"github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/featuremgmt"
+7 -4
View File
@@ -1,13 +1,16 @@
// Code generated by mockery v2.16.0. DO NOT EDIT. // Code generated by mockery v2.15.0. DO NOT EDIT.
package dashboards package dashboards
import ( import (
context "context" context "context"
models "github.com/grafana/grafana/pkg/models" alertingmodels "github.com/grafana/grafana/pkg/services/alerting/models"
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
models "github.com/grafana/grafana/pkg/models"
quota "github.com/grafana/grafana/pkg/services/quota" quota "github.com/grafana/grafana/pkg/services/quota"
) )
@@ -316,11 +319,11 @@ func (_m *FakeDashboardStore) HasEditPermissionInFolders(ctx context.Context, qu
} }
// SaveAlerts provides a mock function with given fields: ctx, dashID, alerts // SaveAlerts provides a mock function with given fields: ctx, dashID, alerts
func (_m *FakeDashboardStore) SaveAlerts(ctx context.Context, dashID int64, alerts []*models.Alert) error { func (_m *FakeDashboardStore) SaveAlerts(ctx context.Context, dashID int64, alerts []*alertingmodels.Alert) error {
ret := _m.Called(ctx, dashID, alerts) ret := _m.Called(ctx, dashID, alerts)
var r0 error var r0 error
if rf, ok := ret.Get(0).(func(context.Context, int64, []*models.Alert) error); ok { if rf, ok := ret.Get(0).(func(context.Context, int64, []*alertingmodels.Alert) error); ok {
r0 = rf(ctx, dashID, alerts) r0 = rf(ctx, dashID, alerts)
} else { } else {
r0 = ret.Error(0) r0 = ret.Error(0)
@@ -4,7 +4,7 @@ import (
"context" "context"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/encryption" "github.com/grafana/grafana/pkg/services/encryption"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org"
@@ -8,15 +8,16 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"gopkg.in/yaml.v3"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/encryption" "github.com/grafana/grafana/pkg/services/encryption"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/provisioning/utils" "github.com/grafana/grafana/pkg/services/provisioning/utils"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"gopkg.in/yaml.v3"
) )
type configReader struct { type configReader struct {
@@ -6,10 +6,12 @@ import (
"os" "os"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/alerting/notifiers" "github.com/grafana/grafana/pkg/services/alerting/notifiers"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
@@ -17,8 +19,6 @@ import (
"github.com/grafana/grafana/pkg/services/org/orgimpl" "github.com/grafana/grafana/pkg/services/org/orgimpl"
"github.com/grafana/grafana/pkg/services/quota/quotatest" "github.com/grafana/grafana/pkg/services/quota/quotatest"
"github.com/grafana/grafana/pkg/services/sqlstore" "github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/stretchr/testify/require"
) )
var ( var (
@@ -7,7 +7,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/expr"
legacymodels "github.com/grafana/grafana/pkg/models" legacymodels "github.com/grafana/grafana/pkg/services/alerting/models"
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
"github.com/grafana/grafana/pkg/tsdb/graphite" "github.com/grafana/grafana/pkg/tsdb/graphite"
) )
@@ -14,7 +14,7 @@ import (
"xorm.io/xorm" "xorm.io/xorm"
"github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting/models"
"github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
ngModels "github.com/grafana/grafana/pkg/services/ngalert/models" ngModels "github.com/grafana/grafana/pkg/services/ngalert/models"
@@ -500,7 +500,7 @@ func TestAMConfigMigration(t *testing.T) {
} }
} }
// TestDashAlertMigration tests the execution of the main DashAlertMigration specifically for migrations of alerts. // TestDashAlertMigration tests the execution of the main DashAlertMigration specifically for migrations of models.
func TestDashAlertMigration(t *testing.T) { func TestDashAlertMigration(t *testing.T) {
// Run initial migration to have a working DB. // Run initial migration to have a working DB.
x := setupTestDB(t) x := setupTestDB(t)