From 163bcc947f6e9df992c9792645bc84aa9d0bbb4d Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 26 Oct 2023 09:22:15 +0200 Subject: [PATCH] lib/storage: fix test TestStorageSeriesAreNotCreatedOnStaleMarkers --- lib/storage/storage_test.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/storage/storage_test.go b/lib/storage/storage_test.go index b79b13100..7aab87e40 100644 --- a/lib/storage/storage_test.go +++ b/lib/storage/storage_test.go @@ -1117,6 +1117,31 @@ func TestStorageAddRowsConcurrent(t *testing.T) { } } +func testGenerateMetricRowsForTenant(accountID, projectID uint32, rng *rand.Rand, rows uint64, timestampMin, timestampMax int64) []MetricRow { + var mrs []MetricRow + var mn MetricName + mn.Tags = []Tag{ + {[]byte("job"), []byte("webservice")}, + {[]byte("instance"), []byte("1.2.3.4")}, + } + for i := 0; i < int(rows); i++ { + mn.AccountID = accountID + mn.ProjectID = projectID + mn.MetricGroup = []byte(fmt.Sprintf("metric_%d", i)) + metricNameRaw := mn.marshalRaw(nil) + timestamp := rng.Int63n(timestampMax-timestampMin) + timestampMin + value := rng.NormFloat64() * 1e6 + + mr := MetricRow{ + MetricNameRaw: metricNameRaw, + Timestamp: timestamp, + Value: value, + } + mrs = append(mrs, mr) + } + return mrs +} + func testGenerateMetricRows(rng *rand.Rand, rows uint64, timestampMin, timestampMax int64) []MetricRow { var mrs []MetricRow var mn MetricName @@ -1363,10 +1388,12 @@ func TestStorageDeleteStaleSnapshots(t *testing.T) { func TestStorageSeriesAreNotCreatedOnStaleMarkers(t *testing.T) { path := "TestStorageSeriesAreNotCreatedOnStaleMarkers" + const accountID = 2344 + const projectID = 89823 s := MustOpenStorage(path, -1, 1e5, 1e6) tr := TimeRange{MinTimestamp: 0, MaxTimestamp: 2e10} - tfsAll := NewTagFilters() + tfsAll := NewTagFilters(accountID, projectID) if err := tfsAll.Add([]byte("__name__"), []byte(".*"), false, true); err != nil { t.Fatalf("unexpected error in TagFilters.Add: %s", err) } @@ -1387,7 +1414,7 @@ func TestStorageSeriesAreNotCreatedOnStaleMarkers(t *testing.T) { findN(0) rng := rand.New(rand.NewSource(1)) - mrs := testGenerateMetricRows(rng, 20, tr.MinTimestamp, tr.MaxTimestamp) + mrs := testGenerateMetricRowsForTenant(accountID, projectID, rng, 20, tr.MinTimestamp, tr.MaxTimestamp) // populate storage with some rows if err := s.AddRows(mrs[:10], defaultPrecisionBits); err != nil { t.Fatal("error when adding mrs: %w", err)