From 2f6899cbb8097cbbc645c39daccb36193a1b5694 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Tue, 1 Nov 2016 14:21:22 +0100 Subject: [PATCH 1/3] Add missing line to CHANGELOG.md This got dropped in the cherrypicking. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ce24f3a6b..16647293b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 1.2.2 / 2016-10-30 +* [BUGFIX] Correctly handle on() in alerts. * [BUGFIX] UI: Deal properly with aborted requests. * [BUGFIX] UI: Decode URL query parameters properly. * [BUGFIX] Storage: Deal better with data corruption (non-monotonic timestamps). From c5bd178b930207362a425889c155ac8ca86628e3 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Tue, 1 Nov 2016 15:05:01 +0100 Subject: [PATCH 2/3] Protect exported Querier interface method against negative time ranges --- storage/local/storage.go | 7 +++++++ storage/local/storage_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/storage/local/storage.go b/storage/local/storage.go index 1288389e03..f05e52eaa3 100644 --- a/storage/local/storage.go +++ b/storage/local/storage.go @@ -480,6 +480,10 @@ func (bit *boundedIterator) Close() { // QueryRange implements Storage. func (s *MemorySeriesStorage) QueryRange(_ context.Context, from, through model.Time, matchers ...*metric.LabelMatcher) ([]SeriesIterator, error) { + if through.Before(from) { + // In that case, nothing will match. + return nil, nil + } fpSeriesPairs, err := s.seriesForLabelMatchers(from, through, matchers...) if err != nil { return nil, err @@ -494,6 +498,9 @@ func (s *MemorySeriesStorage) QueryRange(_ context.Context, from, through model. // QueryInstant implements Storage. func (s *MemorySeriesStorage) QueryInstant(_ context.Context, ts model.Time, stalenessDelta time.Duration, matchers ...*metric.LabelMatcher) ([]SeriesIterator, error) { + if stalenessDelta < 0 { + panic("negative staleness delta") + } from := ts.Add(-stalenessDelta) through := ts diff --git a/storage/local/storage_test.go b/storage/local/storage_test.go index e3b31620b2..fc72b44b3f 100644 --- a/storage/local/storage_test.go +++ b/storage/local/storage_test.go @@ -504,6 +504,39 @@ func BenchmarkQueryRange(b *testing.B) { }) } +func TestQueryRangeThroughBeforeFrom(t *testing.T) { + now := model.Now() + insertStart := now.Add(-2 * time.Hour) + + s, closer := NewTestStorage(t, 2) + defer closer.Close() + + // Stop maintenance loop to prevent actual purging. + close(s.loopStopping) + <-s.loopStopped + <-s.logThrottlingStopped + // Recreate channel to avoid panic when we really shut down. + s.loopStopping = make(chan struct{}) + + for i := 0; i < 8192; i++ { + s.Append(&model.Sample{ + Metric: model.Metric{"__name__": "testmetric", "job": "test"}, + Timestamp: insertStart.Add(time.Duration(i) * time.Second), + Value: model.SampleValue(rand.Float64()), + }) + } + s.WaitForIndexing() + + lm, _ := metric.NewLabelMatcher(metric.Equal, "job", "test") + iters, err := s.QueryRange(context.Background(), now.Add(-30*time.Minute), now.Add(-90*time.Minute), lm) + if err != nil { + t.Error(err) + } + if len(iters) != 0 { + t.Errorf("expected no iters to be returned, got %d", len(iters)) + } +} + func TestRetentionCutoff(t *testing.T) { now := model.Now() insertStart := now.Add(-2 * time.Hour) From 5c41ca84e5056d3cab46911c13f3e91128a612a9 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Tue, 1 Nov 2016 15:17:59 +0100 Subject: [PATCH 3/3] Catch negative staleness delta set on the command line --- cmd/prometheus/config.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/prometheus/config.go b/cmd/prometheus/config.go index 9e0f2eca12..879210827f 100644 --- a/cmd/prometheus/config.go +++ b/cmd/prometheus/config.go @@ -262,6 +262,10 @@ func parse(args []string) error { return err } + if promql.StalenessDelta < 0 { + return fmt.Errorf("negative staleness delta: %s", promql.StalenessDelta) + } + if err := parsePrometheusURL(); err != nil { return err }