Shares #109
2 changed files with 19 additions and 3 deletions
|
@ -38,6 +38,7 @@ type Alerter interface {
|
|||
|
||||
Enabled() bool
|
||||
Go(context.Context)
|
||||
HUP(*config.Config)
|
||||
|
||||
stats
|
||||
}
|
||||
|
@ -101,9 +102,7 @@ func New(cfg config.Alerting, tgCache tgstore.Store, opts ...AlertOption) Alerte
|
|||
tgCache: tgCache,
|
||||
}
|
||||
|
||||
if cfg.Renotify != nil {
|
||||
as.renotify = cfg.Renotify.Duration()
|
||||
}
|
||||
as.reload()
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(as)
|
||||
|
@ -122,6 +121,21 @@ func New(cfg config.Alerting, tgCache tgstore.Store, opts ...AlertOption) Alerte
|
|||
return as
|
||||
}
|
||||
|
||||
func (as *alerter) reload() {
|
||||
if as.cfg.Renotify != nil {
|
||||
as.renotify = as.cfg.Renotify.Duration()
|
||||
}
|
||||
}
|
||||
|
||||
func (as *alerter) HUP(cfg *config.Config) {
|
||||
as.Lock()
|
||||
defer as.Unlock()
|
||||
|
||||
log.Debug().Msg("reloading alert config")
|
||||
as.cfg = cfg.Alerting
|
||||
as.reload()
|
||||
}
|
||||
|
||||
// Go is the alerting loop. It does not start a goroutine.
|
||||
func (as *alerter) Go(ctx context.Context) {
|
||||
ctx = entities.CtxWithSubject(ctx, &entities.SystemServiceSubject{Name: "alerter"})
|
||||
|
@ -381,3 +395,4 @@ func (*noopAlerter) SinkType() string { return "noopA
|
|||
func (*noopAlerter) Call(_ context.Context, _ *calls.Call) error { return nil }
|
||||
func (*noopAlerter) Go(_ context.Context) {}
|
||||
func (*noopAlerter) Enabled() bool { return false }
|
||||
func (*noopAlerter) HUP(_ *config.Config) { }
|
||||
|
|
|
@ -18,6 +18,7 @@ func (s *Server) huppers() []hupper {
|
|||
s.logger,
|
||||
s.auth,
|
||||
s.tgs,
|
||||
s.alerter,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue