Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions api-tests/management/ia/channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import (
pmmapitests "github.com/percona/pmm-managed/api-tests"
)

// Note: Even though the IA services check for alerting enabled or disabled before returning results
// we don't enable or disable IA explicit in our tests since it is enabled by default through
// ENABLE_ALERTING env var.

func TestChannelsAPI(t *testing.T) {
client := channelsClient.Default.Channels

Expand Down
3 changes: 0 additions & 3 deletions api-tests/management/ia/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ import (
pmmapitests "github.com/percona/pmm-managed/api-tests"
)

// Note: Even though the IA services check for alerting enabled or disabled before returning results
// we don't enable or disable IA explicit in our tests since it is enabled by default through
// ENABLE_ALERTING env var.
func TestRulesAPI(t *testing.T) {
rulesClient := client.Default.Rules
templatesClient := client.Default.Templates
Expand Down
3 changes: 0 additions & 3 deletions api-tests/management/ia/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ import (
pmmapitests "github.com/percona/pmm-managed/api-tests"
)

// Note: Even though the IA services check for alerting enabled or disabled before returning results
// we don't enable or disable IA explicit in our tests since it is enabled by default through
// ENABLE_ALERTING env var.
func assertTemplate(t *testing.T, expectedTemplate alert.Template, listTemplates []*templates.TemplatesItems0) {
convertParamUnit := func(u string) alert.Unit {
switch u {
Expand Down
18 changes: 0 additions & 18 deletions api-tests/server/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func TestSettings(t *testing.T) {
slackURL := gofakeit.URL()
res, err := serverClient.Default.Server.ChangeSettings(&server.ChangeSettingsParams{
Body: server.ChangeSettingsBody{
EnableAlerting: true,
EmailAlertingSettings: &server.ChangeSettingsParamsBodyEmailAlertingSettings{
From: email,
Smarthost: smarthost,
Expand All @@ -153,23 +152,6 @@ func TestSettings(t *testing.T) {
assert.Equal(t, slackURL, res.Payload.Settings.SlackAlertingSettings.URL)
})

t.Run("InvalidBothEnableAndDisableAlerting", func(t *testing.T) {
defer restoreSettingsDefaults(t)

res, err := serverClient.Default.Server.ChangeSettings(&server.ChangeSettingsParams{
Body: server.ChangeSettingsBody{
// since alerting is already enabled on managed by default using
// ENABLE_ALERTING env var, just passing DisableAlerting param satisfies
// the condition of both enable and disable alerting being true
DisableAlerting: true,
},
Context: pmmapitests.Context,
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.FailedPrecondition,
`Alerting is enabled via ENABLE_ALERTING environment variable.`)
assert.Empty(t, res)
})

t.Run("InvalidBothSlackAlertingSettingsAndRemoveSlackAlertingSettings", func(t *testing.T) {
defer restoreSettingsDefaults(t)

Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ services:
- ENABLE_DBAAS=${ENABLE_DBAAS:-0}
- AWS_ACCESS_KEY=${AWS_ACCESS_KEY}
- AWS_SECRET_KEY=${AWS_SECRET_KEY}
- ENABLE_ALERTING=1
- ENABLE_BACKUP_MANAGEMENT=1

# for delve
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/minio/minio-go/v7 v7.0.10
github.com/percona-platform/dbaas-api v0.0.0-20211201151251-014259873599
github.com/percona-platform/saas v0.0.0-20211101203847-f65c32bc8770
github.com/percona/pmm v0.0.0-20220105120335-0b304c3d1574
github.com/percona/pmm v0.0.0-20220106113046-71030a073065
github.com/percona/promconfig v0.2.4-0.20211110115058-98687f586f54
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ github.com/percona-platform/dbaas-api v0.0.0-20211201151251-014259873599 h1:dDlc
github.com/percona-platform/dbaas-api v0.0.0-20211201151251-014259873599/go.mod h1:zgb9gTJusc8Jv2zRNAlWV0/XQ8IK+hwHMc9lIqfK0tM=
github.com/percona-platform/saas v0.0.0-20211101203847-f65c32bc8770 h1:ZfS8TnnctQn0ZMB2YV7Q46LbN9odamb/nsyBJWFNaRY=
github.com/percona-platform/saas v0.0.0-20211101203847-f65c32bc8770/go.mod h1:jJRyGMxxDJaSiU7AaHNS+8j1TFQQhX6lcYp8s0t8Knc=
github.com/percona/pmm v0.0.0-20220105120335-0b304c3d1574 h1:VFcUDmqA0/hIFLB12lOdS9cLUlX8egaOVhyj/ql1Uaw=
github.com/percona/pmm v0.0.0-20220105120335-0b304c3d1574/go.mod h1:OmWayvQAavtvlzLkvpea5tAqaWGGNNyG+xj4MJUsNm4=
github.com/percona/pmm v0.0.0-20220106113046-71030a073065 h1:8Xr7oiEONNePTlVB7+zN4WAVKPI6KNqL+wiSC/McSTI=
github.com/percona/pmm v0.0.0-20220106113046-71030a073065/go.mod h1:OmWayvQAavtvlzLkvpea5tAqaWGGNNyG+xj4MJUsNm4=
github.com/percona/promconfig v0.2.1/go.mod h1:Y2uXi5QNk71+ceJHuI9poank+0S1kjxd3K105fXKVkg=
github.com/percona/promconfig v0.2.4-0.20211110115058-98687f586f54 h1:aI1emmycDTGWKsBdxFPKZqohfBbK4y2ta9G4+RX7gVg=
github.com/percona/promconfig v0.2.4-0.20211110115058-98687f586f54/go.mod h1:Y2uXi5QNk71+ceJHuI9poank+0S1kjxd3K105fXKVkg=
Expand Down
1 change: 0 additions & 1 deletion models/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type SaaS struct {

// IntegratedAlerting contains settings related to IntegratedAlerting.
type IntegratedAlerting struct {
Enabled bool `json:"enabled"`
EmailAlertingSettings *EmailAlertingSettings `json:"email_settings"`
SlackAlertingSettings *SlackAlertingSettings `json:"slack_settings"`
}
Expand Down
16 changes: 0 additions & 16 deletions models/settings_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ type ChangeSettingsParams struct {
// Disable Azure Discover features.
DisableAzurediscover bool

// Enable Integrated Alerting features.
EnableAlerting bool
// Disable Integrated Alerting features.
DisableAlerting bool

// Email config for Integrated Alerting.
EmailAlertingSettings *EmailAlertingSettings
// If true removes email alerting settings.
Expand Down Expand Up @@ -248,14 +243,6 @@ func UpdateSettings(q reform.DBTX, params *ChangeSettingsParams) (*Settings, err
settings.Azurediscover.Enabled = true
}

if params.DisableAlerting {
settings.IntegratedAlerting.Enabled = false
}

if params.EnableAlerting {
settings.IntegratedAlerting.Enabled = true
}

if params.RemoveEmailAlertingSettings {
settings.IntegratedAlerting.EmailAlertingSettings = nil
}
Expand Down Expand Up @@ -328,9 +315,6 @@ func ValidateSettings(params *ChangeSettingsParams) error {
if params.EnableVMCache && params.DisableVMCache {
return errors.New("both enable_vm_cache and disable_vm_cache are present")
}
if params.EnableAlerting && params.DisableAlerting {
return errors.New("both enable_alerting and disable_alerting are present")
}
if err := validateEmailAlertingSettings(params); err != nil {
return err
}
Expand Down
12 changes: 0 additions & 12 deletions models/settings_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,16 @@ func TestSettings(t *testing.T) {
}
slackSettings := &models.SlackAlertingSettings{URL: gofakeit.URL()}
ns, err := models.UpdateSettings(sqlDB, &models.ChangeSettingsParams{
EnableAlerting: true,
EmailAlertingSettings: emailSettings,
SlackAlertingSettings: slackSettings,
})
require.NoError(t, err)
assert.True(t, ns.IntegratedAlerting.Enabled)
assert.Equal(t, ns.IntegratedAlerting.EmailAlertingSettings, emailSettings)
assert.Equal(t, ns.IntegratedAlerting.SlackAlertingSettings, slackSettings)

// check that we don't lose settings on empty updates
ns, err = models.UpdateSettings(sqlDB, &models.ChangeSettingsParams{})
require.NoError(t, err)
assert.True(t, ns.IntegratedAlerting.Enabled)
assert.Equal(t, ns.IntegratedAlerting.EmailAlertingSettings, emailSettings)
assert.Equal(t, ns.IntegratedAlerting.SlackAlertingSettings, slackSettings)

Expand Down Expand Up @@ -411,20 +408,11 @@ func TestSettings(t *testing.T) {
assert.EqualError(t, err, "invalid argument: invalid url value")

ns, err = models.UpdateSettings(sqlDB, &models.ChangeSettingsParams{
DisableAlerting: true,
RemoveEmailAlertingSettings: true,
RemoveSlackAlertingSettings: true,
})
require.NoError(t, err)
assert.Empty(t, ns.IntegratedAlerting.EmailAlertingSettings)
assert.False(t, ns.IntegratedAlerting.Enabled)

_, err = models.UpdateSettings(sqlDB, &models.ChangeSettingsParams{
DisableAlerting: true,
EnableAlerting: true,
})
assert.True(t, errors.As(err, &errInvalidArgument))
assert.EqualError(t, err, "invalid argument: both enable_alerting and disable_alerting are present")
})
})

Expand Down
7 changes: 1 addition & 6 deletions services/management/ia/alerts_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ func NewAlertsService(db *reform.DB, alertManager alertManager, templatesService

// Enabled returns if service is enabled and can be used.
func (s *AlertsService) Enabled() bool {
settings, err := models.GetSettings(s.db)
if err != nil {
s.l.WithError(err).Error("can't get settings")
return false
}
return settings.IntegratedAlerting.Enabled
return true
}

// ListAlerts returns list of existing alerts.
Expand Down
7 changes: 1 addition & 6 deletions services/management/ia/channels_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ func NewChannelsService(db *reform.DB, alertManager alertManager) *ChannelsServi

// Enabled returns if service is enabled and can be used.
func (s *ChannelsService) Enabled() bool {
Comment thread
oter marked this conversation as resolved.
settings, err := models.GetSettings(s.db)
if err != nil {
s.l.WithError(err).Error("can't get settings")
return false
}
return settings.IntegratedAlerting.Enabled
return true
}

// ListChannels returns list of available channels.
Expand Down
7 changes: 1 addition & 6 deletions services/management/ia/rules_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ func NewRulesService(db *reform.DB, templates *TemplatesService, vmalert vmAlert

// Enabled returns if service is enabled and can be used.
func (s *RulesService) Enabled() bool {
Comment thread
oter marked this conversation as resolved.
settings, err := models.GetSettings(s.db)
if err != nil {
s.l.WithError(err).Error("can't get settings")
return false
}
return settings.IntegratedAlerting.Enabled
return true
}

// TODO Move this and related types to https://github.com/percona/promconfig
Expand Down
7 changes: 0 additions & 7 deletions services/management/ia/rules_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ func TestCreateAlertRule(t *testing.T) {
sqlDB := testdb.Open(t, models.SkipFixtures, nil)
db := reform.NewDB(sqlDB, postgresql.Dialect, reform.NewPrintfLogger(t.Logf))

// Enable IA
settings, err := models.GetSettings(db)
require.NoError(t, err)
settings.IntegratedAlerting.Enabled = true
err = models.SaveSettings(db, settings)
require.NoError(t, err)

alertManager := new(mockAlertManager)
alertManager.On("RequestConfigurationUpdate").Return()
vmAlert := new(mockVmAlert)
Expand Down
7 changes: 1 addition & 6 deletions services/management/ia/templates_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ func NewTemplatesService(db *reform.DB) (*TemplatesService, error) {

// Enabled returns if service is enabled and can be used.
func (s *TemplatesService) Enabled() bool {
settings, err := models.GetSettings(s.db)
if err != nil {
s.l.WithError(err).Error("can't get settings")
return false
}
return settings.IntegratedAlerting.Enabled
return true
}

func newParamTemplate() *template.Template {
Expand Down
7 changes: 0 additions & 7 deletions services/management/ia/templates_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ func TestTemplateValidation(t *testing.T) {
sqlDB := testdb.Open(t, models.SkipFixtures, nil)
db := reform.NewDB(sqlDB, postgresql.Dialect, reform.NewPrintfLogger(t.Logf))

// Enable IA
settings, err := models.GetSettings(db)
require.NoError(t, err)
settings.IntegratedAlerting.Enabled = true
err = models.SaveSettings(db, settings)
require.NoError(t, err)

t.Run("create a template with missing param", func(t *testing.T) {
t.Parallel()

Expand Down
21 changes: 1 addition & 20 deletions services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (s *Server) convertSettings(settings *models.Settings, connectedToPlatform
AzurediscoverEnabled: settings.Azurediscover.Enabled,
PmmPublicAddress: settings.PMMPublicAddress,

AlertingEnabled: settings.IntegratedAlerting.Enabled,
AlertingEnabled: true,
BackupManagementEnabled: settings.BackupManagement.Enabled,

ConnectedToPlatform: connectedToPlatform,
Expand Down Expand Up @@ -531,11 +531,6 @@ func (s *Server) validateChangeSettingsRequest(ctx context.Context, req *serverp
return status.Error(codes.FailedPrecondition, "Telemetry is disabled via DISABLE_TELEMETRY environment variable.")
}

// ignore req.EnableAlerting even if they are present since that will not change anything
if req.DisableAlerting && s.envSettings.EnableAlerting {
return status.Error(codes.FailedPrecondition, "Alerting is enabled via ENABLE_ALERTING environment variable.")
}

// ignore req.DisableAzurediscover even if they are present since that will not change anything
if req.DisableAzurediscover && s.envSettings.EnableAzurediscover {
return status.Error(codes.FailedPrecondition, "Azure Discover is enabled via ENABLE_AZUREDISCOVER environment variable.")
Expand Down Expand Up @@ -608,8 +603,6 @@ func (s *Server) ChangeSettings(ctx context.Context, req *serverpb.ChangeSetting
PMMPublicAddress: req.PmmPublicAddress,
RemovePMMPublicAddress: req.RemovePmmPublicAddress,

EnableAlerting: req.EnableAlerting,
DisableAlerting: req.DisableAlerting,
RemoveEmailAlertingSettings: req.RemoveEmailAlertingSettings,
RemoveSlackAlertingSettings: req.RemoveSlackAlertingSettings,
EnableBackupManagement: req.EnableBackupManagement,
Expand Down Expand Up @@ -678,18 +671,6 @@ func (s *Server) ChangeSettings(ctx context.Context, req *serverpb.ChangeSetting
return nil, err
}

// When IA moved from disabled state to enabled create rules files.
if !oldSettings.IntegratedAlerting.Enabled && req.EnableAlerting {
s.rulesService.WriteVMAlertRulesFiles()
}

// When IA moved from enabled state to disables cleanup rules files.
if oldSettings.IntegratedAlerting.Enabled && req.DisableAlerting {
if err := s.rulesService.RemoveVMAlertRulesFiles(); err != nil {
s.l.Errorf("Failed to clean old alert rule files: %+v", err)
}
}

// If STT intervals are changed reset timers.
if oldSettings.SaaS.STTCheckIntervals != newSettings.SaaS.STTCheckIntervals {
s.checksService.UpdateIntervals(
Expand Down
33 changes: 1 addition & 32 deletions services/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ func TestServer(t *testing.T) {

server.UpdateSettingsFromEnv([]string{
"ENABLE_DBAAS=1",
"ENABLE_ALERTING=1",
"ENABLE_AZUREDISCOVER=1",
})

Expand All @@ -238,39 +237,9 @@ func TestServer(t *testing.T) {

require.NoError(t, err)
assert.True(t, settings.Settings.DbaasEnabled)
assert.True(t, settings.Settings.AlertingEnabled)
assert.True(t, settings.Settings.AlertingEnabled) //nolint:staticcheck
assert.True(t, settings.Settings.AzurediscoverEnabled)
})

t.Run("ChangeSettings IA", func(t *testing.T) {
server := newServer(t)
rs := new(mockRulesService)
server.rulesService = rs
server.UpdateSettingsFromEnv([]string{})

ctx := context.TODO()
rs.On("RemoveVMAlertRulesFiles").Return(nil)
defer rs.AssertExpectations(t)
s, err := server.ChangeSettings(ctx, &serverpb.ChangeSettingsRequest{
DisableAlerting: true,
})
require.NoError(t, err)
require.NotNil(t, s)

rs.On("WriteVMAlertRulesFiles")
s, err = server.ChangeSettings(ctx, &serverpb.ChangeSettingsRequest{
EnableAlerting: true,
})
require.NoError(t, err)
require.NotNil(t, s)

rs.On("RemoveVMAlertRulesFiles").Return(nil)
s, err = server.ChangeSettings(ctx, &serverpb.ChangeSettingsRequest{
DisableAlerting: true,
})
require.NoError(t, err)
require.NotNil(t, s)
})
}

func TestServer_TestEmailAlertingSettings(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion services/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (s *Service) makeV2Payload(serverUUID string, settings *models.Settings) (*
UpDuration: durationpb.New(time.Since(s.start)),
DistributionMethod: s.tDistributionMethod,
SttEnabled: wrapperspb.Bool(settings.SaaS.STTEnabled),
IaEnabled: wrapperspb.Bool(settings.IntegratedAlerting.Enabled),
IaEnabled: wrapperspb.Bool(true),
}

if err = event.Validate(); err != nil {
Expand Down
Loading