From 598cab79e5f1f697fa8ce0731700bf91c2cd02fe Mon Sep 17 00:00:00 2001 From: George Robinson Date: Thu, 28 Aug 2025 14:21:06 +0100 Subject: [PATCH] fix: don't need to open section to read tenant (#19053) --- pkg/dataobj/tools/stats.go | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/pkg/dataobj/tools/stats.go b/pkg/dataobj/tools/stats.go index 477772856b..97d0b8606a 100644 --- a/pkg/dataobj/tools/stats.go +++ b/pkg/dataobj/tools/stats.go @@ -5,12 +5,9 @@ package tools import ( "context" - "errors" "slices" "github.com/grafana/loki/v3/pkg/dataobj" - "github.com/grafana/loki/v3/pkg/dataobj/sections/logs" - "github.com/grafana/loki/v3/pkg/dataobj/sections/streams" ) type Stats struct { @@ -30,32 +27,13 @@ type SectionsPerTenantStats struct { // ReadStats returns statistics about the data object. ReadStats returns an // error if the data object couldn't be inspected or if the provided ctx is // canceled. -func ReadStats(ctx context.Context, obj *dataobj.Object) (*Stats, error) { +func ReadStats(_ context.Context, obj *dataobj.Object) (*Stats, error) { s := Stats{} s.Size = uint64(obj.Size()) s.TenantSections = make(map[string]int) for _, sec := range obj.Sections() { s.Sections++ - switch { - case streams.CheckSection(sec): - streamsSec, err := streams.Open(ctx, sec) - if err != nil { - return nil, err - } - tenant := streamsSec.Tenant() - s.Tenants = append(s.Tenants, tenant) - s.TenantSections[tenant]++ - case logs.CheckSection(sec): - logsSec, err := logs.Open(ctx, sec) - if err != nil { - return nil, err - } - tenant := logsSec.Tenant() - s.Tenants = append(s.Tenants, tenant) - s.TenantSections[tenant]++ - default: - return nil, errors.New("unknown section type") - } + s.Tenants = append(s.Tenants, sec.Tenant) } // A tenant can have multiple sections, so we must deduplicate them. slices.Sort(s.Tenants)