Merge pull request #11 from filippog/alerts-channel

Make alert channel size configurable (and bigger)
This commit is contained in:
Luca Bigliardi 2020-11-25 17:19:55 +01:00 committed by GitHub
commit 1ef886d2e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 39 deletions

View File

@ -63,6 +63,9 @@ msg_template: "Alert {{ .Labels.alertname }} on {{ .Labels.instance }} is {{ .St
# Note: When sending only one message per alert group the default # Note: When sending only one message per alert group the default
# msg_template is set to # msg_template is set to
# "Alert {{ .GroupLabels.alertname }} for {{ .GroupLabels.job }} is {{ .Status }}" # "Alert {{ .GroupLabels.alertname }} for {{ .GroupLabels.job }} is {{ .Status }}"
# Set the internal buffer size for alerts received but not yet sent to IRC.
alert_buffer_size: 2048
``` ```
Running the bot (assuming *$GOPATH* and *$PATH* are properly setup for go): Running the bot (assuming *$GOPATH* and *$PATH* are properly setup for go):

View File

@ -45,6 +45,7 @@ type Config struct {
MsgTemplate string `yaml:"msg_template"` MsgTemplate string `yaml:"msg_template"`
MsgOnce bool `yaml:"msg_once_per_alert_group"` MsgOnce bool `yaml:"msg_once_per_alert_group"`
UsePrivmsg bool `yaml:"use_privmsg"` UsePrivmsg bool `yaml:"use_privmsg"`
AlertBufferSize int `yaml:"alert_buffer_size"`
} }
func LoadConfig(configFile string) (*Config, error) { func LoadConfig(configFile string) (*Config, error) {
@ -62,6 +63,7 @@ func LoadConfig(configFile string) (*Config, error) {
IRCChannels: []IRCChannel{}, IRCChannels: []IRCChannel{},
MsgOnce: false, MsgOnce: false,
UsePrivmsg: false, UsePrivmsg: false,
AlertBufferSize: 2048,
} }
if configFile != "" { if configFile != "" {

View File

@ -46,6 +46,7 @@ func TestLoadGoodConfig(t *testing.T) {
MsgTemplate: defaultMsgTemplate, MsgTemplate: defaultMsgTemplate,
MsgOnce: false, MsgOnce: false,
UsePrivmsg: false, UsePrivmsg: false,
AlertBufferSize: 666,
} }
expectedData, err := yaml.Marshal(expectedConfig) expectedData, err := yaml.Marshal(expectedConfig)
if err != nil { if err != nil {

View File

@ -37,7 +37,7 @@ func main() {
return return
} }
alertMsgs := make(chan AlertMsg, 10) alertMsgs := make(chan AlertMsg, config.AlertBufferSize)
ircNotifier, err := NewIRCNotifier(config, alertMsgs) ircNotifier, err := NewIRCNotifier(config, alertMsgs)
if err != nil { if err != nil {