From f4df57f6f9dcbadc2fb069a9944aca8d863ff156 Mon Sep 17 00:00:00 2001 From: Filip Petkovski Date: Tue, 23 Apr 2024 11:32:01 +0200 Subject: [PATCH] Improve tests Signed-off-by: Filip Petkovski --- pkg/receive/multitsdb.go | 7 +------ pkg/receive/multitsdb_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pkg/receive/multitsdb.go b/pkg/receive/multitsdb.go index 3702ffd7a9..47ec4c2704 100644 --- a/pkg/receive/multitsdb.go +++ b/pkg/receive/multitsdb.go @@ -6,7 +6,6 @@ package receive import ( "context" "fmt" - "math" "os" "path" "path/filepath" @@ -440,11 +439,7 @@ func (t *MultiTSDB) pruneTSDB(ctx context.Context, logger log.Logger, tenantInst return false, err } - var tenantMinTimeMillis int64 = math.MaxInt64 - for _, b := range tdb.Blocks() { - tenantMinTimeMillis = min(b.MinTime(), tenantMinTimeMillis) - } - if time.Since(time.UnixMilli(tenantMinTimeMillis)).Milliseconds() <= t.tsdbOpts.RetentionDuration { + if sinceLastAppendMillis <= t.tsdbOpts.RetentionDuration { return false, nil } diff --git a/pkg/receive/multitsdb_test.go b/pkg/receive/multitsdb_test.go index c789916f39..6f5dd01ae7 100644 --- a/pkg/receive/multitsdb_test.go +++ b/pkg/receive/multitsdb_test.go @@ -454,10 +454,10 @@ func TestMultiTSDBPrune(t *testing.T) { ) defer func() { testutil.Ok(t, m.Close()) }() - for i := 0; i < 100; i++ { - testutil.Ok(t, appendSample(m, "deleted-tenant", time.Now().Add(-10*time.Hour))) - testutil.Ok(t, appendSample(m, "compacted-tenant", time.Now().Add(-4*time.Hour))) - testutil.Ok(t, appendSample(m, "active-tenant", time.Now().Add(time.Duration(i)*time.Second))) + for step := time.Duration(0); step <= 2*time.Hour; step += time.Minute { + testutil.Ok(t, appendSample(m, "deleted-tenant", time.Now().Add(-9*time.Hour+step))) + testutil.Ok(t, appendSample(m, "compacted-tenant", time.Now().Add(-4*time.Hour+step))) + testutil.Ok(t, appendSample(m, "active-tenant", time.Now().Add(step))) } testutil.Equals(t, 3, len(m.TSDBLocalClients()))