From 3c8e9be489ce12396b7a53d797b276b11b9aafc2 Mon Sep 17 00:00:00 2001 From: stuart nelson Date: Thu, 25 Aug 2016 11:26:15 +0200 Subject: [PATCH] Remove All() interface method It's being removed in a future release and wasn't being used here anyway. --- provider/boltmem/boltmem.go | 10 ++--- provider/boltmem/boltmem_test.go | 71 -------------------------------- provider/provider.go | 2 - 3 files changed, 4 insertions(+), 79 deletions(-) diff --git a/provider/boltmem/boltmem.go b/provider/boltmem/boltmem.go index 48cd531b..242eaa7f 100644 --- a/provider/boltmem/boltmem.go +++ b/provider/boltmem/boltmem.go @@ -241,7 +241,10 @@ func (s *Silences) Close() error { // for all its silences. The data provider may have access to an // optimized view of the data to perform this evaluation. func (s *Silences) Mutes(lset model.LabelSet) bool { - resp, err := s.All() + s.mtx.RLock() + defer s.mtx.RUnlock() + + resp, err := s.Query(uint(len(s.sils)), 0, types.ByEndsAt) if err != nil { log.Errorf("retrieving silences failed: %s", err) // In doubt, do not silence anything. @@ -259,11 +262,6 @@ func (s *Silences) Mutes(lset model.LabelSet) bool { return false } -// All returns all existing silences. -func (s *Silences) All() (*types.SilencesQueryResponse, error) { - return s.Query(uint(len(s.sils)), 0, types.ByCreatedAt) -} - // Query returns at most limit silences starting at offset. func (s *Silences) Query(limit, offset uint, fn types.SilencesLessFunc) (*types.SilencesQueryResponse, error) { s.mtx.RLock() diff --git a/provider/boltmem/boltmem_test.go b/provider/boltmem/boltmem_test.go index 1f557f63..4d63465f 100644 --- a/provider/boltmem/boltmem_test.go +++ b/provider/boltmem/boltmem_test.go @@ -207,77 +207,6 @@ func TestSilencesDelete(t *testing.T) { } } -func TestSilencesAll(t *testing.T) { - var ( - t0 = time.Now() - t1 = t0.Add(10 * time.Minute) - t2 = t0.Add(20 * time.Minute) - t3 = t0.Add(30 * time.Minute) - ) - - insert := []*types.Silence{ - types.NewSilence(&model.Silence{ - Matchers: []*model.Matcher{ - {Name: "key", Value: "val"}, - }, - StartsAt: t0, - EndsAt: t2, - CreatedAt: t1, - CreatedBy: "user", - Comment: "test comment", - }), - types.NewSilence(&model.Silence{ - Matchers: []*model.Matcher{ - {Name: "key", Value: "val"}, - {Name: "key2", Value: "val2.*", IsRegex: true}, - }, - StartsAt: t1, - EndsAt: t2, - CreatedAt: t1, - CreatedBy: "user2", - Comment: "test comment", - }), - types.NewSilence(&model.Silence{ - Matchers: []*model.Matcher{ - {Name: "key", Value: "val"}, - }, - StartsAt: t2, - EndsAt: t3, - CreatedAt: t3, - CreatedBy: "user", - Comment: "another test comment", - }), - } - - dir, err := ioutil.TempDir("", "silences_test") - if err != nil { - t.Fatal(err) - } - - silences, err := NewSilences(dir, nil) - if err != nil { - t.Fatal(err) - } - - for _, sil := range insert { - uid, err := silences.Set(sil) - if err != nil { - t.Fatalf("Insert failed: %s", err) - } - sil.ID = uid - } - - res, err := silences.All() - if err != nil { - t.Fatalf("Retrieval failed: %s", err) - } - - if silenceListEqual(res.Silences, insert) { - t.Errorf("Unexpected result") - t.Fatalf(pretty.Compare(res, insert)) - } -} - func TestSilencesMutes(t *testing.T) { var ( t0 = time.Now() diff --git a/provider/provider.go b/provider/provider.go index d4c39d0f..e3c79e3b 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -94,8 +94,6 @@ type Silences interface { // optimized view of the data to perform this evaluation. types.Muter - // All returns all existing silences. - All() (*types.SilencesQueryResponse, error) // Set a new silence. Set(*types.Silence) (uint64, error) // Del removes a silence.