From 40feee0d17c72421bfd0e9dc5deebc83f7e3bb68 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Mon, 23 Jan 2023 08:19:25 -0500 Subject: [PATCH] chore: move alert-related models (#61716) * chore: move alert notification models into the alerting service (alerting/models) --- pkg/api/alerting.go | 83 ++++++++++--------- pkg/api/dtos/alerting.go | 2 +- pkg/services/alerting/alerting_usage.go | 2 +- pkg/services/alerting/alerting_usage_test.go | 2 +- pkg/services/alerting/engine_test.go | 5 +- pkg/services/alerting/eval_context.go | 35 ++++---- pkg/services/alerting/eval_context_test.go | 4 +- pkg/services/alerting/extractor.go | 10 +-- pkg/services/alerting/extractor_test.go | 2 +- pkg/services/alerting/interfaces.go | 2 +- pkg/{ => services/alerting}/models/alert.go | 0 .../alerting/models/alert_notification.go} | 0 .../alerting}/models/alert_test.go | 5 +- pkg/services/alerting/notifier.go | 15 ++-- pkg/services/alerting/notifier_test.go | 15 ++-- .../alerting/notifiers/alertmanager.go | 4 +- .../alerting/notifiers/alertmanager_test.go | 8 +- pkg/services/alerting/notifiers/base.go | 2 +- pkg/services/alerting/notifiers/base_test.go | 12 +-- pkg/services/alerting/notifiers/dingding.go | 2 +- .../alerting/notifiers/dingding_test.go | 6 +- pkg/services/alerting/notifiers/discord.go | 2 +- .../alerting/notifiers/discord_test.go | 8 +- pkg/services/alerting/notifiers/email.go | 5 +- pkg/services/alerting/notifiers/email_test.go | 8 +- pkg/services/alerting/notifiers/googlechat.go | 2 +- .../alerting/notifiers/googlechat_test.go | 8 +- pkg/services/alerting/notifiers/hipchat.go | 5 +- .../alerting/notifiers/hipchat_test.go | 8 +- pkg/services/alerting/notifiers/kafka.go | 5 +- pkg/services/alerting/notifiers/kafka_test.go | 8 +- pkg/services/alerting/notifiers/line.go | 2 +- pkg/services/alerting/notifiers/line_test.go | 8 +- pkg/services/alerting/notifiers/opsgenie.go | 2 +- .../alerting/notifiers/opsgenie_test.go | 6 +- pkg/services/alerting/notifiers/pagerduty.go | 2 +- .../alerting/notifiers/pagerduty_test.go | 5 +- pkg/services/alerting/notifiers/pushover.go | 5 +- .../alerting/notifiers/pushover_test.go | 6 +- pkg/services/alerting/notifiers/sensu.go | 2 +- pkg/services/alerting/notifiers/sensu_test.go | 2 +- pkg/services/alerting/notifiers/sensugo.go | 2 +- .../alerting/notifiers/sensugo_test.go | 8 +- pkg/services/alerting/notifiers/slack.go | 2 +- pkg/services/alerting/notifiers/slack_test.go | 9 +- pkg/services/alerting/notifiers/teams.go | 2 +- pkg/services/alerting/notifiers/teams_test.go | 8 +- pkg/services/alerting/notifiers/telegram.go | 2 +- .../alerting/notifiers/telegram_test.go | 6 +- pkg/services/alerting/notifiers/threema.go | 2 +- .../alerting/notifiers/threema_test.go | 10 +-- pkg/services/alerting/notifiers/victorops.go | 2 +- .../alerting/notifiers/victorops_test.go | 5 +- pkg/services/alerting/notifiers/webhook.go | 2 +- .../alerting/notifiers/webhook_test.go | 8 +- pkg/services/alerting/reader.go | 2 +- pkg/services/alerting/result_handler.go | 3 +- pkg/services/alerting/rule.go | 2 +- pkg/services/alerting/rule_test.go | 2 +- pkg/services/alerting/scheduler.go | 2 +- pkg/services/alerting/service.go | 2 +- pkg/services/alerting/service_test.go | 2 +- pkg/services/alerting/store.go | 79 +++++++++--------- pkg/services/alerting/store_notification.go | 2 +- .../alerting/store_notification_test.go | 6 +- pkg/services/alerting/store_test.go | 2 +- pkg/services/alerting/test_notification.go | 2 +- pkg/services/dashboards/dashboard.go | 5 +- pkg/services/dashboards/database/database.go | 21 ++--- .../dashboard_service_integration_test.go | 2 +- pkg/services/dashboards/store_mock.go | 11 ++- .../notifiers/alert_notifications.go | 2 +- .../provisioning/notifiers/config_reader.go | 5 +- .../notifiers/config_reader_test.go | 6 +- .../sqlstore/migrations/ualert/alert_rule.go | 2 +- .../migrations/ualert/migration_test.go | 4 +- 76 files changed, 277 insertions(+), 270 deletions(-) rename pkg/{ => services/alerting}/models/alert.go (100%) rename pkg/{models/alert_notifications.go => services/alerting/models/alert_notification.go} (100%) rename pkg/{ => services/alerting}/models/alert_test.go (99%) diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index 8ce873f1cd7..e8f0404498f 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -11,6 +11,7 @@ import ( "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/models" "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/datasources" "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) return } - query := models.GetAlertByIdQuery{Id: id} + query := alertmodels.GetAlertByIdQuery{Id: id} if err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query); err != 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) } - query := models.GetAlertStatesForDashboardQuery{ + query := alertmodels.GetAlertStatesForDashboardQuery{ OrgId: c.OrgID, 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 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, DashboardIDs: dashboardIDs, PanelId: c.QueryInt64("panelId"), @@ -223,7 +224,7 @@ func (hs *HTTPServer) GetAlert(c *models.ReqContext) response.Response { if err != nil { 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 { 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) } -func (hs *HTTPServer) getAlertNotificationsInternal(c *models.ReqContext) ([]*models.AlertNotification, error) { - query := &models.GetAllAlertNotificationsQuery{OrgId: c.OrgID} +func (hs *HTTPServer) getAlertNotificationsInternal(c *models.ReqContext) ([]*alertmodels.AlertNotification, error) { + query := &alertmodels.GetAllAlertNotificationsQuery{OrgId: c.OrgID} if err := hs.AlertNotificationService.GetAllAlertNotifications(c.Req.Context(), query); err != nil { return nil, err @@ -322,7 +323,7 @@ func (hs *HTTPServer) GetAlertNotificationByID(c *models.ReqContext) response.Re if err != nil { return response.Error(http.StatusBadRequest, "notificationId is invalid", err) } - query := &models.GetAlertNotificationsQuery{ + query := &alertmodels.GetAlertNotificationsQuery{ OrgId: c.OrgID, Id: notificationId, } @@ -355,7 +356,7 @@ func (hs *HTTPServer) GetAlertNotificationByID(c *models.ReqContext) response.Re // 404: notFoundError // 500: internalServerError func (hs *HTTPServer) GetAlertNotificationByUID(c *models.ReqContext) response.Response { - query := &models.GetAlertNotificationsWithUidQuery{ + query := &alertmodels.GetAlertNotificationsWithUidQuery{ OrgId: c.OrgID, Uid: web.Params(c.Req)[":uid"], } @@ -388,14 +389,14 @@ func (hs *HTTPServer) GetAlertNotificationByUID(c *models.ReqContext) response.R // 409: conflictError // 500: internalServerError func (hs *HTTPServer) CreateAlertNotification(c *models.ReqContext) response.Response { - cmd := models.CreateAlertNotificationCommand{} + cmd := alertmodels.CreateAlertNotificationCommand{} if err := web.Bind(c.Req, &cmd); err != nil { return response.Error(http.StatusBadRequest, "bad request data", err) } cmd.OrgId = c.OrgID 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) } var alertingErr alerting.ValidationError @@ -421,7 +422,7 @@ func (hs *HTTPServer) CreateAlertNotification(c *models.ReqContext) response.Res // 404: notFoundError // 500: internalServerError func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Response { - cmd := models.UpdateAlertNotificationCommand{} + cmd := alertmodels.UpdateAlertNotificationCommand{} if err := web.Bind(c.Req, &cmd); err != nil { 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 errors.Is(err, models.ErrAlertNotificationNotFound) { + if errors.Is(err, alertmodels.ErrAlertNotificationNotFound) { return response.Error(404, err.Error(), err) } 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) } - query := models.GetAlertNotificationsQuery{ + query := alertmodels.GetAlertNotificationsQuery{ OrgId: c.OrgID, Id: cmd.Id, } @@ -468,7 +469,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Res // 404: notFoundError // 500: internalServerError func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) response.Response { - cmd := models.UpdateAlertNotificationWithUidCommand{} + cmd := alertmodels.UpdateAlertNotificationWithUidCommand{} if err := web.Bind(c.Req, &cmd); err != nil { 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 errors.Is(err, models.ErrAlertNotificationNotFound) { + if errors.Is(err, alertmodels.ErrAlertNotificationNotFound) { return response.Error(404, err.Error(), nil) } return response.Error(500, "Failed to update alert notification", err) } - query := models.GetAlertNotificationsWithUidQuery{ + query := alertmodels.GetAlertNotificationsWithUidQuery{ OrgId: cmd.OrgId, Uid: cmd.Uid, } @@ -499,12 +500,12 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) respons 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 { return nil } - query := &models.GetAlertNotificationsQuery{ + query := &alertmodels.GetAlertNotificationsQuery{ OrgId: cmd.OrgId, Id: cmd.Id, } @@ -527,12 +528,12 @@ func (hs *HTTPServer) fillWithSecureSettingsData(ctx context.Context, cmd *model 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 { return nil } - query := &models.GetAlertNotificationsWithUidQuery{ + query := &alertmodels.GetAlertNotificationsWithUidQuery{ OrgId: cmd.OrgId, 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) } - cmd := models.DeleteAlertNotificationCommand{ + cmd := alertmodels.DeleteAlertNotificationCommand{ OrgId: c.OrgID, Id: notificationId, } 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(500, "Failed to delete alert notification", err) @@ -601,13 +602,13 @@ func (hs *HTTPServer) DeleteAlertNotification(c *models.ReqContext) response.Res // 404: notFoundError // 500: internalServerError func (hs *HTTPServer) DeleteAlertNotificationByUID(c *models.ReqContext) response.Response { - cmd := models.DeleteAlertNotificationWithUidCommand{ + cmd := alertmodels.DeleteAlertNotificationWithUidCommand{ OrgId: c.OrgID, Uid: web.Params(c.Req)[":uid"], } 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(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["alertId"] = alertID - query := models.GetAlertByIdQuery{Id: alertID} + query := alertmodels.GetAlertByIdQuery{Id: alertID} if err := hs.AlertEngine.AlertStore.GetAlertById(c.Req.Context(), &query); err != nil { 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 - if query.Result.State != models.AlertStatePaused && !dto.Paused { + if query.Result.State != alertmodels.AlertStatePaused && !dto.Paused { result["state"] = "un-paused" result["message"] = "Alert is already un-paused" return response.JSON(http.StatusOK, result) - } else if query.Result.State == models.AlertStatePaused && dto.Paused { - result["state"] = models.AlertStatePaused + } else if query.Result.State == alertmodels.AlertStatePaused && dto.Paused { + result["state"] = alertmodels.AlertStatePaused result["message"] = "Alert is already paused" return response.JSON(http.StatusOK, result) } - cmd := models.PauseAlertCommand{ + cmd := alertmodels.PauseAlertCommand{ OrgId: c.OrgID, AlertIds: []int64{alertID}, Paused: dto.Paused, @@ -728,10 +729,10 @@ func (hs *HTTPServer) PauseAlert(legacyAlertingEnabled *bool) func(c *models.Req return response.Error(500, "", err) } - resp := models.AlertStateUnknown + resp := alertmodels.AlertStateUnknown pausedState := "un-paused" if cmd.Paused { - resp = models.AlertStatePaused + resp = alertmodels.AlertStatePaused pausedState = "paused" } @@ -765,7 +766,7 @@ func (hs *HTTPServer) PauseAllAlerts(legacyAlertingEnabled *bool) func(c *models if err := web.Bind(c.Req, &dto); err != nil { return response.Error(http.StatusBadRequest, "bad request data", err) } - updateCmd := models.PauseAllAlertCommand{ + updateCmd := alertmodels.PauseAllAlertCommand{ 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) } - resp := models.AlertStatePending + resp := alertmodels.AlertStatePending pausedState := "un paused" if updateCmd.Paused { - resp = models.AlertStatePaused + resp = alertmodels.AlertStatePaused pausedState = "paused" } @@ -836,14 +837,14 @@ type NotificationChannelTestParams struct { type CreateAlertNotificationChannelParams struct { // in:body // required:true - Body models.CreateAlertNotificationCommand `json:"body"` + Body alertmodels.CreateAlertNotificationCommand `json:"body"` } // swagger:parameters updateAlertNotificationChannel type UpdateAlertNotificationChannelParams struct { // in:body // required:true - Body models.UpdateAlertNotificationCommand `json:"body"` + Body alertmodels.UpdateAlertNotificationCommand `json:"body"` // in:path // required:true NotificationID int64 `json:"notification_channel_id"` @@ -853,7 +854,7 @@ type UpdateAlertNotificationChannelParams struct { type UpdateAlertNotificationChannelByUIDParams struct { // in:body // required:true - Body models.UpdateAlertNotificationWithUidCommand `json:"body"` + Body alertmodels.UpdateAlertNotificationWithUidCommand `json:"body"` // in:path // required:true NotificationUID string `json:"notification_channel_uid"` @@ -997,14 +998,14 @@ type SMTPNotEnabledError PreconditionFailedError type GetAlertsResponse struct { // The response message // in: body - Body []*models.AlertListItemDTO `json:"body"` + Body []*alertmodels.AlertListItemDTO `json:"body"` } // swagger:response getAlertResponse type GetAlertResponse struct { // The response message // in: body - Body *models.Alert `json:"body"` + Body *alertmodels.Alert `json:"body"` } // swagger:response pauseAlertResponse @@ -1032,5 +1033,5 @@ type TestAlertResponse struct { type GetDashboardStatesResponse struct { // The response message // in: body - Body []*models.AlertStateInfoDTO `json:"body"` + Body []*alertmodels.AlertStateInfoDTO `json:"body"` } diff --git a/pkg/api/dtos/alerting.go b/pkg/api/dtos/alerting.go index a692268082f..94a75e4b39c 100644 --- a/pkg/api/dtos/alerting.go +++ b/pkg/api/dtos/alerting.go @@ -6,7 +6,7 @@ import ( "github.com/grafana/grafana/pkg/components/null" "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 { diff --git a/pkg/services/alerting/alerting_usage.go b/pkg/services/alerting/alerting_usage.go index 711337de037..bc919039e04 100644 --- a/pkg/services/alerting/alerting_usage.go +++ b/pkg/services/alerting/alerting_usage.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" - "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/services/alerting/models" "github.com/grafana/grafana/pkg/services/datasources" ) diff --git a/pkg/services/alerting/alerting_usage_test.go b/pkg/services/alerting/alerting_usage_test.go index a2e9f48563e..313f53b1e0a 100644 --- a/pkg/services/alerting/alerting_usage_test.go +++ b/pkg/services/alerting/alerting_usage_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "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" fd "github.com/grafana/grafana/pkg/services/datasources/fakes" ) diff --git a/pkg/services/alerting/engine_test.go b/pkg/services/alerting/engine_test.go index d6d3a7f3e1f..798073aa105 100644 --- a/pkg/services/alerting/engine_test.go +++ b/pkg/services/alerting/engine_test.go @@ -7,11 +7,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/tracing" "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/dashboards" "github.com/grafana/grafana/pkg/services/datasources" @@ -19,7 +21,6 @@ import ( encryptionprovider "github.com/grafana/grafana/pkg/services/encryption/provider" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "github.com/grafana/grafana/pkg/setting" - "github.com/stretchr/testify/require" ) type FakeEvalHandler struct { diff --git a/pkg/services/alerting/eval_context.go b/pkg/services/alerting/eval_context.go index 7ddaa4ace5e..dff04f79e59 100644 --- a/pkg/services/alerting/eval_context.go +++ b/pkg/services/alerting/eval_context.go @@ -8,6 +8,7 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "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/dashboards" "github.com/grafana/grafana/pkg/services/datasources" @@ -34,7 +35,7 @@ type EvalContext struct { ImagePublicURL string ImageOnDiskPath string NoDataFound bool - PrevAlertState models.AlertStateType + PrevAlertState alertmodels.AlertStateType RequestValidator models.PluginRequestValidator @@ -76,22 +77,22 @@ type StateDescription struct { // GetStateModel returns the `StateDescription` based on current state. func (c *EvalContext) GetStateModel() *StateDescription { switch c.Rule.State { - case models.AlertStateOK: + case alertmodels.AlertStateOK: return &StateDescription{ Color: "#36a64f", Text: "OK", } - case models.AlertStateNoData: + case alertmodels.AlertStateNoData: return &StateDescription{ Color: "#888888", Text: "No Data", } - case models.AlertStateAlerting: + case alertmodels.AlertStateAlerting: return &StateDescription{ Color: "#D63232", Text: "Alerting", } - case models.AlertStateUnknown: + case alertmodels.AlertStateUnknown: return &StateDescription{ Color: "#888888", Text: "Unknown", @@ -146,25 +147,25 @@ func (c *EvalContext) GetRuleURL() (string, error) { } // 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) - if ns != models.AlertStateAlerting || c.Rule.For == 0 { + if ns != alertmodels.AlertStateAlerting || c.Rule.For == 0 { return ns } since := time.Since(c.Rule.LastStateChange) - if c.PrevAlertState == models.AlertStatePending && since > c.Rule.For { - return models.AlertStateAlerting + if c.PrevAlertState == alertmodels.AlertStatePending && since > c.Rule.For { + return alertmodels.AlertStateAlerting } - if c.PrevAlertState == models.AlertStateAlerting { - return models.AlertStateAlerting + if c.PrevAlertState == alertmodels.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 { c.Log.Error("Alert Rule Result Error", "ruleId", c.Rule.ID, @@ -172,14 +173,14 @@ func getNewStateInternal(c *EvalContext) models.AlertStateType { "error", c.Error, "changing state to", c.Rule.ExecutionErrorState.ToAlertState()) - if c.Rule.ExecutionErrorState == models.ExecutionErrorKeepState { + if c.Rule.ExecutionErrorState == alertmodels.ExecutionErrorKeepState { return c.PrevAlertState } return c.Rule.ExecutionErrorState.ToAlertState() } if c.Firing { - return models.AlertStateAlerting + return alertmodels.AlertStateAlerting } if c.NoDataFound { @@ -188,13 +189,13 @@ func getNewStateInternal(c *EvalContext) models.AlertStateType { "name", c.Rule.Name, "changing state to", c.Rule.NoDataState.ToAlertState()) - if c.Rule.NoDataState == models.NoDataKeepState { + if c.Rule.NoDataState == alertmodels.NoDataKeepState { return c.PrevAlertState } return c.Rule.NoDataState.ToAlertState() } - return models.AlertStateOK + return alertmodels.AlertStateOK } // evaluateNotificationTemplateFields will treat the alert evaluation rule's name and message fields as diff --git a/pkg/services/alerting/eval_context_test.go b/pkg/services/alerting/eval_context_test.go index b731ed3542c..d717dc5c4b4 100644 --- a/pkg/services/alerting/eval_context_test.go +++ b/pkg/services/alerting/eval_context_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "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/validations" ) @@ -93,7 +93,7 @@ func TestGetStateFromEvalContext(t *testing.T) { name: "alerting -> alerting. should not update regardless of FOR", expected: models.AlertStateAlerting, applyFn: func(ec *EvalContext) { - ec.PrevAlertState = models.AlertStateAlerting + ec.PrevAlertState = models.AlertStatePending ec.Firing = true ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 5) ec.Rule.For = time.Minute * 2 diff --git a/pkg/services/alerting/extractor.go b/pkg/services/alerting/extractor.go index edb9c82dc01..4dce85874e5 100644 --- a/pkg/services/alerting/extractor.go +++ b/pkg/services/alerting/extractor.go @@ -8,7 +8,7 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "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/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) { - alerts := make([]*models.Alert, 0) + ret := make([]*models.Alert, 0) for _, panelObj := range jsonWithPanels.Get("panels").MustArray() { panel := simplejson.NewFromAny(panelObj) @@ -121,7 +121,7 @@ func (e *DashAlertExtractorService) getAlertFromPanels(ctx context.Context, json return nil, err } - alerts = append(alerts, alertSlice...) + ret = append(ret, alertSlice...) 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)} } - alerts = append(alerts, alert) + ret = append(ret, alert) } - return alerts, nil + return ret, nil } func validateAlertRule(alert *models.Alert) bool { diff --git a/pkg/services/alerting/extractor_test.go b/pkg/services/alerting/extractor_test.go index 39c0eb55a42..dc6bc9db30d 100644 --- a/pkg/services/alerting/extractor_test.go +++ b/pkg/services/alerting/extractor_test.go @@ -13,7 +13,7 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db/dbtest" "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/datasources" "github.com/grafana/grafana/pkg/services/datasources/permissions" diff --git a/pkg/services/alerting/interfaces.go b/pkg/services/alerting/interfaces.go index b5f2fce922d..5aeb5077cd8 100644 --- a/pkg/services/alerting/interfaces.go +++ b/pkg/services/alerting/interfaces.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/services/alerting/models" "github.com/grafana/grafana/pkg/tsdb/legacydata" ) diff --git a/pkg/models/alert.go b/pkg/services/alerting/models/alert.go similarity index 100% rename from pkg/models/alert.go rename to pkg/services/alerting/models/alert.go diff --git a/pkg/models/alert_notifications.go b/pkg/services/alerting/models/alert_notification.go similarity index 100% rename from pkg/models/alert_notifications.go rename to pkg/services/alerting/models/alert_notification.go diff --git a/pkg/models/alert_test.go b/pkg/services/alerting/models/alert_test.go similarity index 99% rename from pkg/models/alert_test.go rename to pkg/services/alerting/models/alert_test.go index 6fb86c9513a..cceac2296f4 100644 --- a/pkg/models/alert_test.go +++ b/pkg/services/alerting/models/alert_test.go @@ -3,10 +3,11 @@ package models import ( "testing" - "github.com/grafana/grafana/pkg/components/simplejson" - "github.com/grafana/grafana/pkg/services/tag" "github.com/stretchr/testify/assert" "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) { diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go index bed6ad22211..2687754fc49 100644 --- a/pkg/services/alerting/notifier.go +++ b/pkg/services/alerting/notifier.go @@ -10,6 +10,7 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/metrics" "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/org" "github.com/grafana/grafana/pkg/services/rendering" @@ -154,7 +155,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no return nil } - cmd := &models.SetAlertNotificationStateToCompleteCommand{ + cmd := &alertmodels.SetAlertNotificationStateToCompleteCommand{ Id: notifierState.state.Id, Version: notifierState.state.Version, } @@ -164,7 +165,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error { if !evalContext.IsTestRun { - setPendingCmd := &models.SetAlertNotificationStateToPendingCommand{ + setPendingCmd := &alertmodels.SetAlertNotificationStateToPendingCommand{ Id: notifierState.state.Id, Version: notifierState.state.Version, AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges, @@ -172,7 +173,7 @@ func (n *notificationService) sendNotification(evalContext *EvalContext, notifie err := n.sqlStore.SetAlertNotificationStateToPendingCommand(evalContext.Ctx, setPendingCmd) if err != nil { - if errors.Is(err, models.ErrAlertNotificationStateVersionConflict) { + if errors.Is(err, alertmodels.ErrAlertNotificationStateVersionConflict) { 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) { - query := &models.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids} + query := &alertmodels.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids} if err := n.sqlStore.GetAlertNotificationsWithUidToSend(evalContext.Ctx, query); err != nil { return nil, err @@ -270,7 +271,7 @@ func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids [ continue } - query := &models.GetOrCreateNotificationStateQuery{ + query := &alertmodels.GetOrCreateNotificationStateQuery{ NotifierId: notification.Id, AlertId: evalContext.Rule.ID, OrgId: evalContext.Rule.OrgID, @@ -294,7 +295,7 @@ func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids [ } // 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] if !found { 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 // 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) diff --git a/pkg/services/alerting/notifier_test.go b/pkg/services/alerting/notifier_test.go index 070b8454488..a34ceed7ee2 100644 --- a/pkg/services/alerting/notifier_test.go +++ b/pkg/services/alerting/notifier_test.go @@ -11,6 +11,7 @@ import ( "github.com/grafana/grafana/pkg/components/imguploader" "github.com/grafana/grafana/pkg/components/simplejson" "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/dashboards" "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.getAlertNotificationsWithUidToSend = func(ctx context.Context, query *models.GetAlertNotificationsWithUidToSendQuery) error { - query.Result = []*models.AlertNotification{ + store.getAlertNotificationsWithUidToSend = func(ctx context.Context, query *alertmodels.GetAlertNotificationsWithUidToSendQuery) error { + query.Result = []*alertmodels.AlertNotification{ { Id: 1, Type: "test", @@ -194,13 +195,13 @@ func notificationServiceScenario(t *testing.T, name string, evalCtx *EvalContext return nil } - store.getOrCreateNotificationState = func(ctx context.Context, query *models.GetOrCreateNotificationStateQuery) error { - query.Result = &models.AlertNotificationState{ + store.getOrCreateNotificationState = func(ctx context.Context, query *alertmodels.GetOrCreateNotificationStateQuery) error { + query.Result = &alertmodels.AlertNotificationState{ AlertId: evalCtx.Rule.ID, AlertRuleStateUpdatedVersion: 1, Id: 1, OrgId: evalCtx.Rule.OrgID, - State: models.AlertNotificationStateUnknown, + State: alertmodels.AlertNotificationStateUnknown, } return nil } @@ -275,7 +276,7 @@ type testNotifier struct { 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 value, exist := model.Settings.CheckGet("uploadImage") if exist { @@ -301,7 +302,7 @@ func (n *testNotifier) Notify(evalCtx *EvalContext) error { 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 } diff --git a/pkg/services/alerting/notifiers/alertmanager.go b/pkg/services/alerting/notifiers/alertmanager.go index 274a5bb05f3..9c13c186426 100644 --- a/pkg/services/alerting/notifiers/alertmanager.go +++ b/pkg/services/alerting/notifiers/alertmanager.go @@ -9,8 +9,8 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) @@ -93,7 +93,7 @@ func (am *AlertmanagerNotifier) ShouldNotify(ctx context.Context, evalContext *a 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) { return true } diff --git a/pkg/services/alerting/notifiers/alertmanager_test.go b/pkg/services/alerting/notifiers/alertmanager_test.go index 57d52c4872c..4f3b8e762bd 100644 --- a/pkg/services/alerting/notifiers/alertmanager_test.go +++ b/pkg/services/alerting/notifiers/alertmanager_test.go @@ -4,16 +4,16 @@ import ( "context" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/components/simplejson" "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/models" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "github.com/grafana/grafana/pkg/services/validations" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestReplaceIllegalCharswithUnderscore(t *testing.T) { diff --git a/pkg/services/alerting/notifiers/base.go b/pkg/services/alerting/notifiers/base.go index 07f5957e06d..ea7aa01b9f5 100644 --- a/pkg/services/alerting/notifiers/base.go +++ b/pkg/services/alerting/notifiers/base.go @@ -5,8 +5,8 @@ import ( "time" "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/models" "github.com/grafana/grafana/pkg/services/notifications" ) diff --git a/pkg/services/alerting/notifiers/base_test.go b/pkg/services/alerting/notifiers/base_test.go index 8931f7433b6..ed4d60c84d2 100644 --- a/pkg/services/alerting/notifiers/base_test.go +++ b/pkg/services/alerting/notifiers/base_test.go @@ -5,14 +5,14 @@ import ( "testing" "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/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) { diff --git a/pkg/services/alerting/notifiers/dingding.go b/pkg/services/alerting/notifiers/dingding.go index d88320f0d12..94cb2ee7b25 100644 --- a/pkg/services/alerting/notifiers/dingding.go +++ b/pkg/services/alerting/notifiers/dingding.go @@ -6,8 +6,8 @@ import ( "net/url" "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/models" "github.com/grafana/grafana/pkg/services/notifications" ) diff --git a/pkg/services/alerting/notifiers/dingding_test.go b/pkg/services/alerting/notifiers/dingding_test.go index 9f36f05c5fc..0ff465837c1 100644 --- a/pkg/services/alerting/notifiers/dingding_test.go +++ b/pkg/services/alerting/notifiers/dingding_test.go @@ -4,14 +4,14 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" + "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/models" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "github.com/grafana/grafana/pkg/services/validations" - - "github.com/stretchr/testify/require" ) func TestDingDingNotifier(t *testing.T) { diff --git a/pkg/services/alerting/notifiers/discord.go b/pkg/services/alerting/notifiers/discord.go index 7e7ff16f1d3..eeb68f23729 100644 --- a/pkg/services/alerting/notifiers/discord.go +++ b/pkg/services/alerting/notifiers/discord.go @@ -11,8 +11,8 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/discord_test.go b/pkg/services/alerting/notifiers/discord_test.go index 1b70ed36923..d173a85d215 100644 --- a/pkg/services/alerting/notifiers/discord_test.go +++ b/pkg/services/alerting/notifiers/discord_test.go @@ -3,11 +3,11 @@ package notifiers import ( "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/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) { diff --git a/pkg/services/alerting/notifiers/email.go b/pkg/services/alerting/notifiers/email.go index 69c485cfbf2..db3c2dbf3dc 100644 --- a/pkg/services/alerting/notifiers/email.go +++ b/pkg/services/alerting/notifiers/email.go @@ -4,12 +4,11 @@ import ( "os" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" + "github.com/grafana/grafana/pkg/util" ) func init() { diff --git a/pkg/services/alerting/notifiers/email_test.go b/pkg/services/alerting/notifiers/email_test.go index 8c018aa85df..69ca1bffd21 100644 --- a/pkg/services/alerting/notifiers/email_test.go +++ b/pkg/services/alerting/notifiers/email_test.go @@ -3,11 +3,11 @@ package notifiers import ( "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/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) { diff --git a/pkg/services/alerting/notifiers/googlechat.go b/pkg/services/alerting/notifiers/googlechat.go index 6eeeda4eb85..c12d6ce303c 100644 --- a/pkg/services/alerting/notifiers/googlechat.go +++ b/pkg/services/alerting/notifiers/googlechat.go @@ -7,8 +7,8 @@ import ( "time" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/googlechat_test.go b/pkg/services/alerting/notifiers/googlechat_test.go index a78ced6dc73..48c102a1fe7 100644 --- a/pkg/services/alerting/notifiers/googlechat_test.go +++ b/pkg/services/alerting/notifiers/googlechat_test.go @@ -3,11 +3,11 @@ package notifiers import ( "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/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) { diff --git a/pkg/services/alerting/notifiers/hipchat.go b/pkg/services/alerting/notifiers/hipchat.go index 5b8757934f5..cf3918092f9 100644 --- a/pkg/services/alerting/notifiers/hipchat.go +++ b/pkg/services/alerting/notifiers/hipchat.go @@ -2,14 +2,13 @@ package notifiers import ( "encoding/json" + "fmt" "strconv" "strings" - "fmt" - "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/models" "github.com/grafana/grafana/pkg/services/notifications" ) diff --git a/pkg/services/alerting/notifiers/hipchat_test.go b/pkg/services/alerting/notifiers/hipchat_test.go index 1834d92e507..625eb14da8c 100644 --- a/pkg/services/alerting/notifiers/hipchat_test.go +++ b/pkg/services/alerting/notifiers/hipchat_test.go @@ -3,11 +3,11 @@ package notifiers import ( "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/grafana/grafana/pkg/components/simplejson" + "github.com/grafana/grafana/pkg/services/alerting/models" + encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" ) //nolint:goconst diff --git a/pkg/services/alerting/notifiers/kafka.go b/pkg/services/alerting/notifiers/kafka.go index 55613d17cbb..ac7c04abc30 100644 --- a/pkg/services/alerting/notifiers/kafka.go +++ b/pkg/services/alerting/notifiers/kafka.go @@ -1,14 +1,13 @@ package notifiers import ( - "strconv" - "fmt" + "strconv" "github.com/grafana/grafana/pkg/components/simplejson" "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/models" "github.com/grafana/grafana/pkg/services/notifications" ) diff --git a/pkg/services/alerting/notifiers/kafka_test.go b/pkg/services/alerting/notifiers/kafka_test.go index bc8e854c9fe..95dbaedf57d 100644 --- a/pkg/services/alerting/notifiers/kafka_test.go +++ b/pkg/services/alerting/notifiers/kafka_test.go @@ -3,11 +3,11 @@ package notifiers import ( "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/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) { diff --git a/pkg/services/alerting/notifiers/line.go b/pkg/services/alerting/notifiers/line.go index 7ddbb7c0465..3bf4d09831e 100644 --- a/pkg/services/alerting/notifiers/line.go +++ b/pkg/services/alerting/notifiers/line.go @@ -6,8 +6,8 @@ import ( "net/url" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/line_test.go b/pkg/services/alerting/notifiers/line_test.go index 547897bf044..c6086e09c3b 100644 --- a/pkg/services/alerting/notifiers/line_test.go +++ b/pkg/services/alerting/notifiers/line_test.go @@ -3,11 +3,11 @@ package notifiers import ( "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/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) { diff --git a/pkg/services/alerting/notifiers/opsgenie.go b/pkg/services/alerting/notifiers/opsgenie.go index 4703415f84b..dcf6b7b35ee 100644 --- a/pkg/services/alerting/notifiers/opsgenie.go +++ b/pkg/services/alerting/notifiers/opsgenie.go @@ -7,8 +7,8 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/opsgenie_test.go b/pkg/services/alerting/notifiers/opsgenie_test.go index 2f60a6bf5bc..d6561624422 100644 --- a/pkg/services/alerting/notifiers/opsgenie_test.go +++ b/pkg/services/alerting/notifiers/opsgenie_test.go @@ -6,16 +6,16 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "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/models" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/services/validations" - - "github.com/stretchr/testify/require" ) func TestOpsGenieNotifier(t *testing.T) { diff --git a/pkg/services/alerting/notifiers/pagerduty.go b/pkg/services/alerting/notifiers/pagerduty.go index 7c464a668e0..2ecf0833285 100644 --- a/pkg/services/alerting/notifiers/pagerduty.go +++ b/pkg/services/alerting/notifiers/pagerduty.go @@ -9,8 +9,8 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/pagerduty_test.go b/pkg/services/alerting/notifiers/pagerduty_test.go index 9e6cf996101..bf7769c24f6 100644 --- a/pkg/services/alerting/notifiers/pagerduty_test.go +++ b/pkg/services/alerting/notifiers/pagerduty_test.go @@ -6,17 +6,16 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/components/null" "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/models" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/services/validations" - - "github.com/stretchr/testify/require" ) func presenceComparer(a, b string) bool { diff --git a/pkg/services/alerting/notifiers/pushover.go b/pkg/services/alerting/notifiers/pushover.go index 322da15632b..dcfd187d683 100644 --- a/pkg/services/alerting/notifiers/pushover.go +++ b/pkg/services/alerting/notifiers/pushover.go @@ -9,12 +9,11 @@ import ( "os" "strconv" - "github.com/grafana/grafana/pkg/setting" - "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/models" "github.com/grafana/grafana/pkg/services/notifications" + "github.com/grafana/grafana/pkg/setting" ) const pushoverEndpoint = "https://api.pushover.net/1/messages.json" diff --git a/pkg/services/alerting/notifiers/pushover_test.go b/pkg/services/alerting/notifiers/pushover_test.go index 6286e0892bb..371e78fcd71 100644 --- a/pkg/services/alerting/notifiers/pushover_test.go +++ b/pkg/services/alerting/notifiers/pushover_test.go @@ -5,14 +5,14 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "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/models" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "github.com/grafana/grafana/pkg/services/validations" - - "github.com/stretchr/testify/require" ) func TestPushoverNotifier(t *testing.T) { diff --git a/pkg/services/alerting/notifiers/sensu.go b/pkg/services/alerting/notifiers/sensu.go index 655a3ec9a43..c00dad176dc 100644 --- a/pkg/services/alerting/notifiers/sensu.go +++ b/pkg/services/alerting/notifiers/sensu.go @@ -7,8 +7,8 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/sensu_test.go b/pkg/services/alerting/notifiers/sensu_test.go index ad0717f9e8c..78073b54988 100644 --- a/pkg/services/alerting/notifiers/sensu_test.go +++ b/pkg/services/alerting/notifiers/sensu_test.go @@ -4,7 +4,7 @@ import ( "testing" "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" "github.com/stretchr/testify/require" diff --git a/pkg/services/alerting/notifiers/sensugo.go b/pkg/services/alerting/notifiers/sensugo.go index 802681fd647..d5f6a4dbfaf 100644 --- a/pkg/services/alerting/notifiers/sensugo.go +++ b/pkg/services/alerting/notifiers/sensugo.go @@ -9,8 +9,8 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/sensugo_test.go b/pkg/services/alerting/notifiers/sensugo_test.go index 72d1e6e3112..73d30ecf73b 100644 --- a/pkg/services/alerting/notifiers/sensugo_test.go +++ b/pkg/services/alerting/notifiers/sensugo_test.go @@ -3,12 +3,12 @@ package notifiers import ( "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/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) { diff --git a/pkg/services/alerting/notifiers/slack.go b/pkg/services/alerting/notifiers/slack.go index 092b366b559..7a673b99dd2 100644 --- a/pkg/services/alerting/notifiers/slack.go +++ b/pkg/services/alerting/notifiers/slack.go @@ -17,8 +17,8 @@ import ( "time" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/slack_test.go b/pkg/services/alerting/notifiers/slack_test.go index 316999607da..909257c741a 100644 --- a/pkg/services/alerting/notifiers/slack_test.go +++ b/pkg/services/alerting/notifiers/slack_test.go @@ -7,12 +7,13 @@ import ( "net/http/httptest" "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/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) { diff --git a/pkg/services/alerting/notifiers/teams.go b/pkg/services/alerting/notifiers/teams.go index 0add355228d..55456a437d0 100644 --- a/pkg/services/alerting/notifiers/teams.go +++ b/pkg/services/alerting/notifiers/teams.go @@ -4,8 +4,8 @@ import ( "encoding/json" "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/models" "github.com/grafana/grafana/pkg/services/notifications" ) diff --git a/pkg/services/alerting/notifiers/teams_test.go b/pkg/services/alerting/notifiers/teams_test.go index aa864a35af8..ce100158882 100644 --- a/pkg/services/alerting/notifiers/teams_test.go +++ b/pkg/services/alerting/notifiers/teams_test.go @@ -3,11 +3,11 @@ package notifiers import ( "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/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) { diff --git a/pkg/services/alerting/notifiers/telegram.go b/pkg/services/alerting/notifiers/telegram.go index 92b77d27a4d..0dcf34afb67 100644 --- a/pkg/services/alerting/notifiers/telegram.go +++ b/pkg/services/alerting/notifiers/telegram.go @@ -9,8 +9,8 @@ import ( "os" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/telegram_test.go b/pkg/services/alerting/notifiers/telegram_test.go index 26ce91576c2..f9c1650edb4 100644 --- a/pkg/services/alerting/notifiers/telegram_test.go +++ b/pkg/services/alerting/notifiers/telegram_test.go @@ -4,14 +4,14 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" + "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/models" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "github.com/grafana/grafana/pkg/services/validations" - - "github.com/stretchr/testify/require" ) func TestTelegramNotifier(t *testing.T) { diff --git a/pkg/services/alerting/notifiers/threema.go b/pkg/services/alerting/notifiers/threema.go index 07111646d45..6fc3589e099 100644 --- a/pkg/services/alerting/notifiers/threema.go +++ b/pkg/services/alerting/notifiers/threema.go @@ -7,8 +7,8 @@ import ( "strings" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/threema_test.go b/pkg/services/alerting/notifiers/threema_test.go index fba57eca41c..42b1aea6c8f 100644 --- a/pkg/services/alerting/notifiers/threema_test.go +++ b/pkg/services/alerting/notifiers/threema_test.go @@ -4,12 +4,12 @@ import ( "errors" "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/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) { diff --git a/pkg/services/alerting/notifiers/victorops.go b/pkg/services/alerting/notifiers/victorops.go index f2904ca39e6..e8e9736ed9a 100644 --- a/pkg/services/alerting/notifiers/victorops.go +++ b/pkg/services/alerting/notifiers/victorops.go @@ -6,8 +6,8 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/victorops_test.go b/pkg/services/alerting/notifiers/victorops_test.go index d3655a256d0..b6c1ea8956a 100644 --- a/pkg/services/alerting/notifiers/victorops_test.go +++ b/pkg/services/alerting/notifiers/victorops_test.go @@ -5,16 +5,15 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/require" "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/models" "github.com/grafana/grafana/pkg/services/annotations/annotationstest" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "github.com/grafana/grafana/pkg/services/tag" "github.com/grafana/grafana/pkg/services/validations" - - "github.com/stretchr/testify/require" ) func presenceComparerInt(a, b int64) bool { diff --git a/pkg/services/alerting/notifiers/webhook.go b/pkg/services/alerting/notifiers/webhook.go index 4baade18f5c..4342ee46b2a 100644 --- a/pkg/services/alerting/notifiers/webhook.go +++ b/pkg/services/alerting/notifiers/webhook.go @@ -5,8 +5,8 @@ import ( "encoding/json" "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/models" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/setting" ) diff --git a/pkg/services/alerting/notifiers/webhook_test.go b/pkg/services/alerting/notifiers/webhook_test.go index 391f3fa7ff2..05c489f61ec 100644 --- a/pkg/services/alerting/notifiers/webhook_test.go +++ b/pkg/services/alerting/notifiers/webhook_test.go @@ -3,12 +3,12 @@ package notifiers import ( "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/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) { diff --git a/pkg/services/alerting/reader.go b/pkg/services/alerting/reader.go index ebd41626164..d40893d15d6 100644 --- a/pkg/services/alerting/reader.go +++ b/pkg/services/alerting/reader.go @@ -6,7 +6,7 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/metrics" - "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/services/alerting/models" ) type ruleReader interface { diff --git a/pkg/services/alerting/result_handler.go b/pkg/services/alerting/result_handler.go index 366b6512058..6fa1048882a 100644 --- a/pkg/services/alerting/result_handler.go +++ b/pkg/services/alerting/result_handler.go @@ -8,8 +8,7 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/log" "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/notifications" "github.com/grafana/grafana/pkg/services/rendering" diff --git a/pkg/services/alerting/rule.go b/pkg/services/alerting/rule.go index 0096e63f83b..5f58e672597 100644 --- a/pkg/services/alerting/rule.go +++ b/pkg/services/alerting/rule.go @@ -10,7 +10,7 @@ import ( "time" "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" ) diff --git a/pkg/services/alerting/rule_test.go b/pkg/services/alerting/rule_test.go index 9bb974d0c4c..1cdc3c66bdc 100644 --- a/pkg/services/alerting/rule_test.go +++ b/pkg/services/alerting/rule_test.go @@ -12,7 +12,7 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "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" ) diff --git a/pkg/services/alerting/scheduler.go b/pkg/services/alerting/scheduler.go index f8dda48d8d4..4e9286c04bd 100644 --- a/pkg/services/alerting/scheduler.go +++ b/pkg/services/alerting/scheduler.go @@ -5,7 +5,7 @@ import ( "time" "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" ) diff --git a/pkg/services/alerting/service.go b/pkg/services/alerting/service.go index 34b6b717c74..b05d55daa39 100644 --- a/pkg/services/alerting/service.go +++ b/pkg/services/alerting/service.go @@ -5,7 +5,7 @@ import ( "fmt" "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/notifications" "github.com/grafana/grafana/pkg/setting" diff --git a/pkg/services/alerting/service_test.go b/pkg/services/alerting/service_test.go index 32460e09b63..4baad496536 100644 --- a/pkg/services/alerting/service_test.go +++ b/pkg/services/alerting/service_test.go @@ -13,7 +13,7 @@ import ( "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" "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" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "github.com/grafana/grafana/pkg/services/notifications" diff --git a/pkg/services/alerting/store.go b/pkg/services/alerting/store.go index 6ac3b154f75..ffbe00f30c9 100644 --- a/pkg/services/alerting/store.go +++ b/pkg/services/alerting/store.go @@ -10,6 +10,7 @@ import ( "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" "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/tag" "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. // A subset is needed to make it easier to mock during the tests. type AlertStore interface { - GetAlertById(context.Context, *models.GetAlertByIdQuery) error - GetAllAlertQueryHandler(context.Context, *models.GetAllAlertsQuery) error - GetAlertStatesForDashboard(context.Context, *models.GetAlertStatesForDashboardQuery) error - HandleAlertsQuery(context.Context, *models.GetAlertsQuery) error - SetAlertNotificationStateToCompleteCommand(context.Context, *models.SetAlertNotificationStateToCompleteCommand) error - SetAlertNotificationStateToPendingCommand(context.Context, *models.SetAlertNotificationStateToPendingCommand) error - GetAlertNotificationUidWithId(context.Context, *models.GetAlertNotificationUidQuery) error - GetAlertNotificationsWithUidToSend(context.Context, *models.GetAlertNotificationsWithUidToSendQuery) error - GetOrCreateAlertNotificationState(context.Context, *models.GetOrCreateNotificationStateQuery) error - SetAlertState(context.Context, *models.SetAlertStateCommand) error - PauseAlert(context.Context, *models.PauseAlertCommand) error - PauseAllAlerts(context.Context, *models.PauseAllAlertCommand) error + GetAlertById(context.Context, *alertmodels.GetAlertByIdQuery) error + GetAllAlertQueryHandler(context.Context, *alertmodels.GetAllAlertsQuery) error + GetAlertStatesForDashboard(context.Context, *alertmodels.GetAlertStatesForDashboardQuery) error + HandleAlertsQuery(context.Context, *alertmodels.GetAlertsQuery) error + SetAlertNotificationStateToCompleteCommand(context.Context, *alertmodels.SetAlertNotificationStateToCompleteCommand) error + SetAlertNotificationStateToPendingCommand(context.Context, *alertmodels.SetAlertNotificationStateToPendingCommand) error + GetAlertNotificationUidWithId(context.Context, *alertmodels.GetAlertNotificationUidQuery) error + GetAlertNotificationsWithUidToSend(context.Context, *alertmodels.GetAlertNotificationsWithUidToSendQuery) error + GetOrCreateAlertNotificationState(context.Context, *alertmodels.GetOrCreateNotificationStateQuery) error + SetAlertState(context.Context, *alertmodels.SetAlertStateCommand) error + PauseAlert(context.Context, *alertmodels.PauseAlertCommand) error + PauseAllAlerts(context.Context, *alertmodels.PauseAllAlertCommand) error } 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 { - alert := models.Alert{} + alert := alertmodels.Alert{} has, err := sess.ID(query.Id).Get(&alert) if !has { 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 { - var alerts []*models.Alert + var alerts []*alertmodels.Alert err := sess.SQL("select * from alert").Find(&alerts) if err != nil { return err @@ -103,7 +104,7 @@ func deleteAlertByIdInternal(alertId int64, reason string, sess *db.Session, log 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 { 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)) } - alerts := make([]*models.AlertListItemDTO, 0) + alerts := make([]*alertmodels.AlertListItemDTO, 0) if err := sess.SQL(builder.GetSQLString(), builder.GetParams()...).Find(&alerts); err != nil { 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 { existingAlerts, err := GetAlertsByDashboardId2(dashID, sess) 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 { update := false - var alertToUpdate *models.Alert + var alertToUpdate *alertmodels.Alert for _, k := range existingAlerts { if alert.PanelId == k.PanelId { @@ -232,7 +233,7 @@ func (ss *sqlStore) UpdateAlerts(ctx context.Context, existingAlerts []*models.A } else { alert.Updated = timeNow() alert.Created = timeNow() - alert.State = models.AlertStateUnknown + alert.State = alertmodels.AlertStateUnknown alert.NewStateDate = timeNow() _, err := sess.Insert(alert) @@ -262,7 +263,7 @@ func (ss *sqlStore) UpdateAlerts(ctx context.Context, existingAlerts []*models.A 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 { missing := true @@ -285,20 +286,20 @@ func deleteMissingAlerts(alerts []*models.Alert, existingAlerts []*models.Alert, return nil } -func GetAlertsByDashboardId2(dashboardId int64, sess *db.Session) ([]*models.Alert, error) { - alerts := make([]*models.Alert, 0) +func GetAlertsByDashboardId2(dashboardId int64, sess *db.Session) ([]*alertmodels.Alert, error) { + alerts := make([]*alertmodels.Alert, 0) err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts) if err != nil { - return []*models.Alert{}, err + return []*alertmodels.Alert{}, err } 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 { - alert := models.Alert{} + alert := alertmodels.Alert{} if has, err := sess.ID(cmd.AlertId).Get(&alert); err != nil { return err @@ -306,12 +307,12 @@ func (ss *sqlStore) SetAlertState(ctx context.Context, cmd *models.SetAlertState return fmt.Errorf("could not find alert") } - if alert.State == models.AlertStatePaused { - return models.ErrCannotChangeStateOnPausedAlert + if alert.State == alertmodels.AlertStatePaused { + return alertmodels.ErrCannotChangeStateOnPausedAlert } if alert.State == cmd.State { - return models.ErrRequiresNewState + return alertmodels.ErrRequiresNewState } 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 { if len(cmd.AlertIds) == 0 { 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 = ?`) if cmd.Paused { - params = append(params, string(models.AlertStatePaused)) + params = append(params, string(alertmodels.AlertStatePaused)) params = append(params, timeNow().UTC()) } else { - params = append(params, string(models.AlertStateUnknown)) + params = append(params, string(alertmodels.AlertStateUnknown)) 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 { var newState string if cmd.Paused { - newState = string(models.AlertStatePaused) + newState = string(alertmodels.AlertStatePaused) } else { - newState = string(models.AlertStateUnknown) + newState = string(alertmodels.AlertStateUnknown) } 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 { var rawSQL = `SELECT id, @@ -398,7 +399,7 @@ func (ss *sqlStore) GetAlertStatesForDashboard(ctx context.Context, query *model FROM alert 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) return err diff --git a/pkg/services/alerting/store_notification.go b/pkg/services/alerting/store_notification.go index 051f41a53df..1ff1fbaa1e1 100644 --- a/pkg/services/alerting/store_notification.go +++ b/pkg/services/alerting/store_notification.go @@ -9,7 +9,7 @@ import ( "time" "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" ) diff --git a/pkg/services/alerting/store_notification_test.go b/pkg/services/alerting/store_notification_test.go index b2724ef946c..bb2ad9c01c8 100644 --- a/pkg/services/alerting/store_notification_test.go +++ b/pkg/services/alerting/store_notification_test.go @@ -7,13 +7,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/models" - - "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/services/alerting/models" ) func TestIntegrationAlertNotificationSQLAccess(t *testing.T) { diff --git a/pkg/services/alerting/store_test.go b/pkg/services/alerting/store_test.go index 248cf73264f..ff56cec089b 100644 --- a/pkg/services/alerting/store_test.go +++ b/pkg/services/alerting/store_test.go @@ -10,7 +10,7 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "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" dashver "github.com/grafana/grafana/pkg/services/dashboardversion" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/services/alerting/test_notification.go b/pkg/services/alerting/test_notification.go index 2759a8a681c..a331f1d000d 100644 --- a/pkg/services/alerting/test_notification.go +++ b/pkg/services/alerting/test_notification.go @@ -9,7 +9,7 @@ import ( "github.com/grafana/grafana/pkg/components/null" "github.com/grafana/grafana/pkg/components/simplejson" "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" ) diff --git a/pkg/services/dashboards/dashboard.go b/pkg/services/dashboards/dashboard.go index 201d758a218..f6fa8e2faf2 100644 --- a/pkg/services/dashboards/dashboard.go +++ b/pkg/services/dashboards/dashboard.go @@ -4,6 +4,7 @@ import ( "context" "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/quota" ) @@ -69,8 +70,8 @@ type Store interface { GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*DashboardProvisioning, error) HasAdminPermissionInDashboardsOrFolders(ctx context.Context, query *models.HasAdminPermissionInDashboardsOrFoldersQuery) error HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error - // SaveAlerts saves dashboard alerts. - SaveAlerts(ctx context.Context, dashID int64, alerts []*models.Alert) error + // SaveAlerts saves dashboard alertmodels. + SaveAlerts(ctx context.Context, dashID int64, alerts []*alertmodels.Alert) error SaveDashboard(ctx context.Context, cmd SaveDashboardCommand) (*Dashboard, error) SaveProvisionedDashboard(ctx context.Context, cmd SaveDashboardCommand, provisioning *DashboardProvisioning) (*Dashboard, error) UnprovisionDashboard(ctx context.Context, id int64) error diff --git a/pkg/services/dashboards/database/database.go b/pkg/services/dashboards/database/database.go index 87fa9af301b..ec5a46893fe 100644 --- a/pkg/services/dashboards/database/database.go +++ b/pkg/services/dashboards/database/database.go @@ -13,6 +13,7 @@ import ( "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/models" ac "github.com/grafana/grafana/pkg/services/accesscontrol" + alertmodels "github.com/grafana/grafana/pkg/services/alerting/models" "github.com/grafana/grafana/pkg/services/dashboards" dashver "github.com/grafana/grafana/pkg/services/dashboardversion" "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 { existingAlerts, err := GetAlertsByDashboardId2(dashID, sess) if err != nil { @@ -632,22 +633,22 @@ func saveProvisionedData(sess *db.Session, provisioning *dashboards.DashboardPro return err } -func GetAlertsByDashboardId2(dashboardId int64, sess *db.Session) ([]*models.Alert, error) { - alerts := make([]*models.Alert, 0) +func GetAlertsByDashboardId2(dashboardId int64, sess *db.Session) ([]*alertmodels.Alert, error) { + alerts := make([]*alertmodels.Alert, 0) err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts) if err != nil { - return []*models.Alert{}, err + return []*alertmodels.Alert{}, err } 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 { - for _, alert := range alerts { + for _, alert := range alertsIn { update := false - var alertToUpdate *models.Alert + var alertToUpdate *alertmodels.Alert for _, k := range existingAlerts { if alert.PanelId == k.PanelId { @@ -674,7 +675,7 @@ func (d *DashboardStore) updateAlerts(ctx context.Context, existingAlerts []*mod } else { alert.Updated = time.Now() alert.Created = time.Now() - alert.State = models.AlertStateUnknown + alert.State = alertmodels.AlertStateUnknown alert.NewStateDate = time.Now() _, 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 { missing := true @@ -906,7 +907,7 @@ func createEntityEvent(dashboard *dashboards.Dashboard, eventType store.EntityEv } 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 { return err } diff --git a/pkg/services/dashboards/service/dashboard_service_integration_test.go b/pkg/services/dashboards/service/dashboard_service_integration_test.go index 8ead48aed57..03264673f95 100644 --- a/pkg/services/dashboards/service/dashboard_service_integration_test.go +++ b/pkg/services/dashboards/service/dashboard_service_integration_test.go @@ -9,9 +9,9 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" - "github.com/grafana/grafana/pkg/models" accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" "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/database" "github.com/grafana/grafana/pkg/services/featuremgmt" diff --git a/pkg/services/dashboards/store_mock.go b/pkg/services/dashboards/store_mock.go index 641caef3bbd..361b376ece6 100644 --- a/pkg/services/dashboards/store_mock.go +++ b/pkg/services/dashboards/store_mock.go @@ -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 import ( context "context" - models "github.com/grafana/grafana/pkg/models" + alertingmodels "github.com/grafana/grafana/pkg/services/alerting/models" + mock "github.com/stretchr/testify/mock" + models "github.com/grafana/grafana/pkg/models" + 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 -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) 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) } else { r0 = ret.Error(0) diff --git a/pkg/services/provisioning/notifiers/alert_notifications.go b/pkg/services/provisioning/notifiers/alert_notifications.go index 9cd7d363454..217e33f4647 100644 --- a/pkg/services/provisioning/notifiers/alert_notifications.go +++ b/pkg/services/provisioning/notifiers/alert_notifications.go @@ -4,7 +4,7 @@ import ( "context" "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/notifications" "github.com/grafana/grafana/pkg/services/org" diff --git a/pkg/services/provisioning/notifiers/config_reader.go b/pkg/services/provisioning/notifiers/config_reader.go index 944527bfacc..7e87891a932 100644 --- a/pkg/services/provisioning/notifiers/config_reader.go +++ b/pkg/services/provisioning/notifiers/config_reader.go @@ -8,15 +8,16 @@ import ( "path/filepath" "strings" + "gopkg.in/yaml.v3" + "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/models" "github.com/grafana/grafana/pkg/services/encryption" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/provisioning/utils" "github.com/grafana/grafana/pkg/setting" - "gopkg.in/yaml.v3" ) type configReader struct { diff --git a/pkg/services/provisioning/notifiers/config_reader_test.go b/pkg/services/provisioning/notifiers/config_reader_test.go index db4271b6aae..9b501bf8968 100644 --- a/pkg/services/provisioning/notifiers/config_reader_test.go +++ b/pkg/services/provisioning/notifiers/config_reader_test.go @@ -6,10 +6,12 @@ import ( "os" "testing" + "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/infra/db" "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/models" "github.com/grafana/grafana/pkg/services/alerting/notifiers" encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service" "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/quota/quotatest" "github.com/grafana/grafana/pkg/services/sqlstore" - - "github.com/stretchr/testify/require" ) var ( diff --git a/pkg/services/sqlstore/migrations/ualert/alert_rule.go b/pkg/services/sqlstore/migrations/ualert/alert_rule.go index cbcc0f2118d..6a373126fb4 100644 --- a/pkg/services/sqlstore/migrations/ualert/alert_rule.go +++ b/pkg/services/sqlstore/migrations/ualert/alert_rule.go @@ -7,7 +7,7 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "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" "github.com/grafana/grafana/pkg/tsdb/graphite" ) diff --git a/pkg/services/sqlstore/migrations/ualert/migration_test.go b/pkg/services/sqlstore/migrations/ualert/migration_test.go index f9b60781b1b..7a1d3f4374f 100644 --- a/pkg/services/sqlstore/migrations/ualert/migration_test.go +++ b/pkg/services/sqlstore/migrations/ualert/migration_test.go @@ -14,7 +14,7 @@ import ( "xorm.io/xorm" "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/datasources" 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) { // Run initial migration to have a working DB. x := setupTestDB(t)