From 4922f0bd2e435a232d8915b56929604a9533f8d1 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Wed, 18 Sep 2019 15:03:40 +0530 Subject: [PATCH] Make sure the HA tracker only handles valid keys If the ring and the HA tracker share the same prefix then we will end up handling invalid keys. Fixes #1652 and #1628 Signed-off-by: Goutham Veeramachaneni --- pkg/distributor/ha_tracker.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/distributor/ha_tracker.go b/pkg/distributor/ha_tracker.go index 0c6a2c8dd3c..abff201e00b 100644 --- a/pkg/distributor/ha_tracker.go +++ b/pkg/distributor/ha_tracker.go @@ -150,6 +150,13 @@ func (c *haTracker) loop(ctx context.Context) { c.electedLock.Lock() defer c.electedLock.Unlock() chunks := strings.SplitN(key, "/", 2) + + // The prefix has already been stripped, so a valid key would look like cluster/replica, + // and a key without a / such as `ring` would be invalid. + if len(chunks) != 2 { + return true + } + if replica.Replica != c.elected[key].Replica { electedReplicaChanges.WithLabelValues(chunks[0], chunks[1]).Inc() }