fix(backend): ensure alertmanager server uses default name if not set

Fixes #1646
This commit is contained in:
Łukasz Mierzwa
2020-04-20 15:36:35 +01:00
committed by Łukasz Mierzwa
parent 5f5ee9eb63
commit 1e787e0c9c
3 changed files with 24 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
# Raises an error if we have 2 instances with the same name (one using default name)
karma.bin-should-fail --log.format=text --log.config=false --log.level=error --config.file=karma.yaml
! stdout .
stderr 'msg="Failed to register Alertmanager ''default'' with URI ''https://localhost:9094'': alertmanager upstream ''default'' already exist"'
-- karma.yaml --
alertmanager:
servers:
- name: default
uri: https://localhost:9093
- uri: https://localhost:9094

View File

@@ -0,0 +1,10 @@
# Uses 'default' as the default alertmanager name
karma.bin-should-work --log.format=text --log.config=false --config.file=karma.yaml --check-config
! stdout .
stderr 'msg="\[default\] Configured Alertmanager source at http://localhost:9093 \(proxied: false\, readonly: false\)"'
! stderr 'level=error'
-- karma.yaml --
alertmanager:
servers:
- uri: http://localhost:9093

View File

@@ -269,6 +269,9 @@ func (config *configSchema) Read(flags *pflag.FlagSet) string {
}
for i, s := range config.Alertmanager.Servers {
if s.Name == "" {
config.Alertmanager.Servers[i].Name = "default"
}
if s.Timeout.Seconds() == 0 {
config.Alertmanager.Servers[i].Timeout = config.Alertmanager.Timeout
}