Correctly call default silence maintenance function (#2701)

https://github.com/prometheus/alertmanager/pull/2689 introduced a
regression where the default maintenance function would no longer be
called even if no override was specified. The Alertmanager now crashes
on any silence maintenance run without this fix.

Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
Julius Volz 2021-09-13 16:12:48 +02:00 committed by GitHub
parent 44011410d7
commit 5195460c95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -378,7 +378,7 @@ func (s *Silences) Maintenance(interval time.Duration, snapf string, stopc <-cha
return size, f.Close()
}
if doMaintenance != nil {
if override != nil {
doMaintenance = override
}

View File

@ -180,6 +180,25 @@ func TestSilencesSnapshot(t *testing.T) {
}
}
// This tests a regression introduced by https://github.com/prometheus/alertmanager/pull/2689.
func TestSilences_Maintenance_DefaultMaintenanceFuncDoesntCrash(t *testing.T) {
f, err := ioutil.TempFile("", "snapshot")
require.NoError(t, err, "creating temp file failed")
s := &Silences{st: state{}, logger: log.NewNopLogger(), now: utcNow, metrics: newMetrics(nil, nil)}
stopc := make(chan struct{})
done := make(chan struct{})
go func() {
s.Maintenance(100*time.Millisecond, f.Name(), stopc, nil)
close(done)
}()
time.Sleep(200 * time.Millisecond)
close(stopc)
<-done
}
func TestSilences_Maintenance_SupportsCustomCallback(t *testing.T) {
f, err := ioutil.TempFile("", "snapshot")
require.NoError(t, err, "creating temp file failed")