diff --git a/retrieval/targetpool_test.go b/retrieval/targetpool_test.go index 1e8005f27..f22185ff3 100644 --- a/retrieval/targetpool_test.go +++ b/retrieval/targetpool_test.go @@ -91,11 +91,8 @@ func testTargetPool(t testing.TB) { t.Errorf("%s %d. expected TargetPool size to be %d but was %d", scenario.name, i, len(scenario.outputs), len(pool.targetsByAddress)) } else { for j, output := range scenario.outputs { - target := pool.Targets()[j] - - if target.Address() != output.address { + if target, ok := pool.targetsByAddress[output.address]; !ok { t.Errorf("%s %d.%d. expected Target address to be %s but was %s", scenario.name, i, j, output.address, target.Address()) - } } diff --git a/rules/helpers_test.go b/rules/helpers_test.go index 72bfeb36c..aaf249056 100644 --- a/rules/helpers_test.go +++ b/rules/helpers_test.go @@ -64,6 +64,7 @@ func storeMatrix(storage local.Storage, matrix ast.Matrix) { } } storage.AppendSamples(pendingSamples) + storage.WaitForIndexing() } var testMatrix = ast.Matrix{ diff --git a/storage/local/interface.go b/storage/local/interface.go index 81b17de63..69ae6b793 100644 --- a/storage/local/interface.go +++ b/storage/local/interface.go @@ -44,6 +44,10 @@ type Storage interface { Serve(started chan<- bool) // Close the MetricsStorage and releases all resources. Close() error + // WaitForIndexing returns once all samples in the storage are + // indexed. Indexing is needed for GetFingerprintsForLabelMatchers and + // GetLabelValuesForLabelName and may lag behind. + WaitForIndexing() } // SeriesIterator enables efficient access of sample values in a series. All diff --git a/storage/local/series.go b/storage/local/series.go index efc10e54e..f756b7f86 100644 --- a/storage/local/series.go +++ b/storage/local/series.go @@ -533,6 +533,9 @@ func (it *memorySeriesIterator) GetValueAtTime(t clientmodel.Timestamp) metric.V // GetBoundaryValues implements SeriesIterator. func (it *memorySeriesIterator) GetBoundaryValues(in metric.Interval) metric.Values { + return it.GetRangeValues(in) + + // TODO: The following doesn't work as expected. Fix it. it.lock() defer it.unlock() diff --git a/storage/local/storage.go b/storage/local/storage.go index 738dbbf61..1c132b38b 100644 --- a/storage/local/storage.go +++ b/storage/local/storage.go @@ -238,6 +238,11 @@ func (s *memorySeriesStorage) handlePersistQueue() { s.persistDone <- true } +// WaitForIndexing implements Storage. +func (s *memorySeriesStorage) WaitForIndexing() { + s.persistence.waitForIndexing() +} + // Close stops serving, flushes all pending operations, and frees all // resources. It implements Storage. func (s *memorySeriesStorage) Close() error { diff --git a/templates/templates_test.go b/templates/templates_test.go index ae817aa14..2d371b6f1 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -168,8 +168,9 @@ func TestTemplateExpansion(t *testing.T) { Value: 21, }, }) + storage.WaitForIndexing() - for _, s := range scenarios { + for i, s := range scenarios { var result string var err error expander := NewTemplateExpander(s.text, "test", s.input, time, storage) @@ -180,16 +181,16 @@ func TestTemplateExpansion(t *testing.T) { } if s.shouldFail { if err == nil { - t.Fatalf("Error not returned from %v", s.text) + t.Fatalf("%d. Error not returned from %v", i, s.text) } continue } if err != nil { - t.Fatalf("Error returned from %v: %v", s.text, err) + t.Fatalf("%d. Error returned from %v: %v", i, s.text, err) continue } if result != s.output { - t.Fatalf("Error in result from %v: Expected '%v' Got '%v'", s.text, s.output, result) + t.Fatalf("%d. Error in result from %v: Expected '%v' Got '%v'", i, s.text, s.output, result) continue } }