use the config hash for the map lookup
This commit is contained in:
parent
8369826808
commit
5260c650ec
|
@ -16,6 +16,8 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
@ -295,9 +297,12 @@ func main() {
|
|||
func(cfg *config.Config) error {
|
||||
c := make(map[string]sd_config.ServiceDiscoveryConfig)
|
||||
for _, v := range cfg.AlertingConfig.AlertmanagerConfigs {
|
||||
// AlertmanagerConfigs doesn't hold an unique identifier so we use the config pointer as the identifier.
|
||||
// TODO Krasi - Maybe use the slice index as the reference.
|
||||
c[fmt.Sprintf("%p", v)] = v.ServiceDiscoveryConfig
|
||||
// AlertmanagerConfigs doesn't hold an unique identifier so we use the config hash as the identifier.
|
||||
b, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c[fmt.Sprintf("%x", md5.Sum(b))] = v.ServiceDiscoveryConfig
|
||||
}
|
||||
return discoveryManagerNotify.ApplyConfig(c)
|
||||
},
|
||||
|
|
|
@ -16,6 +16,7 @@ package notifier
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
|
@ -256,9 +257,12 @@ func (n *Notifier) ApplyConfig(conf *config.Config) error {
|
|||
|
||||
ams.metrics = n.metrics
|
||||
|
||||
// The config pointer is used for the map lookup identifier.
|
||||
// TODO Krasi - Maybe use the slice index as the reference.
|
||||
amSets[fmt.Sprintf("%p", cfg)] = ams
|
||||
// The config hash is used for the map lookup identifier.
|
||||
b, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
amSets[fmt.Sprintf("%x", md5.Sum(b))] = ams
|
||||
}
|
||||
|
||||
n.alertmanagers = amSets
|
||||
|
|
Loading…
Reference in New Issue