@@ -2,6 +2,8 @@ package ruler
2
2
3
3
import (
4
4
native_ctx "context"
5
+ "crypto/md5"
6
+ "encoding/json"
5
7
"flag"
6
8
"fmt"
7
9
"net/http"
@@ -133,9 +135,11 @@ func (rn *rulerNotifier) run() {
133
135
if err := rn .sdManager .Run (rn .sdCtx ); err != nil {
134
136
level .Error (rn .logger ).Log ("msg" , "error starting notifier discovery manager" , "err" , err )
135
137
}
138
+ rn .wg .Done ()
136
139
}()
137
140
go func () {
138
141
rn .notifier .Run (rn .sdManager .SyncCh ())
142
+ rn .wg .Done ()
139
143
}()
140
144
}
141
145
@@ -144,13 +148,19 @@ func (rn *rulerNotifier) applyConfig(cfg *config.Config) error {
144
148
return err
145
149
}
146
150
147
- amConfigs := cfg .AlertingConfig .AlertmanagerConfigs
148
- if len (amConfigs ) != 1 {
149
- return fmt .Errorf ("ruler alerting config should have exactly one AlertmanagerConfig" )
151
+ sdCfgs := make (map [string ]sd_config.ServiceDiscoveryConfig )
152
+ for _ , v := range cfg .AlertingConfig .AlertmanagerConfigs {
153
+ // AlertmanagerConfigs doesn't hold an unique identifier so we use the config hash as the identifier.
154
+ b , err := json .Marshal (v )
155
+ if err != nil {
156
+ return err
157
+ }
158
+ // This hash needs to be identical to the one computed in the notifier in
159
+ // https://github.com/prometheus/prometheus/blob/719c579f7b917b384c3d629752dea026513317dc/notifier/notifier.go#L265
160
+ // This kind of sucks, but it's done in Prometheus in main.go in the same way.
161
+ sdCfgs [fmt .Sprintf ("%x" , md5 .Sum (b ))] = v .ServiceDiscoveryConfig
150
162
}
151
- return rn .sdManager .ApplyConfig (
152
- map [string ]sd_config.ServiceDiscoveryConfig {"ruler" : amConfigs [0 ].ServiceDiscoveryConfig },
153
- )
163
+ return rn .sdManager .ApplyConfig (sdCfgs )
154
164
}
155
165
156
166
func (rn * rulerNotifier ) stop () {
0 commit comments