vllogs: add tests fix some descriptions

This commit is contained in:
dmitryk-dk 2024-11-08 09:34:24 +01:00
parent 2c96f3512d
commit 64b48d0abf
No known key found for this signature in database
GPG key ID: 789E20A826606D2A
4 changed files with 76 additions and 4 deletions

View file

@ -252,5 +252,5 @@ var (
logsqlStreamIDsRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/logsql/stream_ids"}`)
logsqlStreamsRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/logsql/streams"}`)
logsqlTailRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/logsql/tail"}`)
logsqlAdminTenantsRequests = metrics.NewCounter(`vl_http_requests_total{path="/admin/tenants"}`)
logsqlAdminTenantsRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/admin/tenants"}`)
)

View file

@ -176,7 +176,7 @@ func GetStreamIDs(ctx context.Context, tenantIDs []logstorage.TenantID, q *logst
return strg.GetStreamIDs(ctx, tenantIDs, q, limit)
}
// GetTenantIDs returns tenantIDs in the storage.
// GetTenantIDs returns tenantIDs from the storage by the given start and end.
func GetTenantIDs(ctx context.Context, start, end int64) ([]string, error) {
return strg.GetTenantIDs(ctx, start, end)
}

View file

@ -3,6 +3,7 @@ package logstorage
import (
"fmt"
"reflect"
"slices"
"testing"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
@ -254,5 +255,76 @@ func TestStorageSearchStreamIDs(t *testing.T) {
}
func TestGetTenantsIds(t *testing.T) {
t.Parallel()
path := t.Name()
const partitionName = "foobar"
s := newTestStorage()
mustCreateIndexdb(path)
idb := mustOpenIndexdb(path, partitionName, s)
tenantIDs := []TenantID{
{AccountID: 0, ProjectID: 0},
{AccountID: 0, ProjectID: 1},
{AccountID: 1, ProjectID: 0},
{AccountID: 1, ProjectID: 1},
{AccountID: 123, ProjectID: 567},
}
getStreamIDForTags := func(tags map[string]string) ([]streamID, []byte) {
st := GetStreamTags()
for k, v := range tags {
st.Add(k, v)
}
streamTagsCanonical := st.MarshalCanonical(nil)
PutStreamTags(st)
id := hash128(streamTagsCanonical)
sids := make([]streamID, 0, len(tenantIDs))
for _, tenantID := range tenantIDs {
sid := streamID{
tenantID: tenantID,
id: id,
}
sids = append(sids, sid)
}
return sids, streamTagsCanonical
}
// Create indexdb entries
const jobsCount = 7
const instancesCount = 5
for i := 0; i < jobsCount; i++ {
for j := 0; j < instancesCount; j++ {
sids, streamTagsCanonical := getStreamIDForTags(map[string]string{
"job": fmt.Sprintf("job-%d", i),
"instance": fmt.Sprintf("instance-%d", j),
})
for _, sid := range sids {
idb.mustRegisterStream(&sid, streamTagsCanonical)
}
}
}
idb.debugFlush()
f := func(expectedTenantIDs []string) {
t.Helper()
tenantIDs := idb.searchTenants()
slices.Sort(tenantIDs)
slices.Sort(expectedTenantIDs)
if !reflect.DeepEqual(tenantIDs, expectedTenantIDs) {
fs.MustRemoveAll(path)
t.Fatalf("unexpected tensntIds; got %v; want %v", tenantIDs, expectedTenantIDs)
}
}
expectedTenantIDs := []string{"1:1", "123:567", "0:0", "0:1", "1:0"}
f(expectedTenantIDs)
mustCloseIndexdb(idb)
fs.MustRemoveAll(path)
closeTestStorage(s)
}

View file

@ -394,7 +394,7 @@ func (s *Storage) GetStreamIDs(ctx context.Context, tenantIDs []TenantID, q *Que
return s.GetFieldValues(ctx, tenantIDs, q, "_stream_id", limit)
}
// GetTenantIDs returns tenantIDs for the given q.
// GetTenantIDs returns tenantIDs for the given start and end.
func (s *Storage) GetTenantIDs(ctx context.Context, start, end int64) ([]string, error) {
return s.getTenantIDs(ctx, start, end)
}
@ -420,7 +420,7 @@ func (s *Storage) getTenantIDs(ctx context.Context, start, end int64) ([]string,
for tid := range m {
tenants = append(tenants, tid)
}
sort.Strings(tenants)
slices.Sort(tenants)
return tenants, nil
}