Skip to content

Commit

Permalink
pkg/alertmanger: remove changes for telegram bot_toke_file
Browse files Browse the repository at this point in the history
The telegram bot_token_file is already handle in prometheus-operator#5882
  • Loading branch information
Hendrik Ferber committed Sep 4, 2023
1 parent 764a6cd commit 8d02a0c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 102 deletions.
14 changes: 1 addition & 13 deletions pkg/alertmanager/amcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2030,26 +2030,14 @@ func (tc *telegramConfig) sanitize(amVersion semver.Version, logger log.Logger)
return fmt.Errorf(`invalid syntax in receivers config; telegram integration is available in Alertmanager >= 0.24.0`)
}

if tc.BotTokenFile != "" && amVersion.LT(semver.MustParse("0.26.0")) {
msg := "'bot_token_file' supported in Alertmanager >= 0.26.0 only - dropping field from provided config"
level.Warn(logger).Log("msg", msg, "current_version", amVersion.String())
tc.BotTokenFile = ""
}

if tc.ChatID == 0 {
return errors.Errorf("mandatory field %q is empty", "chatID")
}

if tc.BotToken == "" && amVersion.LT(semver.MustParse("0.26.0")) {
if tc.BotToken == "" {
return fmt.Errorf("mandatory field %q is empty", "BotToken")
}

if tc.BotToken != "" && tc.BotTokenFile != "" {
msg := "'bot_token' and 'bot_toke_file' are mutually exclusive for telegram receiver config - 'bot_token' has taken precedence"
level.Warn(logger).Log("msg", msg)
tc.BotTokenFile = ""
}

return tc.HTTPConfig.sanitize(amVersion, logger)
}

Expand Down
88 changes: 0 additions & 88 deletions pkg/alertmanager/amcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3199,94 +3199,6 @@ func TestSanitizePushoverConfig(t *testing.T) {
}
}

func TestSanitizeTelegramConfig(t *testing.T) {
logger := log.NewNopLogger()

for _, tc := range []struct {
name string
againstVersion semver.Version
in *alertmanagerConfig
expect alertmanagerConfig
expectErr bool
}{
{
name: "Test telegram_bot_token_file is dropped in telegram config for unsupported versions",
againstVersion: semver.Version{Major: 0, Minor: 25},
in: &alertmanagerConfig{
Receivers: []*receiver{
{
TelegramConfigs: []*telegramConfig{
{
BotTokenFile: "foo",
BotToken: "bar",
ChatID: 123,
},
},
},
},
},
expect: alertmanagerConfig{
Receivers: []*receiver{
{
TelegramConfigs: []*telegramConfig{
{
BotTokenFile: "",
BotToken: "bar",
ChatID: 123,
},
},
},
},
},
},
{
name: "Test bot_token takes precedence in telegram config",
againstVersion: semver.Version{Major: 0, Minor: 26},
in: &alertmanagerConfig{
Receivers: []*receiver{
{
TelegramConfigs: []*telegramConfig{
{
BotToken: "foo",
BotTokenFile: "bar",
ChatID: 123,
},
},
},
},
},
expect: alertmanagerConfig{
Receivers: []*receiver{
{
TelegramConfigs: []*telegramConfig{
{
BotToken: "foo",
ChatID: 123,
},
},
},
},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
err := tc.in.sanitize(tc.againstVersion, logger)
if tc.expectErr {
if err == nil {
t.Fatal("expected error but got none")
}
return
}

if err != nil {
t.Fatalf("expected no error but got: %q", err)
}

require.Equal(t, tc.expect, *tc.in)
})
}
}

func TestSanitizePagerDutyConfig(t *testing.T) {
logger := log.NewNopLogger()

Expand Down
1 change: 0 additions & 1 deletion pkg/alertmanager/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ type telegramConfig struct {
VSendResolved *bool `yaml:"send_resolved,omitempty" json:"send_resolved,omitempty"`
APIUrl string `yaml:"api_url,omitempty" json:"api_url,omitempty"`
BotToken string `yaml:"bot_token,omitempty" json:"bot_token,omitempty"`
BotTokenFile string `yaml:"bot_token_file,omitempty" json:"bot_token_file,omitempty"`
ChatID int64 `yaml:"chat_id,omitempty" json:"chat_id,omitempty"`
Message string `yaml:"message,omitempty" json:"message,omitempty"`
DisableNotifications bool `yaml:"disable_notifications,omitempty" json:"disable_notifications,omitempty"`
Expand Down

0 comments on commit 8d02a0c

Please sign in to comment.