From 5b27c45bf060ea23586f38256e5b8187b12b3443 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Tue, 29 Jul 2025 11:04:52 +0200 Subject: [PATCH] chore: Do not pass `nil` slice in `HashWithoutLabels` call Signed-off-by: Christian Haudum --- clients/pkg/promtail/wal/writer.go | 3 ++- pkg/blockbuilder/builder/appender.go | 2 +- pkg/dataobj/querier/metadata.go | 2 +- pkg/ingester/index/index_test.go | 2 +- pkg/ingester/instance.go | 2 +- pkg/logql/log/labels_slicelabels.go | 2 +- pkg/pattern/instance.go | 2 +- pkg/querier/queryrange/limits.go | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/clients/pkg/promtail/wal/writer.go b/clients/pkg/promtail/wal/writer.go index a0afdf02d1075..b0aa1872b8531 100644 --- a/clients/pkg/promtail/wal/writer.go +++ b/clients/pkg/promtail/wal/writer.go @@ -226,6 +226,7 @@ func (wrt *Writer) SubscribeWrite(subscriber WriteEventSubscriber) { // across every write. type entryWriter struct { reusableWALRecord *wal.Record + lbsBuf []byte // buffer for hashing labels } // newEntryWriter creates a new entryWriter. @@ -247,7 +248,7 @@ func (ew *entryWriter) WriteEntry(entry api.Entry, wl WAL, _ log.Logger) error { var fp uint64 lbs := labels.FromMap(util.ModelLabelSetToMap(entry.Labels)) - fp, _ = lbs.HashWithoutLabels(nil, []string(nil)...) + fp, ew.lbsBuf = lbs.HashWithoutLabels(ew.lbsBuf) // Append the entry to an already existing stream (if any) ew.reusableWALRecord.RefEntries = append(ew.reusableWALRecord.RefEntries, wal.RefEntries{ diff --git a/pkg/blockbuilder/builder/appender.go b/pkg/blockbuilder/builder/appender.go index 041d31a9b12b3..ca9a5023ec474 100644 --- a/pkg/blockbuilder/builder/appender.go +++ b/pkg/blockbuilder/builder/appender.go @@ -284,7 +284,7 @@ func (m *streamsMap) getLabelsFromFingerprint(fp model.Fingerprint) labels.Label func (i *instance) getHashForLabels(ls labels.Labels) model.Fingerprint { var fp uint64 - fp, i.buf = ls.HashWithoutLabels(i.buf, []string(nil)...) + fp, i.buf = ls.HashWithoutLabels(i.buf) return i.mapper.MapFP(model.Fingerprint(fp), ls) } diff --git a/pkg/dataobj/querier/metadata.go b/pkg/dataobj/querier/metadata.go index f38720e5d2335..ab583dba681c6 100644 --- a/pkg/dataobj/querier/metadata.go +++ b/pkg/dataobj/querier/metadata.go @@ -259,7 +259,7 @@ func (sp *streamProcessor) processSingleReader(ctx context.Context, reader *stre break } for _, stream := range streams[:n] { - h, buf = stream.Labels.HashWithoutLabels(buf, []string(nil)...) + h, buf = stream.Labels.HashWithoutLabels(buf) // Try to claim this hash first if _, seen := sp.seenSeries.LoadOrStore(h, nil); seen { continue diff --git a/pkg/ingester/index/index_test.go b/pkg/ingester/index/index_test.go index 8b07663032e60..6515899fefc48 100644 --- a/pkg/ingester/index/index_test.go +++ b/pkg/ingester/index/index_test.go @@ -69,7 +69,7 @@ func BenchmarkHash(b *testing.B) { b.Run("xxash", func(b *testing.B) { for n := 0; n < b.N; n++ { var fp uint64 - fp, buf = logproto.FromLabelAdaptersToLabels(lbs).HashWithoutLabels(buf, []string(nil)...) + fp, buf = logproto.FromLabelAdaptersToLabels(lbs).HashWithoutLabels(buf) result = util.HashFP(model.Fingerprint(fp)) % 16 } }) diff --git a/pkg/ingester/instance.go b/pkg/ingester/instance.go index 225f0ace629ea..d3d06ab5a48fd 100644 --- a/pkg/ingester/instance.go +++ b/pkg/ingester/instance.go @@ -455,7 +455,7 @@ func (i *instance) removeStream(s *stream) { func (i *instance) getHashForLabels(ls labels.Labels) model.Fingerprint { var fp uint64 - fp, i.buf = ls.HashWithoutLabels(i.buf, []string(nil)...) + fp, i.buf = ls.HashWithoutLabels(i.buf) return i.mapper.MapFP(model.Fingerprint(fp), ls) } diff --git a/pkg/logql/log/labels_slicelabels.go b/pkg/logql/log/labels_slicelabels.go index 01036a0a54023..e3ce76f26f7de 100644 --- a/pkg/logql/log/labels_slicelabels.go +++ b/pkg/logql/log/labels_slicelabels.go @@ -19,6 +19,6 @@ func newHasher() *hasher { // It is not guaranteed to be stable across different Loki processes or versions. func (h *hasher) Hash(lbs labels.Labels) uint64 { var hash uint64 - hash, h.buf = lbs.HashWithoutLabels(h.buf, []string(nil)...) + hash, h.buf = lbs.HashWithoutLabels(h.buf) return hash } diff --git a/pkg/pattern/instance.go b/pkg/pattern/instance.go index 997461737a431..b2f60bc3ee976 100644 --- a/pkg/pattern/instance.go +++ b/pkg/pattern/instance.go @@ -260,7 +260,7 @@ func (i *instance) createStream(_ context.Context, pushReqStream logproto.Stream func (i *instance) getHashForLabels(ls labels.Labels) model.Fingerprint { var fp uint64 - fp, i.buf = ls.HashWithoutLabels(i.buf, []string(nil)...) + fp, i.buf = ls.HashWithoutLabels(i.buf) return i.mapper.MapFP(model.Fingerprint(fp), ls) } diff --git a/pkg/querier/queryrange/limits.go b/pkg/querier/queryrange/limits.go index 5e89f1e6b27ba..c8ab358ea3695 100644 --- a/pkg/querier/queryrange/limits.go +++ b/pkg/querier/queryrange/limits.go @@ -445,7 +445,7 @@ func (sl *seriesLimiter) Do(ctx context.Context, req queryrangebase.Request) (qu } } - hash, sl.buf = lbs.HashWithoutLabels(sl.buf, []string(nil)...) + hash, sl.buf = lbs.HashWithoutLabels(sl.buf) // If there's a variant label, track it in the variant map if variant != "" {