From f61a4d2612d8fa3a385c90c363301ec05bab34d8 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Mon, 8 Nov 2021 05:21:14 -0700 Subject: [PATCH] fix flaky retention tests (#4697) (#4698) (cherry picked from commit 20726e6ba1a81f56a0bf0daa2ad3d51242fbcce5) Co-authored-by: Sandeep Sukhani --- .../compactor/retention/retention_test.go | 22 +++++++++---------- .../shipper/compactor/retention/util_test.go | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/storage/stores/shipper/compactor/retention/retention_test.go b/pkg/storage/stores/shipper/compactor/retention/retention_test.go index 0e64da614da64..de1dc2ff91411 100644 --- a/pkg/storage/stores/shipper/compactor/retention/retention_test.go +++ b/pkg/storage/stores/shipper/compactor/retention/retention_test.go @@ -462,7 +462,7 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) { { name: "no chunk and series deleted", chunks: []chunk.Chunk{ - createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now), + createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)), }, expiry: []chunkExpiry{ { @@ -482,7 +482,7 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) { { name: "only one chunk in store which gets deleted", chunks: []chunk.Chunk{ - createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now), + createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)), }, expiry: []chunkExpiry{ { @@ -502,14 +502,14 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) { { name: "only one chunk in store which gets partially deleted", chunks: []chunk.Chunk{ - createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now), + createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)), }, expiry: []chunkExpiry{ { isExpired: true, nonDeletedIntervals: []model.Interval{{ - Start: now.Add(-15 * time.Minute), - End: now, + Start: todaysTableInterval.Start, + End: todaysTableInterval.Start.Add(15 * time.Minute), }}, }, }, @@ -526,8 +526,8 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) { { name: "one of two chunks deleted", chunks: []chunk.Chunk{ - createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now), - createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "2"}}, now.Add(-30*time.Minute), now), + createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)), + createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "2"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)), }, expiry: []chunkExpiry{ { @@ -550,8 +550,8 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) { { name: "one of two chunks partially deleted", chunks: []chunk.Chunk{ - createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now), - createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "2"}}, now.Add(-30*time.Minute), now), + createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)), + createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "2"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)), }, expiry: []chunkExpiry{ { @@ -560,8 +560,8 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) { { isExpired: true, nonDeletedIntervals: []model.Interval{{ - Start: now.Add(-15 * time.Minute), - End: now, + Start: todaysTableInterval.Start, + End: todaysTableInterval.Start.Add(15 * time.Minute), }}, }, }, diff --git a/pkg/storage/stores/shipper/compactor/retention/util_test.go b/pkg/storage/stores/shipper/compactor/retention/util_test.go index 9ba7d2bfec682..1ad108e2ef897 100644 --- a/pkg/storage/stores/shipper/compactor/retention/util_test.go +++ b/pkg/storage/stores/shipper/compactor/retention/util_test.go @@ -29,7 +29,7 @@ import ( ) func dayFromTime(t model.Time) chunk.DayTime { - parsed, err := time.Parse("2006-01-02", t.Time().Format("2006-01-02")) + parsed, err := time.Parse("2006-01-02", t.Time().In(time.UTC).Format("2006-01-02")) if err != nil { panic(err) }