From 02c095938023c79ff8cdd76b6b4115d42a1d7a23 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 5 Mar 2021 09:05:52 +0200 Subject: [PATCH] lib/promscrape: make cluster membership calculations consistent across 32-bit and 64-bit architectures --- lib/promscrape/config.go | 4 ++-- lib/promscrape/config_test.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 2e520a943c..118c5dcc5b 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -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 } diff --git a/lib/promscrape/config_test.go b/lib/promscrape/config_test.go index ef4d20599f..d79bee3c82 100644 --- a/lib/promscrape/config_test.go +++ b/lib/promscrape/config_test.go @@ -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