use the config hash for the map lookup

pull/3638/head
Krasi Georgiev 2018-01-16 11:10:54 +00:00
parent 8369826808
commit 5260c650ec
2 changed files with 15 additions and 6 deletions

View File

@ -16,6 +16,8 @@ package main
import ( import (
"context" "context"
"crypto/md5"
"encoding/json"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
@ -295,9 +297,12 @@ func main() {
func(cfg *config.Config) error { func(cfg *config.Config) error {
c := make(map[string]sd_config.ServiceDiscoveryConfig) c := make(map[string]sd_config.ServiceDiscoveryConfig)
for _, v := range cfg.AlertingConfig.AlertmanagerConfigs { for _, v := range cfg.AlertingConfig.AlertmanagerConfigs {
// AlertmanagerConfigs doesn't hold an unique identifier so we use the config pointer as the identifier. // AlertmanagerConfigs doesn't hold an unique identifier so we use the config hash as the identifier.
// TODO Krasi - Maybe use the slice index as the reference. b, err := json.Marshal(v)
c[fmt.Sprintf("%p", v)] = v.ServiceDiscoveryConfig if err != nil {
return err
}
c[fmt.Sprintf("%x", md5.Sum(b))] = v.ServiceDiscoveryConfig
} }
return discoveryManagerNotify.ApplyConfig(c) return discoveryManagerNotify.ApplyConfig(c)
}, },

View File

@ -16,6 +16,7 @@ package notifier
import ( import (
"bytes" "bytes"
"context" "context"
"crypto/md5"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net" "net"
@ -256,9 +257,12 @@ func (n *Notifier) ApplyConfig(conf *config.Config) error {
ams.metrics = n.metrics ams.metrics = n.metrics
// The config pointer is used for the map lookup identifier. // The config hash is used for the map lookup identifier.
// TODO Krasi - Maybe use the slice index as the reference. b, err := json.Marshal(cfg)
amSets[fmt.Sprintf("%p", cfg)] = ams if err != nil {
return err
}
amSets[fmt.Sprintf("%x", md5.Sum(b))] = ams
} }
n.alertmanagers = amSets n.alertmanagers = amSets