forked from prymitive/karma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.go
44 lines (34 loc) · 835 Bytes
/
timer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"runtime"
"sync"
"github.com/prymitive/karma/internal/alertmanager"
log "github.com/sirupsen/logrus"
)
func pullFromAlertmanager() {
// always flush cache once we're done
defer apiCache.Flush()
log.Info("Pulling latest alerts and silences from Alertmanager")
upstreams := alertmanager.GetAlertmanagers()
wg := sync.WaitGroup{}
wg.Add(len(upstreams))
for _, upstream := range upstreams {
go func(am *alertmanager.Alertmanager) {
log.Infof("[%s] Collecting alerts and silences", am.Name)
err := am.Pull()
if err != nil {
log.Errorf("[%s] %s", am.Name, err)
}
wg.Done()
}(upstream)
}
wg.Wait()
log.Info("Pull completed")
runtime.GC()
}
// Tick is the background timer used to call PullFromAlertmanager
func Tick() {
for range ticker.C {
pullFromAlertmanager()
}
}