provider/mesh: filter deleted silences from results

This commit is contained in:
Fabian Reinartz 2016-06-24 15:50:10 +02:00
parent 022adbff36
commit c0103dd8c6
2 changed files with 10 additions and 2 deletions

View File

@ -174,7 +174,9 @@ func (s *Silences) All() ([]*types.Silence, error) {
res := make([]*types.Silence, 0, len(s.st.m))
for _, sil := range s.st.m {
res = append(res, sil)
if !sil.Deleted() {
res = append(res, sil)
}
}
return res, nil
}
@ -225,7 +227,7 @@ func (s *Silences) Get(id uuid.UUID) (*types.Silence, error) {
defer s.st.mtx.RUnlock()
sil, ok := s.st.m[id]
if !ok {
if !ok || sil.Deleted() {
return nil, provider.ErrNotFound
}
// TODO(fabxc): ensure that silence objects are never modified; just replaced.

View File

@ -298,6 +298,12 @@ func (s *Silence) Mutes(lset model.LabelSet) bool {
return s.Matchers.Match(lset)
}
// Returns whether a silence is deleted. Semantically this means it had no effect
// on history at any point.
func (s *Silence) Deleted() bool {
return s.StartsAt.Equal(s.EndsAt)
}
// NotifyInfo holds information about the last successful notification
// of an alert to a receiver.
type NotifyInfo struct {