diff --git a/go.mod b/go.mod index 8bf438d9e44..3869249170e 100644 --- a/go.mod +++ b/go.mod @@ -74,7 +74,7 @@ require ( github.com/googleapis/gax-go/v2 v2.12.3 // @grafana/grafana-backend-group github.com/gorilla/mux v1.8.1 // @grafana/grafana-backend-group github.com/gorilla/websocket v1.5.0 // @grafana/grafana-app-platform-squad - github.com/grafana/alerting v0.0.0-20240723124849-f2ab7c7b8f7d // @grafana/alerting-backend + github.com/grafana/alerting v0.0.0-20240812131556-611a23ff0f7f // @grafana/alerting-backend github.com/grafana/authlib v0.0.0-20240812070441-ccb639ea96d0 // @grafana/identity-access-team github.com/grafana/authlib/claims v0.0.0-20240809101159-74eaccc31a06 // @grafana/identity-access-team github.com/grafana/codejen v0.0.3 // @grafana/dataviz-squad diff --git a/go.sum b/go.sum index 4bfd3f335b3..73da8d916a2 100644 --- a/go.sum +++ b/go.sum @@ -2309,8 +2309,8 @@ github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grafana/alerting v0.0.0-20240723124849-f2ab7c7b8f7d h1:d2NZeTs+zBPVMd8uOOV5+6lyfs0BCDKxtiNxIMjnPNA= -github.com/grafana/alerting v0.0.0-20240723124849-f2ab7c7b8f7d/go.mod h1:DLj8frbtCaITljC2jc0L85JQViPF3mPfOSiYhm1osso= +github.com/grafana/alerting v0.0.0-20240812131556-611a23ff0f7f h1:c8QAFXkilBiF29xc7oKO2IkbGE3bp9NIKgiNLazdooY= +github.com/grafana/alerting v0.0.0-20240812131556-611a23ff0f7f/go.mod h1:DLj8frbtCaITljC2jc0L85JQViPF3mPfOSiYhm1osso= github.com/grafana/authlib v0.0.0-20240812070441-ccb639ea96d0 h1:LDLHuN0nwa9fwZUKQrOBflePLxzOz4u4AuNutI78AHk= github.com/grafana/authlib v0.0.0-20240812070441-ccb639ea96d0/go.mod h1:71+xJm0AE6eNGNExUvnABtyEztQ/Acb53/TAdOgwdmc= github.com/grafana/authlib/claims v0.0.0-20240809101159-74eaccc31a06 h1:uD1LcKwvEAqzDsgVChBudPqo5BhPxkj9AgylT5QCReo= diff --git a/pkg/services/ngalert/api/api_alertmanager.go b/pkg/services/ngalert/api/api_alertmanager.go index 41205be0897..4d9f3bec5a5 100644 --- a/pkg/services/ngalert/api/api_alertmanager.go +++ b/pkg/services/ngalert/api/api_alertmanager.go @@ -254,7 +254,7 @@ func (srv AlertmanagerSrv) RoutePostTestReceivers(c *contextmodel.ReqContext, bo return errResp } - result, err := am.TestReceivers(ctx, body) + result, status, err := am.TestReceivers(ctx, body) if err != nil { if errors.Is(err, alertingNotify.ErrNoReceivers) { return response.Error(http.StatusBadRequest, "", err) @@ -262,7 +262,7 @@ func (srv AlertmanagerSrv) RoutePostTestReceivers(c *contextmodel.ReqContext, bo return response.Error(http.StatusInternalServerError, "", err) } - return response.JSON(statusForTestReceivers(result.Receivers), newTestReceiversResult(result)) + return response.JSON(status, newTestReceiversResult(result)) } func (srv AlertmanagerSrv) RoutePostTestTemplates(c *contextmodel.ReqContext, body apimodels.TestTemplatesConfigBodyParams) response.Response { @@ -301,7 +301,7 @@ func contextWithTimeoutFromRequest(ctx context.Context, r *http.Request, default return ctx, cancelFunc, nil } -func newTestReceiversResult(r *notifier.TestReceiversResult) apimodels.TestReceiversResult { +func newTestReceiversResult(r *alertingNotify.TestReceiversResult) apimodels.TestReceiversResult { v := apimodels.TestReceiversResult{ Alert: apimodels.TestReceiversConfigAlertParams{ Annotations: r.Alert.Annotations, @@ -316,9 +316,7 @@ func newTestReceiversResult(r *notifier.TestReceiversResult) apimodels.TestRecei configs[jx].Name = config.Name configs[jx].UID = config.UID configs[jx].Status = config.Status - if config.Error != nil { - configs[jx].Error = config.Error.Error() - } + configs[jx].Error = config.Error } v.Receivers[ix].Configs = configs v.Receivers[ix].Name = next.Name @@ -326,50 +324,6 @@ func newTestReceiversResult(r *notifier.TestReceiversResult) apimodels.TestRecei return v } -// statusForTestReceivers returns the appropriate status code for the response -// for the results. -// -// It returns an HTTP 200 OK status code if notifications were sent to all receivers, -// an HTTP 400 Bad Request status code if all receivers contain invalid configuration, -// an HTTP 408 Request Timeout status code if all receivers timed out when sending -// a test notification or an HTTP 207 Multi Status. -func statusForTestReceivers(v []notifier.TestReceiverResult) int { - var ( - numBadRequests int - numTimeouts int - numUnknownErrors int - ) - for _, receiver := range v { - for _, next := range receiver.Configs { - if next.Error != nil { - var ( - invalidReceiverErr alertingNotify.IntegrationValidationError - receiverTimeoutErr alertingNotify.IntegrationTimeoutError - ) - if errors.As(next.Error, &invalidReceiverErr) { - numBadRequests += 1 - } else if errors.As(next.Error, &receiverTimeoutErr) { - numTimeouts += 1 - } else { - numUnknownErrors += 1 - } - } - } - } - if numBadRequests == len(v) { - // if all receivers contain invalid configuration - return http.StatusBadRequest - } else if numTimeouts == len(v) { - // if all receivers contain valid configuration but timed out - return http.StatusRequestTimeout - } else if numBadRequests+numTimeouts+numUnknownErrors > 0 { - return http.StatusMultiStatus - } else { - // all receivers were sent a notification without error - return http.StatusOK - } -} - func newTestTemplateResult(res *notifier.TestTemplatesResults) apimodels.TestTemplatesResults { apiRes := apimodels.TestTemplatesResults{} for _, r := range res.Results { @@ -382,7 +336,7 @@ func newTestTemplateResult(res *notifier.TestTemplatesResults) apimodels.TestTem apiRes.Errors = append(apiRes.Errors, apimodels.TestTemplatesErrorResult{ Name: e.Name, Kind: apimodels.TemplateErrorKind(e.Kind), - Message: e.Error.Error(), + Message: e.Error, }) } return apiRes diff --git a/pkg/services/ngalert/api/api_alertmanager_test.go b/pkg/services/ngalert/api/api_alertmanager_test.go index d025bd86796..14676789294 100644 --- a/pkg/services/ngalert/api/api_alertmanager_test.go +++ b/pkg/services/ngalert/api/api_alertmanager_test.go @@ -14,8 +14,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" - alertingNotify "github.com/grafana/alerting/notify" - "github.com/grafana/grafana/pkg/services/authz/zanzana" "github.com/grafana/grafana/pkg/services/ngalert/accesscontrol" @@ -101,72 +99,6 @@ func TestContextWithTimeoutFromRequest(t *testing.T) { }) } -func TestStatusForTestReceivers(t *testing.T) { - t.Run("assert HTTP 400 Status Bad Request for no receivers", func(t *testing.T) { - require.Equal(t, http.StatusBadRequest, statusForTestReceivers([]notifier.TestReceiverResult{})) - }) - - t.Run("assert HTTP 400 Bad Request when all invalid receivers", func(t *testing.T) { - require.Equal(t, http.StatusBadRequest, statusForTestReceivers([]notifier.TestReceiverResult{{ - Name: "test1", - Configs: []notifier.TestReceiverConfigResult{{ - Name: "test1", - UID: "uid1", - Status: "failed", - Error: alertingNotify.IntegrationValidationError{}, - }}, - }, { - Name: "test2", - Configs: []notifier.TestReceiverConfigResult{{ - Name: "test2", - UID: "uid2", - Status: "failed", - Error: alertingNotify.IntegrationValidationError{}, - }}, - }})) - }) - - t.Run("assert HTTP 408 Request Timeout when all receivers timed out", func(t *testing.T) { - require.Equal(t, http.StatusRequestTimeout, statusForTestReceivers([]notifier.TestReceiverResult{{ - Name: "test1", - Configs: []notifier.TestReceiverConfigResult{{ - Name: "test1", - UID: "uid1", - Status: "failed", - Error: alertingNotify.IntegrationTimeoutError{}, - }}, - }, { - Name: "test2", - Configs: []notifier.TestReceiverConfigResult{{ - Name: "test2", - UID: "uid2", - Status: "failed", - Error: alertingNotify.IntegrationTimeoutError{}, - }}, - }})) - }) - - t.Run("assert 207 Multi Status for different errors", func(t *testing.T) { - require.Equal(t, http.StatusMultiStatus, statusForTestReceivers([]notifier.TestReceiverResult{{ - Name: "test1", - Configs: []notifier.TestReceiverConfigResult{{ - Name: "test1", - UID: "uid1", - Status: "failed", - Error: alertingNotify.IntegrationValidationError{}, - }}, - }, { - Name: "test2", - Configs: []notifier.TestReceiverConfigResult{{ - Name: "test2", - UID: "uid2", - Status: "failed", - Error: alertingNotify.IntegrationTimeoutError{}, - }}, - }})) - }) -} - func TestAlertmanagerConfig(t *testing.T) { sut := createSut(t) diff --git a/pkg/services/ngalert/notifier/alertmanager_mock/Alertmanager.go b/pkg/services/ngalert/notifier/alertmanager_mock/Alertmanager.go index b0b647233c1..a3419fdc508 100644 --- a/pkg/services/ngalert/notifier/alertmanager_mock/Alertmanager.go +++ b/pkg/services/ngalert/notifier/alertmanager_mock/Alertmanager.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package alertmanager_mock @@ -13,8 +13,6 @@ import ( models "github.com/grafana/grafana/pkg/services/ngalert/models" - notifier "github.com/grafana/grafana/pkg/services/ngalert/notifier" - notify "github.com/grafana/alerting/notify" v2models "github.com/prometheus/alertmanager/api/v2/models" @@ -816,33 +814,40 @@ func (_c *AlertmanagerMock_StopAndWait_Call) RunAndReturn(run func()) *Alertmana } // TestReceivers provides a mock function with given fields: ctx, c -func (_m *AlertmanagerMock) TestReceivers(ctx context.Context, c definitions.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error) { +func (_m *AlertmanagerMock) TestReceivers(ctx context.Context, c definitions.TestReceiversConfigBodyParams) (*notify.TestReceiversResult, int, error) { ret := _m.Called(ctx, c) if len(ret) == 0 { panic("no return value specified for TestReceivers") } - var r0 *notifier.TestReceiversResult - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, definitions.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error)); ok { + var r0 *notify.TestReceiversResult + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, definitions.TestReceiversConfigBodyParams) (*notify.TestReceiversResult, int, error)); ok { return rf(ctx, c) } - if rf, ok := ret.Get(0).(func(context.Context, definitions.TestReceiversConfigBodyParams) *notifier.TestReceiversResult); ok { + if rf, ok := ret.Get(0).(func(context.Context, definitions.TestReceiversConfigBodyParams) *notify.TestReceiversResult); ok { r0 = rf(ctx, c) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*notifier.TestReceiversResult) + r0 = ret.Get(0).(*notify.TestReceiversResult) } } - if rf, ok := ret.Get(1).(func(context.Context, definitions.TestReceiversConfigBodyParams) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, definitions.TestReceiversConfigBodyParams) int); ok { r1 = rf(ctx, c) } else { - r1 = ret.Error(1) + r1 = ret.Get(1).(int) } - return r0, r1 + if rf, ok := ret.Get(2).(func(context.Context, definitions.TestReceiversConfigBodyParams) error); ok { + r2 = rf(ctx, c) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 } // AlertmanagerMock_TestReceivers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TestReceivers' @@ -864,12 +869,12 @@ func (_c *AlertmanagerMock_TestReceivers_Call) Run(run func(ctx context.Context, return _c } -func (_c *AlertmanagerMock_TestReceivers_Call) Return(_a0 *notifier.TestReceiversResult, _a1 error) *AlertmanagerMock_TestReceivers_Call { - _c.Call.Return(_a0, _a1) +func (_c *AlertmanagerMock_TestReceivers_Call) Return(_a0 *notify.TestReceiversResult, _a1 int, _a2 error) *AlertmanagerMock_TestReceivers_Call { + _c.Call.Return(_a0, _a1, _a2) return _c } -func (_c *AlertmanagerMock_TestReceivers_Call) RunAndReturn(run func(context.Context, definitions.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error)) *AlertmanagerMock_TestReceivers_Call { +func (_c *AlertmanagerMock_TestReceivers_Call) RunAndReturn(run func(context.Context, definitions.TestReceiversConfigBodyParams) (*notify.TestReceiversResult, int, error)) *AlertmanagerMock_TestReceivers_Call { _c.Call.Return(run) return _c } diff --git a/pkg/services/ngalert/notifier/legacy_storage/persist_mock.go b/pkg/services/ngalert/notifier/legacy_storage/persist_mock.go index 0520bbe03ec..03b5f825775 100644 --- a/pkg/services/ngalert/notifier/legacy_storage/persist_mock.go +++ b/pkg/services/ngalert/notifier/legacy_storage/persist_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.34.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package legacy_storage @@ -26,6 +26,10 @@ func (_m *MockAMConfigStore) EXPECT() *MockAMConfigStore_Expecter { func (_m *MockAMConfigStore) GetLatestAlertmanagerConfiguration(ctx context.Context, orgID int64) (*models.AlertConfiguration, error) { ret := _m.Called(ctx, orgID) + if len(ret) == 0 { + panic("no return value specified for GetLatestAlertmanagerConfiguration") + } + var r0 *models.AlertConfiguration var r1 error if rf, ok := ret.Get(0).(func(context.Context, int64) (*models.AlertConfiguration, error)); ok { @@ -81,6 +85,10 @@ func (_c *MockAMConfigStore_GetLatestAlertmanagerConfiguration_Call) RunAndRetur func (_m *MockAMConfigStore) UpdateAlertmanagerConfiguration(ctx context.Context, cmd *models.SaveAlertmanagerConfigurationCmd) error { ret := _m.Called(ctx, cmd) + if len(ret) == 0 { + panic("no return value specified for UpdateAlertmanagerConfiguration") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, *models.SaveAlertmanagerConfigurationCmd) error); ok { r0 = rf(ctx, cmd) diff --git a/pkg/services/ngalert/notifier/multiorg_alertmanager.go b/pkg/services/ngalert/notifier/multiorg_alertmanager.go index 7a1150fa843..8e0f89dceb8 100644 --- a/pkg/services/ngalert/notifier/multiorg_alertmanager.go +++ b/pkg/services/ngalert/notifier/multiorg_alertmanager.go @@ -68,7 +68,7 @@ type Alertmanager interface { // Receivers GetReceivers(ctx context.Context) ([]apimodels.Receiver, error) - TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*TestReceiversResult, error) + TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*alertingNotify.TestReceiversResult, int, error) TestTemplate(ctx context.Context, c apimodels.TestTemplatesConfigBodyParams) (*TestTemplatesResults, error) // Lifecycle diff --git a/pkg/services/ngalert/notifier/testreceivers.go b/pkg/services/ngalert/notifier/testreceivers.go index 44b0c7a4d2a..1ca9cf9c42d 100644 --- a/pkg/services/ngalert/notifier/testreceivers.go +++ b/pkg/services/ngalert/notifier/testreceivers.go @@ -3,34 +3,13 @@ package notifier import ( "context" "encoding/json" - "time" alertingNotify "github.com/grafana/alerting/notify" - "github.com/prometheus/alertmanager/types" - apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" ) -type TestReceiversResult struct { - Alert types.Alert - Receivers []TestReceiverResult - NotifedAt time.Time -} - -type TestReceiverResult struct { - Name string - Configs []TestReceiverConfigResult -} - -type TestReceiverConfigResult struct { - Name string - UID string - Status string - Error error -} - -func (am *alertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*TestReceiversResult, error) { +func (am *alertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*alertingNotify.TestReceiversResult, int, error) { receivers := make([]*alertingNotify.APIReceiver, 0, len(c.Receivers)) for _, r := range c.Receivers { integrations := make([]*alertingNotify.GrafanaIntegrationConfig, 0, len(r.GrafanaManagedReceivers)) @@ -56,37 +35,10 @@ func (am *alertmanager) TestReceivers(ctx context.Context, c apimodels.TestRecei alert = &alertingNotify.TestReceiversConfigAlertParams{Annotations: c.Alert.Annotations, Labels: c.Alert.Labels} } - result, err := am.Base.TestReceivers(ctx, alertingNotify.TestReceiversConfigBodyParams{ + return am.Base.TestReceivers(ctx, alertingNotify.TestReceiversConfigBodyParams{ Alert: alert, Receivers: receivers, }) - - if err != nil { - return nil, err - } - - resultReceivers := make([]TestReceiverResult, 0, len(result.Receivers)) - for _, resultReceiver := range result.Receivers { - configs := make([]TestReceiverConfigResult, 0, len(resultReceiver.Configs)) - for _, c := range resultReceiver.Configs { - configs = append(configs, TestReceiverConfigResult{ - Name: c.Name, - UID: c.UID, - Status: c.Status, - Error: c.Error, - }) - } - resultReceivers = append(resultReceivers, TestReceiverResult{ - Name: resultReceiver.Name, - Configs: configs, - }) - } - - return &TestReceiversResult{ - Alert: result.Alert, - Receivers: resultReceivers, - NotifedAt: result.NotifedAt, - }, err } func (am *alertmanager) GetReceivers(_ context.Context) ([]apimodels.Receiver, error) { diff --git a/pkg/services/ngalert/remote/alertmanager.go b/pkg/services/ngalert/remote/alertmanager.go index 87bfc8a1f6e..41b1066a1e9 100644 --- a/pkg/services/ngalert/remote/alertmanager.go +++ b/pkg/services/ngalert/remote/alertmanager.go @@ -509,8 +509,8 @@ func (am *Alertmanager) GetReceivers(ctx context.Context) ([]apimodels.Receiver, return am.mimirClient.GetReceivers(ctx) } -func (am *Alertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error) { - return ¬ifier.TestReceiversResult{}, nil +func (am *Alertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*alertingNotify.TestReceiversResult, int, error) { + return &alertingNotify.TestReceiversResult{}, 0, nil } func (am *Alertmanager) TestTemplate(ctx context.Context, c apimodels.TestTemplatesConfigBodyParams) (*notifier.TestTemplatesResults, error) { diff --git a/pkg/services/ngalert/remote/forked_alertmanager_test.go b/pkg/services/ngalert/remote/forked_alertmanager_test.go index d7ae6429871..63221c45daa 100644 --- a/pkg/services/ngalert/remote/forked_alertmanager_test.go +++ b/pkg/services/ngalert/remote/forked_alertmanager_test.go @@ -291,14 +291,14 @@ func TestForkedAlertmanager_ModeRemoteSecondary(t *testing.T) { t.Run("TestReceivers", func(tt *testing.T) { // TestReceivers should be called only in the internal Alertmanager. internal, _, forked := genTestAlertmanagers(tt, modeRemoteSecondary) - internal.EXPECT().TestReceivers(mock.Anything, mock.Anything).Return(nil, nil).Once() - _, err := forked.TestReceivers(ctx, apimodels.TestReceiversConfigBodyParams{}) + internal.EXPECT().TestReceivers(mock.Anything, mock.Anything).Return(nil, 0, nil).Once() + _, _, err := forked.TestReceivers(ctx, apimodels.TestReceiversConfigBodyParams{}) require.NoError(tt, err) // If there's an error in the internal Alertmanager, it should be returned. internal, _, forked = genTestAlertmanagers(tt, modeRemoteSecondary) - internal.EXPECT().TestReceivers(mock.Anything, mock.Anything).Return(nil, expErr).Once() - _, err = forked.TestReceivers(ctx, apimodels.TestReceiversConfigBodyParams{}) + internal.EXPECT().TestReceivers(mock.Anything, mock.Anything).Return(nil, 0, expErr).Once() + _, _, err = forked.TestReceivers(ctx, apimodels.TestReceiversConfigBodyParams{}) require.ErrorIs(tt, expErr, err) }) @@ -628,14 +628,14 @@ func TestForkedAlertmanager_ModeRemotePrimary(t *testing.T) { // TestReceivers should be called only in the remote Alertmanager. // TODO: change to remote AM once it's implemented there. internal, _, forked := genTestAlertmanagers(tt, modeRemotePrimary) - internal.EXPECT().TestReceivers(mock.Anything, mock.Anything).Return(nil, nil).Once() - _, err := forked.TestReceivers(ctx, apimodels.TestReceiversConfigBodyParams{}) + internal.EXPECT().TestReceivers(mock.Anything, mock.Anything).Return(nil, 0, nil).Once() + _, _, err := forked.TestReceivers(ctx, apimodels.TestReceiversConfigBodyParams{}) require.NoError(tt, err) // If there's an error in the remote Alertmanager, it should be returned. internal, _, forked = genTestAlertmanagers(tt, modeRemotePrimary) - internal.EXPECT().TestReceivers(mock.Anything, mock.Anything).Return(nil, expErr).Once() - _, err = forked.TestReceivers(ctx, apimodels.TestReceiversConfigBodyParams{}) + internal.EXPECT().TestReceivers(mock.Anything, mock.Anything).Return(nil, 0, expErr).Once() + _, _, err = forked.TestReceivers(ctx, apimodels.TestReceiversConfigBodyParams{}) require.ErrorIs(tt, expErr, err) }) diff --git a/pkg/services/ngalert/remote/mock/remoteAlertmanager.go b/pkg/services/ngalert/remote/mock/remoteAlertmanager.go index 8cf3983bcb0..dc73d379b3c 100644 --- a/pkg/services/ngalert/remote/mock/remoteAlertmanager.go +++ b/pkg/services/ngalert/remote/mock/remoteAlertmanager.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package alertmanager_mock @@ -13,8 +13,6 @@ import ( models "github.com/grafana/grafana/pkg/services/ngalert/models" - notifier "github.com/grafana/grafana/pkg/services/ngalert/notifier" - notify "github.com/grafana/alerting/notify" v2models "github.com/prometheus/alertmanager/api/v2/models" @@ -909,33 +907,40 @@ func (_c *RemoteAlertmanagerMock_StopAndWait_Call) RunAndReturn(run func()) *Rem } // TestReceivers provides a mock function with given fields: ctx, c -func (_m *RemoteAlertmanagerMock) TestReceivers(ctx context.Context, c definitions.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error) { +func (_m *RemoteAlertmanagerMock) TestReceivers(ctx context.Context, c definitions.TestReceiversConfigBodyParams) (*notify.TestReceiversResult, int, error) { ret := _m.Called(ctx, c) if len(ret) == 0 { panic("no return value specified for TestReceivers") } - var r0 *notifier.TestReceiversResult - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, definitions.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error)); ok { + var r0 *notify.TestReceiversResult + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, definitions.TestReceiversConfigBodyParams) (*notify.TestReceiversResult, int, error)); ok { return rf(ctx, c) } - if rf, ok := ret.Get(0).(func(context.Context, definitions.TestReceiversConfigBodyParams) *notifier.TestReceiversResult); ok { + if rf, ok := ret.Get(0).(func(context.Context, definitions.TestReceiversConfigBodyParams) *notify.TestReceiversResult); ok { r0 = rf(ctx, c) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*notifier.TestReceiversResult) + r0 = ret.Get(0).(*notify.TestReceiversResult) } } - if rf, ok := ret.Get(1).(func(context.Context, definitions.TestReceiversConfigBodyParams) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, definitions.TestReceiversConfigBodyParams) int); ok { r1 = rf(ctx, c) } else { - r1 = ret.Error(1) + r1 = ret.Get(1).(int) } - return r0, r1 + if rf, ok := ret.Get(2).(func(context.Context, definitions.TestReceiversConfigBodyParams) error); ok { + r2 = rf(ctx, c) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 } // RemoteAlertmanagerMock_TestReceivers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TestReceivers' @@ -957,12 +962,12 @@ func (_c *RemoteAlertmanagerMock_TestReceivers_Call) Run(run func(ctx context.Co return _c } -func (_c *RemoteAlertmanagerMock_TestReceivers_Call) Return(_a0 *notifier.TestReceiversResult, _a1 error) *RemoteAlertmanagerMock_TestReceivers_Call { - _c.Call.Return(_a0, _a1) +func (_c *RemoteAlertmanagerMock_TestReceivers_Call) Return(_a0 *notify.TestReceiversResult, _a1 int, _a2 error) *RemoteAlertmanagerMock_TestReceivers_Call { + _c.Call.Return(_a0, _a1, _a2) return _c } -func (_c *RemoteAlertmanagerMock_TestReceivers_Call) RunAndReturn(run func(context.Context, definitions.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error)) *RemoteAlertmanagerMock_TestReceivers_Call { +func (_c *RemoteAlertmanagerMock_TestReceivers_Call) RunAndReturn(run func(context.Context, definitions.TestReceiversConfigBodyParams) (*notify.TestReceiversResult, int, error)) *RemoteAlertmanagerMock_TestReceivers_Call { _c.Call.Return(run) return _c } diff --git a/pkg/services/ngalert/remote/remote_primary_forked_alertmanager.go b/pkg/services/ngalert/remote/remote_primary_forked_alertmanager.go index 1f8f349fc98..be783deef4e 100644 --- a/pkg/services/ngalert/remote/remote_primary_forked_alertmanager.go +++ b/pkg/services/ngalert/remote/remote_primary_forked_alertmanager.go @@ -118,7 +118,7 @@ func (fam *RemotePrimaryForkedAlertmanager) GetReceivers(ctx context.Context) ([ return fam.remote.GetReceivers(ctx) } -func (fam *RemotePrimaryForkedAlertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error) { +func (fam *RemotePrimaryForkedAlertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*alertingNotify.TestReceiversResult, int, error) { // TODO: change to remote AM once it's implemented there. return fam.internal.TestReceivers(ctx, c) } diff --git a/pkg/services/ngalert/remote/remote_secondary_forked_alertmanager.go b/pkg/services/ngalert/remote/remote_secondary_forked_alertmanager.go index 5f9c9d3f641..8143c29ba79 100644 --- a/pkg/services/ngalert/remote/remote_secondary_forked_alertmanager.go +++ b/pkg/services/ngalert/remote/remote_secondary_forked_alertmanager.go @@ -159,7 +159,7 @@ func (fam *RemoteSecondaryForkedAlertmanager) GetReceivers(ctx context.Context) return fam.internal.GetReceivers(ctx) } -func (fam *RemoteSecondaryForkedAlertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, error) { +func (fam *RemoteSecondaryForkedAlertmanager) TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*alertingNotify.TestReceiversResult, int, error) { return fam.internal.TestReceivers(ctx, c) }