Files
karma/timer.go
Łukasz Mierzwa 26d14d1bd2 Refactor Alertmanager API client code to use multiple upstream instances
Alerts are stored per instance and deduplicated on read.
2017-06-28 22:35:16 -07:00

48 lines
847 B
Go

package main
import (
"runtime"
"sync"
"github.com/cloudflare/unsee/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 {
select {
case <-ticker.C:
pullFromAlertmanager()
}
}
}