Skip to content

Commit f61a4d2

Browse files
fix flaky retention tests (#4697) (#4698)
(cherry picked from commit 20726e6) Co-authored-by: Sandeep Sukhani <[email protected]>
1 parent 56792bb commit f61a4d2

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

pkg/storage/stores/shipper/compactor/retention/retention_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) {
462462
{
463463
name: "no chunk and series deleted",
464464
chunks: []chunk.Chunk{
465-
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now),
465+
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)),
466466
},
467467
expiry: []chunkExpiry{
468468
{
@@ -482,7 +482,7 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) {
482482
{
483483
name: "only one chunk in store which gets deleted",
484484
chunks: []chunk.Chunk{
485-
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now),
485+
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)),
486486
},
487487
expiry: []chunkExpiry{
488488
{
@@ -502,14 +502,14 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) {
502502
{
503503
name: "only one chunk in store which gets partially deleted",
504504
chunks: []chunk.Chunk{
505-
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now),
505+
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)),
506506
},
507507
expiry: []chunkExpiry{
508508
{
509509
isExpired: true,
510510
nonDeletedIntervals: []model.Interval{{
511-
Start: now.Add(-15 * time.Minute),
512-
End: now,
511+
Start: todaysTableInterval.Start,
512+
End: todaysTableInterval.Start.Add(15 * time.Minute),
513513
}},
514514
},
515515
},
@@ -526,8 +526,8 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) {
526526
{
527527
name: "one of two chunks deleted",
528528
chunks: []chunk.Chunk{
529-
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now),
530-
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "2"}}, now.Add(-30*time.Minute), now),
529+
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)),
530+
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "2"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)),
531531
},
532532
expiry: []chunkExpiry{
533533
{
@@ -550,8 +550,8 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) {
550550
{
551551
name: "one of two chunks partially deleted",
552552
chunks: []chunk.Chunk{
553-
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, now.Add(-30*time.Minute), now),
554-
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "2"}}, now.Add(-30*time.Minute), now),
553+
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "1"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)),
554+
createChunk(t, userID, labels.Labels{labels.Label{Name: "foo", Value: "2"}}, todaysTableInterval.Start, todaysTableInterval.Start.Add(30*time.Minute)),
555555
},
556556
expiry: []chunkExpiry{
557557
{
@@ -560,8 +560,8 @@ func TestMarkForDelete_SeriesCleanup(t *testing.T) {
560560
{
561561
isExpired: true,
562562
nonDeletedIntervals: []model.Interval{{
563-
Start: now.Add(-15 * time.Minute),
564-
End: now,
563+
Start: todaysTableInterval.Start,
564+
End: todaysTableInterval.Start.Add(15 * time.Minute),
565565
}},
566566
},
567567
},

pkg/storage/stores/shipper/compactor/retention/util_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
)
3030

3131
func dayFromTime(t model.Time) chunk.DayTime {
32-
parsed, err := time.Parse("2006-01-02", t.Time().Format("2006-01-02"))
32+
parsed, err := time.Parse("2006-01-02", t.Time().In(time.UTC).Format("2006-01-02"))
3333
if err != nil {
3434
panic(err)
3535
}

0 commit comments

Comments
 (0)