Scrape tests: Better series references

`collectResultAppender` on its own will now use the labels hash
instead of a random number. This avoids the situation where a series
could be added twice under different references.

When there is an underlying appender, use the reference it generates.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2025-09-02 14:51:19 +01:00
parent 70bf09cb2b
commit 8dea1f04a5

View File

@ -19,7 +19,6 @@ import (
"encoding/binary"
"fmt"
"math"
"math/rand"
"strings"
"sync"
"testing"
@ -148,10 +147,11 @@ func (a *collectResultAppender) Append(ref storage.SeriesRef, lset labels.Labels
f: v,
})
if ref == 0 {
ref = storage.SeriesRef(rand.Uint64())
}
if a.next == nil {
if ref == 0 {
// Use labels hash as a stand-in for unique series reference, to avoid having to track all series.
ref = storage.SeriesRef(lset.Hash())
}
return ref, nil
}
@ -195,10 +195,10 @@ func (a *collectResultAppender) UpdateMetadata(ref storage.SeriesRef, l labels.L
a.mtx.Lock()
defer a.mtx.Unlock()
a.pendingMetadata = append(a.pendingMetadata, metadataEntry{metric: l, m: m})
if ref == 0 {
ref = storage.SeriesRef(rand.Uint64())
}
if a.next == nil {
if ref == 0 {
ref = storage.SeriesRef(l.Hash())
}
return ref, nil
}