Alerting: Remove CleanUp method from the Alertmanager (#85650)

Alerting: Remove Cleanup method from the Alertmanager
This commit is contained in:
Santiago 2024-04-09 12:13:27 +02:00 committed by GitHub
parent 4b5b738646
commit 2e7cc68394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 131 additions and 102 deletions

View File

@ -417,9 +417,6 @@ func (am *alertmanager) PutAlerts(_ context.Context, postableAlerts apimodels.Po
return am.Base.PutAlerts(alerts)
}
// CleanUp no-ops as no files are stored on disk.
func (am *alertmanager) CleanUp() {}
// AlertValidationError is the error capturing the validation errors
// faced on the alerts.
type AlertValidationError struct {

View File

@ -1,4 +1,4 @@
// Code generated by mockery v2.34.2. DO NOT EDIT.
// Code generated by mockery v2.42.1. DO NOT EDIT.
package alertmanager_mock
@ -34,6 +34,10 @@ func (_m *AlertmanagerMock) EXPECT() *AlertmanagerMock_Expecter {
func (_m *AlertmanagerMock) ApplyConfig(_a0 context.Context, _a1 *models.AlertConfiguration) error {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ApplyConfig")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *models.AlertConfiguration) error); ok {
r0 = rf(_a0, _a1)
@ -73,42 +77,14 @@ func (_c *AlertmanagerMock_ApplyConfig_Call) RunAndReturn(run func(context.Conte
return _c
}
// CleanUp provides a mock function with given fields:
func (_m *AlertmanagerMock) CleanUp() {
_m.Called()
}
// AlertmanagerMock_CleanUp_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CleanUp'
type AlertmanagerMock_CleanUp_Call struct {
*mock.Call
}
// CleanUp is a helper method to define mock.On call
func (_e *AlertmanagerMock_Expecter) CleanUp() *AlertmanagerMock_CleanUp_Call {
return &AlertmanagerMock_CleanUp_Call{Call: _e.mock.On("CleanUp")}
}
func (_c *AlertmanagerMock_CleanUp_Call) Run(run func()) *AlertmanagerMock_CleanUp_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *AlertmanagerMock_CleanUp_Call) Return() *AlertmanagerMock_CleanUp_Call {
_c.Call.Return()
return _c
}
func (_c *AlertmanagerMock_CleanUp_Call) RunAndReturn(run func()) *AlertmanagerMock_CleanUp_Call {
_c.Call.Return(run)
return _c
}
// CreateSilence provides a mock function with given fields: _a0, _a1
func (_m *AlertmanagerMock) CreateSilence(_a0 context.Context, _a1 *v2models.PostableSilence) (string, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for CreateSilence")
}
var r0 string
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v2models.PostableSilence) (string, error)); ok {
@ -162,6 +138,10 @@ func (_c *AlertmanagerMock_CreateSilence_Call) RunAndReturn(run func(context.Con
func (_m *AlertmanagerMock) DeleteSilence(_a0 context.Context, _a1 string) error {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for DeleteSilence")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string) error); ok {
r0 = rf(_a0, _a1)
@ -205,6 +185,10 @@ func (_c *AlertmanagerMock_DeleteSilence_Call) RunAndReturn(run func(context.Con
func (_m *AlertmanagerMock) GetAlertGroups(ctx context.Context, active bool, silenced bool, inhibited bool, filter []string, receiver string) (v2models.AlertGroups, error) {
ret := _m.Called(ctx, active, silenced, inhibited, filter, receiver)
if len(ret) == 0 {
panic("no return value specified for GetAlertGroups")
}
var r0 v2models.AlertGroups
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, bool, bool, bool, []string, string) (v2models.AlertGroups, error)); ok {
@ -264,6 +248,10 @@ func (_c *AlertmanagerMock_GetAlertGroups_Call) RunAndReturn(run func(context.Co
func (_m *AlertmanagerMock) GetAlerts(ctx context.Context, active bool, silenced bool, inhibited bool, filter []string, receiver string) (v2models.GettableAlerts, error) {
ret := _m.Called(ctx, active, silenced, inhibited, filter, receiver)
if len(ret) == 0 {
panic("no return value specified for GetAlerts")
}
var r0 v2models.GettableAlerts
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, bool, bool, bool, []string, string) (v2models.GettableAlerts, error)); ok {
@ -323,6 +311,10 @@ func (_c *AlertmanagerMock_GetAlerts_Call) RunAndReturn(run func(context.Context
func (_m *AlertmanagerMock) GetReceivers(ctx context.Context) ([]v2models.Receiver, error) {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for GetReceivers")
}
var r0 []v2models.Receiver
var r1 error
if rf, ok := ret.Get(0).(func(context.Context) ([]v2models.Receiver, error)); ok {
@ -377,6 +369,10 @@ func (_c *AlertmanagerMock_GetReceivers_Call) RunAndReturn(run func(context.Cont
func (_m *AlertmanagerMock) GetSilence(_a0 context.Context, _a1 string) (v2models.GettableSilence, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for GetSilence")
}
var r0 v2models.GettableSilence
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) (v2models.GettableSilence, error)); ok {
@ -430,6 +426,10 @@ func (_c *AlertmanagerMock_GetSilence_Call) RunAndReturn(run func(context.Contex
func (_m *AlertmanagerMock) GetStatus() definitions.GettableStatus {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetStatus")
}
var r0 definitions.GettableStatus
if rf, ok := ret.Get(0).(func() definitions.GettableStatus); ok {
r0 = rf()
@ -471,6 +471,10 @@ func (_c *AlertmanagerMock_GetStatus_Call) RunAndReturn(run func() definitions.G
func (_m *AlertmanagerMock) ListSilences(_a0 context.Context, _a1 []string) (v2models.GettableSilences, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ListSilences")
}
var r0 v2models.GettableSilences
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, []string) (v2models.GettableSilences, error)); ok {
@ -526,6 +530,10 @@ func (_c *AlertmanagerMock_ListSilences_Call) RunAndReturn(run func(context.Cont
func (_m *AlertmanagerMock) PutAlerts(_a0 context.Context, _a1 definitions.PostableAlerts) error {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for PutAlerts")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, definitions.PostableAlerts) error); ok {
r0 = rf(_a0, _a1)
@ -569,6 +577,10 @@ func (_c *AlertmanagerMock_PutAlerts_Call) RunAndReturn(run func(context.Context
func (_m *AlertmanagerMock) Ready() bool {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Ready")
}
var r0 bool
if rf, ok := ret.Get(0).(func() bool); ok {
r0 = rf()
@ -610,6 +622,10 @@ func (_c *AlertmanagerMock_Ready_Call) RunAndReturn(run func() bool) *Alertmanag
func (_m *AlertmanagerMock) SaveAndApplyConfig(ctx context.Context, config *definitions.PostableUserConfig) error {
ret := _m.Called(ctx, config)
if len(ret) == 0 {
panic("no return value specified for SaveAndApplyConfig")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *definitions.PostableUserConfig) error); ok {
r0 = rf(ctx, config)
@ -653,6 +669,10 @@ func (_c *AlertmanagerMock_SaveAndApplyConfig_Call) RunAndReturn(run func(contex
func (_m *AlertmanagerMock) SaveAndApplyDefaultConfig(ctx context.Context) error {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for SaveAndApplyDefaultConfig")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context) error); ok {
r0 = rf(ctx)
@ -727,6 +747,10 @@ func (_c *AlertmanagerMock_StopAndWait_Call) RunAndReturn(run func()) *Alertmana
func (_m *AlertmanagerMock) TestReceivers(ctx context.Context, c definitions.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, 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 {
@ -782,6 +806,10 @@ func (_c *AlertmanagerMock_TestReceivers_Call) RunAndReturn(run func(context.Con
func (_m *AlertmanagerMock) TestTemplate(ctx context.Context, c definitions.TestTemplatesConfigBodyParams) (*notify.TestTemplatesResults, error) {
ret := _m.Called(ctx, c)
if len(ret) == 0 {
panic("no return value specified for TestTemplate")
}
var r0 *notify.TestTemplatesResults
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, definitions.TestTemplatesConfigBodyParams) (*notify.TestTemplatesResults, error)); ok {

View File

@ -52,8 +52,7 @@ type Alertmanager interface {
TestReceivers(ctx context.Context, c apimodels.TestReceiversConfigBodyParams) (*TestReceiversResult, error)
TestTemplate(ctx context.Context, c apimodels.TestTemplatesConfigBodyParams) (*TestTemplatesResults, error)
// State
CleanUp()
// Lifecycle
StopAndWait()
Ready() bool
}
@ -325,8 +324,6 @@ func (moa *MultiOrgAlertmanager) SyncAlertmanagersForOrgs(ctx context.Context, o
moa.logger.Info("Stopping Alertmanager", "org", orgID)
am.StopAndWait()
moa.logger.Info("Stopped Alertmanager", "org", orgID)
// Clean up all the remaining resources from this alertmanager.
am.CleanUp()
}
moa.cleanupOrphanLocalOrgState(ctx, orgsFound)

View File

@ -401,9 +401,6 @@ func (am *Alertmanager) Ready() bool {
return am.ready
}
// CleanUp does not have an equivalent in a "remote Alertmanager" context, we don't have files on disk, no-op.
func (am *Alertmanager) CleanUp() {}
// getFullState returns a base64-encoded protobuf message representing the Alertmanager's internal state.
func (am *Alertmanager) getFullState(ctx context.Context) (string, error) {
var parts []alertingClusterPB.Part

View File

@ -314,14 +314,6 @@ func TestForkedAlertmanager_ModeRemoteSecondary(t *testing.T) {
require.ErrorIs(tt, expErr, err)
})
t.Run("CleanUp", func(tt *testing.T) {
// CleanUp should be called only in the internal Alertmanager,
// there's no cleanup to do in the remote one.
internal, _, forked := genTestAlertmanagers(tt, modeRemoteSecondary)
internal.EXPECT().CleanUp().Once()
forked.CleanUp()
})
t.Run("StopAndWait", func(tt *testing.T) {
{
// StopAndWait should be called in both Alertmanagers.
@ -589,14 +581,6 @@ func TestForkedAlertmanager_ModeRemotePrimary(t *testing.T) {
require.ErrorIs(tt, expErr, err)
})
t.Run("CleanUp", func(tt *testing.T) {
// CleanUp should be called only in the internal Alertmanager,
// there's no cleanup to do in the remote one.
internal, _, forked := genTestAlertmanagers(tt, modeRemotePrimary)
internal.EXPECT().CleanUp().Once()
forked.CleanUp()
})
t.Run("StopAndWait", func(tt *testing.T) {
// StopAndWait should be called on both Alertmanagers.
internal, remote, forked := genTestAlertmanagers(tt, modeRemotePrimary)

View File

@ -1,4 +1,4 @@
// Code generated by mockery v2.34.2. DO NOT EDIT.
// Code generated by mockery v2.42.1. DO NOT EDIT.
package alertmanager_mock
@ -34,6 +34,10 @@ func (_m *RemoteAlertmanagerMock) EXPECT() *RemoteAlertmanagerMock_Expecter {
func (_m *RemoteAlertmanagerMock) ApplyConfig(_a0 context.Context, _a1 *models.AlertConfiguration) error {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ApplyConfig")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *models.AlertConfiguration) error); ok {
r0 = rf(_a0, _a1)
@ -73,42 +77,14 @@ func (_c *RemoteAlertmanagerMock_ApplyConfig_Call) RunAndReturn(run func(context
return _c
}
// CleanUp provides a mock function with given fields:
func (_m *RemoteAlertmanagerMock) CleanUp() {
_m.Called()
}
// RemoteAlertmanagerMock_CleanUp_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CleanUp'
type RemoteAlertmanagerMock_CleanUp_Call struct {
*mock.Call
}
// CleanUp is a helper method to define mock.On call
func (_e *RemoteAlertmanagerMock_Expecter) CleanUp() *RemoteAlertmanagerMock_CleanUp_Call {
return &RemoteAlertmanagerMock_CleanUp_Call{Call: _e.mock.On("CleanUp")}
}
func (_c *RemoteAlertmanagerMock_CleanUp_Call) Run(run func()) *RemoteAlertmanagerMock_CleanUp_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *RemoteAlertmanagerMock_CleanUp_Call) Return() *RemoteAlertmanagerMock_CleanUp_Call {
_c.Call.Return()
return _c
}
func (_c *RemoteAlertmanagerMock_CleanUp_Call) RunAndReturn(run func()) *RemoteAlertmanagerMock_CleanUp_Call {
_c.Call.Return(run)
return _c
}
// CompareAndSendConfiguration provides a mock function with given fields: _a0, _a1
func (_m *RemoteAlertmanagerMock) CompareAndSendConfiguration(_a0 context.Context, _a1 *models.AlertConfiguration) error {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for CompareAndSendConfiguration")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *models.AlertConfiguration) error); ok {
r0 = rf(_a0, _a1)
@ -152,6 +128,10 @@ func (_c *RemoteAlertmanagerMock_CompareAndSendConfiguration_Call) RunAndReturn(
func (_m *RemoteAlertmanagerMock) CompareAndSendState(_a0 context.Context) error {
ret := _m.Called(_a0)
if len(ret) == 0 {
panic("no return value specified for CompareAndSendState")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context) error); ok {
r0 = rf(_a0)
@ -194,6 +174,10 @@ func (_c *RemoteAlertmanagerMock_CompareAndSendState_Call) RunAndReturn(run func
func (_m *RemoteAlertmanagerMock) CreateSilence(_a0 context.Context, _a1 *v2models.PostableSilence) (string, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for CreateSilence")
}
var r0 string
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v2models.PostableSilence) (string, error)); ok {
@ -247,6 +231,10 @@ func (_c *RemoteAlertmanagerMock_CreateSilence_Call) RunAndReturn(run func(conte
func (_m *RemoteAlertmanagerMock) DeleteSilence(_a0 context.Context, _a1 string) error {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for DeleteSilence")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string) error); ok {
r0 = rf(_a0, _a1)
@ -290,6 +278,10 @@ func (_c *RemoteAlertmanagerMock_DeleteSilence_Call) RunAndReturn(run func(conte
func (_m *RemoteAlertmanagerMock) GetAlertGroups(ctx context.Context, active bool, silenced bool, inhibited bool, filter []string, receiver string) (v2models.AlertGroups, error) {
ret := _m.Called(ctx, active, silenced, inhibited, filter, receiver)
if len(ret) == 0 {
panic("no return value specified for GetAlertGroups")
}
var r0 v2models.AlertGroups
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, bool, bool, bool, []string, string) (v2models.AlertGroups, error)); ok {
@ -349,6 +341,10 @@ func (_c *RemoteAlertmanagerMock_GetAlertGroups_Call) RunAndReturn(run func(cont
func (_m *RemoteAlertmanagerMock) GetAlerts(ctx context.Context, active bool, silenced bool, inhibited bool, filter []string, receiver string) (v2models.GettableAlerts, error) {
ret := _m.Called(ctx, active, silenced, inhibited, filter, receiver)
if len(ret) == 0 {
panic("no return value specified for GetAlerts")
}
var r0 v2models.GettableAlerts
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, bool, bool, bool, []string, string) (v2models.GettableAlerts, error)); ok {
@ -408,6 +404,10 @@ func (_c *RemoteAlertmanagerMock_GetAlerts_Call) RunAndReturn(run func(context.C
func (_m *RemoteAlertmanagerMock) GetReceivers(ctx context.Context) ([]v2models.Receiver, error) {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for GetReceivers")
}
var r0 []v2models.Receiver
var r1 error
if rf, ok := ret.Get(0).(func(context.Context) ([]v2models.Receiver, error)); ok {
@ -462,6 +462,10 @@ func (_c *RemoteAlertmanagerMock_GetReceivers_Call) RunAndReturn(run func(contex
func (_m *RemoteAlertmanagerMock) GetSilence(_a0 context.Context, _a1 string) (v2models.GettableSilence, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for GetSilence")
}
var r0 v2models.GettableSilence
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) (v2models.GettableSilence, error)); ok {
@ -515,6 +519,10 @@ func (_c *RemoteAlertmanagerMock_GetSilence_Call) RunAndReturn(run func(context.
func (_m *RemoteAlertmanagerMock) GetStatus() definitions.GettableStatus {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for GetStatus")
}
var r0 definitions.GettableStatus
if rf, ok := ret.Get(0).(func() definitions.GettableStatus); ok {
r0 = rf()
@ -556,6 +564,10 @@ func (_c *RemoteAlertmanagerMock_GetStatus_Call) RunAndReturn(run func() definit
func (_m *RemoteAlertmanagerMock) ListSilences(_a0 context.Context, _a1 []string) (v2models.GettableSilences, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ListSilences")
}
var r0 v2models.GettableSilences
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, []string) (v2models.GettableSilences, error)); ok {
@ -611,6 +623,10 @@ func (_c *RemoteAlertmanagerMock_ListSilences_Call) RunAndReturn(run func(contex
func (_m *RemoteAlertmanagerMock) PutAlerts(_a0 context.Context, _a1 definitions.PostableAlerts) error {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for PutAlerts")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, definitions.PostableAlerts) error); ok {
r0 = rf(_a0, _a1)
@ -654,6 +670,10 @@ func (_c *RemoteAlertmanagerMock_PutAlerts_Call) RunAndReturn(run func(context.C
func (_m *RemoteAlertmanagerMock) Ready() bool {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Ready")
}
var r0 bool
if rf, ok := ret.Get(0).(func() bool); ok {
r0 = rf()
@ -695,6 +715,10 @@ func (_c *RemoteAlertmanagerMock_Ready_Call) RunAndReturn(run func() bool) *Remo
func (_m *RemoteAlertmanagerMock) SaveAndApplyConfig(ctx context.Context, config *definitions.PostableUserConfig) error {
ret := _m.Called(ctx, config)
if len(ret) == 0 {
panic("no return value specified for SaveAndApplyConfig")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *definitions.PostableUserConfig) error); ok {
r0 = rf(ctx, config)
@ -738,6 +762,10 @@ func (_c *RemoteAlertmanagerMock_SaveAndApplyConfig_Call) RunAndReturn(run func(
func (_m *RemoteAlertmanagerMock) SaveAndApplyDefaultConfig(ctx context.Context) error {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for SaveAndApplyDefaultConfig")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context) error); ok {
r0 = rf(ctx)
@ -812,6 +840,10 @@ func (_c *RemoteAlertmanagerMock_StopAndWait_Call) RunAndReturn(run func()) *Rem
func (_m *RemoteAlertmanagerMock) TestReceivers(ctx context.Context, c definitions.TestReceiversConfigBodyParams) (*notifier.TestReceiversResult, 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 {
@ -867,6 +899,10 @@ func (_c *RemoteAlertmanagerMock_TestReceivers_Call) RunAndReturn(run func(conte
func (_m *RemoteAlertmanagerMock) TestTemplate(ctx context.Context, c definitions.TestTemplatesConfigBodyParams) (*notify.TestTemplatesResults, error) {
ret := _m.Called(ctx, c)
if len(ret) == 0 {
panic("no return value specified for TestTemplate")
}
var r0 *notify.TestTemplatesResults
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, definitions.TestTemplatesConfigBodyParams) (*notify.TestTemplatesResults, error)); ok {

View File

@ -91,11 +91,6 @@ func (fam *RemotePrimaryForkedAlertmanager) TestTemplate(ctx context.Context, c
return fam.remote.TestTemplate(ctx, c)
}
func (fam *RemotePrimaryForkedAlertmanager) CleanUp() {
// No cleanup to do in the remote Alertmanager.
fam.internal.CleanUp()
}
func (fam *RemotePrimaryForkedAlertmanager) StopAndWait() {
fam.internal.StopAndWait()
fam.remote.StopAndWait()

View File

@ -165,11 +165,6 @@ func (fam *RemoteSecondaryForkedAlertmanager) TestTemplate(ctx context.Context,
return fam.internal.TestTemplate(ctx, c)
}
func (fam *RemoteSecondaryForkedAlertmanager) CleanUp() {
// No cleanup to do in the remote Alertmanager.
fam.internal.CleanUp()
}
func (fam *RemoteSecondaryForkedAlertmanager) StopAndWait() {
// Stop the internal Alertmanager.
fam.internal.StopAndWait()