lib/promscrape: make cluster membership calculations consistent across 32-bit and 64-bit architectures

This commit is contained in:
Aliaksandr Valialkin 2021-03-05 09:05:52 +02:00
parent 5277507932
commit 02c0959380
2 changed files with 4 additions and 3 deletions

View File

@ -727,8 +727,8 @@ func needSkipScrapeWork(key string, membersCount, replicasCount, memberNum int)
if membersCount <= 1 {
return false
}
h := int(xxhash.Sum64(bytesutil.ToUnsafeBytes(key)))
idx := h % membersCount
h := xxhash.Sum64(bytesutil.ToUnsafeBytes(key))
idx := int(h % uint64(membersCount))
if replicasCount < 1 {
replicasCount = 1
}

View File

@ -17,7 +17,8 @@ func TestNeedSkipScrapeWork(t *testing.T) {
t.Helper()
needSkip := needSkipScrapeWork(key, membersCount, replicationFactor, memberNum)
if needSkip != needSkipExpected {
t.Fatalf("unexpected needSkipScrapeWork(key=%q, membersCount=%d, replicationFactor=%d, memberNum=%d)", key, membersCount, replicationFactor, memberNum)
t.Fatalf("unexpected needSkipScrapeWork(key=%q, membersCount=%d, replicationFactor=%d, memberNum=%d); got %v; want %v",
key, membersCount, replicationFactor, memberNum, needSkip, needSkipExpected)
}
}
// Disabled clustering