Skip to content

Commit

Permalink
PMM-7135 Add seconds and summary, fix bugs (#591)
Browse files Browse the repository at this point in the history
* PMM-7135 Update pmm dependency

* PMM-7135 Allow to change channel summary, fix bug with updating channel configuraion

* PMM-7135 Add seconds unit type support

* PMM-7135 Simplify param unit conversion
  • Loading branch information
artemgavrilov committed Dec 22, 2020
1 parent fdc9333 commit acb22f6
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 86 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions models/channel_helpers.go
Expand Up @@ -238,6 +238,8 @@ func CreateChannel(q *reform.Querier, params *CreateChannelParams) (*Channel, er

// ChangeChannelParams is params for changing existing channel.
type ChangeChannelParams struct {
Summary string

EmailConfig *EmailConfig
PagerDutyConfig *PagerDutyConfig
SlackConfig *SlackConfig
Expand All @@ -254,11 +256,16 @@ func ChangeChannel(q *reform.Querier, channelID string, params *ChangeChannelPar
}

// remove previous configuration
row.Type = ""
row.EmailConfig = nil
row.PagerDutyConfig = nil
row.SlackConfig = nil
row.WebHookConfig = nil

if params.Summary != "" {
row.Summary = params.Summary
}

if params.EmailConfig != nil {
if err := checkEmailConfig(params.EmailConfig); err != nil {
return nil, err
Expand Down
24 changes: 14 additions & 10 deletions models/channel_helpers_test.go
Expand Up @@ -54,6 +54,11 @@ func TestNotificationChannels(t *testing.T) {

expected, err := models.CreateChannel(q, &params)
require.NoError(t, err)
assert.Equal(t, models.Email, expected.Type)
assert.Equal(t, params.Summary, expected.Summary)
assert.Equal(t, params.Disabled, expected.Disabled)
assert.Equal(t, params.EmailConfig.SendResolved, expected.EmailConfig.SendResolved)
assert.EqualValues(t, params.EmailConfig.SendResolved, expected.EmailConfig.SendResolved)

actual, err := models.FindChannelByID(q, expected.ID)
require.NoError(t, err)
Expand Down Expand Up @@ -82,27 +87,26 @@ func TestNotificationChannels(t *testing.T) {
require.NoError(t, err)

uParams := &models.ChangeChannelParams{
EmailConfig: &models.EmailConfig{
Summary: "completely new summary",
SlackConfig: &models.SlackConfig{
SendResolved: true,
To: []string{"test2@test.test"},
Channel: "general",
},
Disabled: true,
}

updated, err := models.ChangeChannel(q, created.ID, uParams)
require.NoError(t, err)
assert.Equal(t, created.Type, updated.Type)
assert.Equal(t, created.Summary, updated.Summary)
assert.Equal(t, models.Slack, updated.Type)
assert.Equal(t, uParams.Summary, updated.Summary)
assert.Equal(t, uParams.Disabled, updated.Disabled)
assert.Equal(t, uParams.EmailConfig.SendResolved, updated.EmailConfig.SendResolved)
assert.EqualValues(t, uParams.EmailConfig.SendResolved, updated.EmailConfig.SendResolved)
assert.Nil(t, updated.EmailConfig)
assert.Equal(t, uParams.SlackConfig.Channel, updated.SlackConfig.Channel)
assert.EqualValues(t, uParams.SlackConfig.SendResolved, updated.SlackConfig.SendResolved)

actual, err := models.FindChannelByID(q, created.ID)
require.NoError(t, err)
assert.Equal(t, updated.Type, actual.Type)
assert.Equal(t, updated.Summary, actual.Summary)
assert.Equal(t, updated.Disabled, actual.Disabled)
assert.Equal(t, updated.EmailConfig, actual.EmailConfig)
assert.Equal(t, updated, actual)
})

t.Run("remove", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions services/management/ia/channels_service.go
Expand Up @@ -142,6 +142,7 @@ func (s *ChannelsService) ChangeChannel(ctx context.Context, req *iav1beta1.Chan
}

params := &models.ChangeChannelParams{
Summary: req.Summary,
Disabled: req.Disabled,
}

Expand Down
5 changes: 3 additions & 2 deletions services/management/ia/common.go
Expand Up @@ -31,10 +31,11 @@ import (
)

func convertParamUnit(u string) iav1beta1.ParamUnit {
// TODO: check possible variants.
switch strings.ToLower(u) {
case "%", "percentage":
case "%":
return iav1beta1.ParamUnit_PERCENTAGE
case "s":
return iav1beta1.ParamUnit_SECONDS
default:
return iav1beta1.ParamUnit_PARAM_UNIT_INVALID
}
Expand Down
136 changes: 73 additions & 63 deletions vendor/github.com/percona/pmm/api/managementpb/ia/channels.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit acb22f6

Please sign in to comment.