mirror of
https://github.com/prometheus/alertmanager
synced 2025-02-25 23:30:55 +00:00
Correcting the condition for updating a silence. Earlier was checking upto
nanosecond precision but reduced to second as the UI only sends upto millisecond Signed-off-by: Prashant Balachandran <pnair@redhat.com>
This commit is contained in:
parent
4dcc0d9563
commit
66182178d0
@ -586,7 +586,7 @@ func canUpdate(a, b *pb.Silence, now time.Time) bool {
|
|||||||
// Allowed timestamp modifications depend on the current time.
|
// Allowed timestamp modifications depend on the current time.
|
||||||
switch st := getState(a, now); st {
|
switch st := getState(a, now); st {
|
||||||
case types.SilenceStateActive:
|
case types.SilenceStateActive:
|
||||||
if !b.StartsAt.Equal(a.StartsAt) {
|
if b.StartsAt.Unix() != a.StartsAt.Unix() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if b.EndsAt.Before(now) {
|
if b.EndsAt.Before(now) {
|
||||||
|
@ -362,7 +362,6 @@ func TestSilenceSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
require.Equal(t, want, s.st, "unexpected state after silence creation")
|
require.Equal(t, want, s.st, "unexpected state after silence creation")
|
||||||
|
|
||||||
// Update silence 2 with new matcher expires it and creates a new one.
|
// Update silence 2 with new matcher expires it and creates a new one.
|
||||||
now = now.Add(time.Minute)
|
now = now.Add(time.Minute)
|
||||||
now4 := now
|
now4 := now
|
||||||
@ -429,6 +428,55 @@ func TestSilenceSet(t *testing.T) {
|
|||||||
require.Equal(t, want, s.st, "unexpected state after silence creation")
|
require.Equal(t, want, s.st, "unexpected state after silence creation")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetActiveSilence(t *testing.T) {
|
||||||
|
s, err := New(Options{
|
||||||
|
Retention: time.Hour,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
now := utcNow()
|
||||||
|
s.now = func() time.Time { return now }
|
||||||
|
|
||||||
|
startsAt := now.Add(-1 * time.Minute)
|
||||||
|
endsAt := now.Add(5 * time.Minute)
|
||||||
|
// Insert silence with fixed start time.
|
||||||
|
sil1 := &pb.Silence{
|
||||||
|
Matchers: []*pb.Matcher{{Name: "a", Pattern: "b"}},
|
||||||
|
StartsAt: startsAt,
|
||||||
|
EndsAt: endsAt,
|
||||||
|
}
|
||||||
|
id1, _ := s.Set(sil1)
|
||||||
|
|
||||||
|
// Update silence with 2 extra nanoseconds so the "seconds" part should not change
|
||||||
|
|
||||||
|
newStartsAt := now.Add(2 * time.Nanosecond)
|
||||||
|
newEndsAt := endsAt.Add(2 * time.Minute)
|
||||||
|
|
||||||
|
sil2 := cloneSilence(sil1)
|
||||||
|
sil2.Id = id1
|
||||||
|
sil2.StartsAt = newStartsAt
|
||||||
|
sil2.EndsAt = newEndsAt
|
||||||
|
|
||||||
|
now = now.Add(time.Minute)
|
||||||
|
id2, err := s.Set(sil2)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, id1, id2)
|
||||||
|
|
||||||
|
want := state{
|
||||||
|
id2: &pb.MeshSilence{
|
||||||
|
Silence: &pb.Silence{
|
||||||
|
Id: id1,
|
||||||
|
Matchers: []*pb.Matcher{{Name: "a", Pattern: "b"}},
|
||||||
|
StartsAt: newStartsAt,
|
||||||
|
EndsAt: newEndsAt,
|
||||||
|
UpdatedAt: now,
|
||||||
|
},
|
||||||
|
ExpiresAt: newEndsAt.Add(s.retention),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.Equal(t, want, s.st, "unexpected state after silence creation")
|
||||||
|
}
|
||||||
|
|
||||||
func TestSilencesSetFail(t *testing.T) {
|
func TestSilencesSetFail(t *testing.T) {
|
||||||
s, err := New(Options{})
|
s, err := New(Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user