headIndexReader: reduce debug logging (#15993)

Around Mimir compactions we see logging in ShardedPostings do massive allocations and drive GC up to 50% of CPU.

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
This commit is contained in:
Dimitar Dimitrov 2025-02-07 16:46:55 +01:00 committed by GitHub
parent 20371118b6
commit 686dcc7b0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -117,15 +117,19 @@ func (h *headIndexReader) PostingsForAllLabelValues(ctx context.Context, name st
func (h *headIndexReader) SortedPostings(p index.Postings) index.Postings { func (h *headIndexReader) SortedPostings(p index.Postings) index.Postings {
series := make([]*memSeries, 0, 128) series := make([]*memSeries, 0, 128)
notFoundSeriesCount := 0
// Fetch all the series only once. // Fetch all the series only once.
for p.Next() { for p.Next() {
s := h.head.series.getByID(chunks.HeadSeriesRef(p.At())) s := h.head.series.getByID(chunks.HeadSeriesRef(p.At()))
if s == nil { if s == nil {
h.head.logger.Debug("Looked up series not found") notFoundSeriesCount++
} else { } else {
series = append(series, s) series = append(series, s)
} }
} }
if notFoundSeriesCount > 0 {
h.head.logger.Debug("Looked up series not found", "count", notFoundSeriesCount)
}
if err := p.Err(); err != nil { if err := p.Err(); err != nil {
return index.ErrPostings(fmt.Errorf("expand postings: %w", err)) return index.ErrPostings(fmt.Errorf("expand postings: %w", err))
} }
@ -150,11 +154,12 @@ func (h *headIndexReader) ShardedPostings(p index.Postings, shardIndex, shardCou
} }
out := make([]storage.SeriesRef, 0, 128) out := make([]storage.SeriesRef, 0, 128)
notFoundSeriesCount := 0
for p.Next() { for p.Next() {
s := h.head.series.getByID(chunks.HeadSeriesRef(p.At())) s := h.head.series.getByID(chunks.HeadSeriesRef(p.At()))
if s == nil { if s == nil {
h.head.logger.Debug("Looked up series not found") notFoundSeriesCount++
continue continue
} }
@ -165,6 +170,9 @@ func (h *headIndexReader) ShardedPostings(p index.Postings, shardIndex, shardCou
out = append(out, storage.SeriesRef(s.ref)) out = append(out, storage.SeriesRef(s.ref))
} }
if notFoundSeriesCount > 0 {
h.head.logger.Debug("Looked up series not found", "count", notFoundSeriesCount)
}
return index.NewListPostings(out) return index.NewListPostings(out)
} }