From dc264f8ae170465c6bb7cd8ab8be12086f8c0011 Mon Sep 17 00:00:00 2001 From: Bartlomiej Plotka Date: Tue, 20 Apr 2021 16:34:50 +0200 Subject: [PATCH] Fixes. Signed-off-by: Bartlomiej Plotka --- pkg/receive/hashring.go | 5 +++++ pkg/store/labelpb/label.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/receive/hashring.go b/pkg/receive/hashring.go index 0de4dbefe15..b368bf30e74 100644 --- a/pkg/receive/hashring.go +++ b/pkg/receive/hashring.go @@ -6,6 +6,7 @@ package receive import ( "context" "fmt" + "sort" "sync" "github.com/pkg/errors" @@ -65,6 +66,10 @@ func (s simpleHashring) GetN(tenant string, ts *prompb.TimeSeries, n uint64) (st if n >= uint64(len(s)) { return "", &insufficientNodesError{have: uint64(len(s)), want: n + 1} } + + // TODO(bwplotka): This might be not needed, double check. + sort.Slice(ts.Labels, func(i, j int) bool { return ts.Labels[i].Name < ts.Labels[j].Name }) + return s[(labelpb.HashWithPrefix(tenant, ts.Labels)+n)%uint64(len(s))], nil } diff --git a/pkg/store/labelpb/label.go b/pkg/store/labelpb/label.go index 2aa778d71ca..ca504410363 100644 --- a/pkg/store/labelpb/label.go +++ b/pkg/store/labelpb/label.go @@ -19,6 +19,8 @@ import ( "github.com/prometheus/prometheus/pkg/labels" ) +var sep = []byte{'\xff'} + func noAllocString(buf []byte) string { return *(*string)(unsafe.Pointer(&buf)) } @@ -316,8 +318,6 @@ func DeepCopy(lbls []ZLabel) []ZLabel { return ret } -var sep = []byte{'\xff'} - // HashWithPrefix returns a hash for the given prefix and labels. func HashWithPrefix(prefix string, lbls []ZLabel) uint64 { // Use xxhash.Sum64(b) for fast path as it's faster.