mirror of https://github.com/prometheus/prometheus
use the config hash for the map lookup
parent
8369826808
commit
5260c650ec
|
@ -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)
|
||||||
},
|
},
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue