From f03c45406cae0e5dd519068630efe9cb1cb5b762 Mon Sep 17 00:00:00 2001 From: Filippo Giunchedi Date: Wed, 25 Nov 2020 11:45:40 +0100 Subject: [PATCH] Make alert channel size configurable (and bigger) Signed-off-by: Filippo Giunchedi --- README.md | 3 +++ config.go | 56 ++++++++++++++++++++++++++------------------------ config_test.go | 23 +++++++++++---------- main.go | 2 +- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index c504f93..dedd17a 100644 --- a/README.md +++ b/README.md @@ -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 # msg_template is set to # "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): diff --git a/config.go b/config.go index e554a82..0fa2fad 100644 --- a/config.go +++ b/config.go @@ -31,37 +31,39 @@ type IRCChannel struct { } type Config struct { - HTTPHost string `yaml:"http_host"` - HTTPPort int `yaml:"http_port"` - IRCNick string `yaml:"irc_nickname"` - IRCNickPass string `yaml:"irc_nickname_password"` - IRCRealName string `yaml:"irc_realname"` - IRCHost string `yaml:"irc_host"` - IRCPort int `yaml:"irc_port"` - IRCHostPass string `yaml:"irc_host_password"` - IRCUseSSL bool `yaml:"irc_use_ssl"` - IRCVerifySSL bool `yaml:"irc_verify_ssl"` - IRCChannels []IRCChannel `yaml:"irc_channels"` - MsgTemplate string `yaml:"msg_template"` - MsgOnce bool `yaml:"msg_once_per_alert_group"` - UsePrivmsg bool `yaml:"use_privmsg"` + HTTPHost string `yaml:"http_host"` + HTTPPort int `yaml:"http_port"` + IRCNick string `yaml:"irc_nickname"` + IRCNickPass string `yaml:"irc_nickname_password"` + IRCRealName string `yaml:"irc_realname"` + IRCHost string `yaml:"irc_host"` + IRCPort int `yaml:"irc_port"` + IRCHostPass string `yaml:"irc_host_password"` + IRCUseSSL bool `yaml:"irc_use_ssl"` + IRCVerifySSL bool `yaml:"irc_verify_ssl"` + IRCChannels []IRCChannel `yaml:"irc_channels"` + MsgTemplate string `yaml:"msg_template"` + MsgOnce bool `yaml:"msg_once_per_alert_group"` + UsePrivmsg bool `yaml:"use_privmsg"` + AlertBufferSize int `yaml:"alert_buffer_size"` } func LoadConfig(configFile string) (*Config, error) { config := &Config{ - HTTPHost: "localhost", - HTTPPort: 8000, - IRCNick: "alertmanager-irc-relay", - IRCNickPass: "", - IRCRealName: "Alertmanager IRC Relay", - IRCHost: "example.com", - IRCPort: 7000, - IRCHostPass: "", - IRCUseSSL: true, - IRCVerifySSL: true, - IRCChannels: []IRCChannel{}, - MsgOnce: false, - UsePrivmsg: false, + HTTPHost: "localhost", + HTTPPort: 8000, + IRCNick: "alertmanager-irc-relay", + IRCNickPass: "", + IRCRealName: "Alertmanager IRC Relay", + IRCHost: "example.com", + IRCPort: 7000, + IRCHostPass: "", + IRCUseSSL: true, + IRCVerifySSL: true, + IRCChannels: []IRCChannel{}, + MsgOnce: false, + UsePrivmsg: false, + AlertBufferSize: 2048, } if configFile != "" { diff --git a/config_test.go b/config_test.go index a029c37..486d09c 100644 --- a/config_test.go +++ b/config_test.go @@ -35,17 +35,18 @@ func TestNoConfig(t *testing.T) { func TestLoadGoodConfig(t *testing.T) { expectedConfig := &Config{ - HTTPHost: "test.web", - HTTPPort: 8888, - IRCNick: "foo", - IRCHost: "irc.example.com", - IRCPort: 1234, - IRCHostPass: "hostsecret", - IRCUseSSL: true, - IRCChannels: []IRCChannel{IRCChannel{Name: "#foobar"}}, - MsgTemplate: defaultMsgTemplate, - MsgOnce: false, - UsePrivmsg: false, + HTTPHost: "test.web", + HTTPPort: 8888, + IRCNick: "foo", + IRCHost: "irc.example.com", + IRCPort: 1234, + IRCHostPass: "hostsecret", + IRCUseSSL: true, + IRCChannels: []IRCChannel{IRCChannel{Name: "#foobar"}}, + MsgTemplate: defaultMsgTemplate, + MsgOnce: false, + UsePrivmsg: false, + AlertBufferSize: 666, } expectedData, err := yaml.Marshal(expectedConfig) if err != nil { diff --git a/main.go b/main.go index a4e1f82..d198042 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,7 @@ func main() { return } - alertMsgs := make(chan AlertMsg, 10) + alertMsgs := make(chan AlertMsg, config.AlertBufferSize) ircNotifier, err := NewIRCNotifier(config, alertMsgs) if err != nil {