From 77dd13bfb2ac4eb9ab3a4dd79d7a09a8fdc6d299 Mon Sep 17 00:00:00 2001 From: Timo Tietavainen Date: Wed, 22 Dec 2021 00:46:03 +0200 Subject: [PATCH] Fix SDLCLI healthcheck to ignore ghost Sentinels Fix SDLCLI 'healthcheck' command to ignore Redis Sentinel entries what have a zero port numbers, because these extra entries are not valid entries but instead are caused by a bug (#9240) in Redis server. Until there is a fix for the Redis server issue available, we ignore these ghost Redis Sentinel entries from SDLCLI 'healthcheck' command's validation. Version: 0.9.2 Issue-Id: RIC-869 Signed-off-by: Timo Tietavainen Change-Id: I4ba075cf66af98a59da8c558e9602ba1427fb8d9 --- docs/release-notes.rst | 4 ++++ internal/sdlgoredis/sdlgoredis_test.go | 28 ++++++++++++++++++++++++++++ internal/sdlgoredis/sdlgosentinel.go | 6 +++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/release-notes.rst b/docs/release-notes.rst index dfaf2e0..6a1074b 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -29,6 +29,10 @@ This document provides the release notes of the sdlgo. Version history --------------- +[0.9.2] - 2021-12-22 + +* Fix SDL CLI healthcheck to ignore ghost Redis Sentinel entries + [0.9.1] - 2021-12-20 * Refactor and reduce code complexity, no API changes diff --git a/internal/sdlgoredis/sdlgoredis_test.go b/internal/sdlgoredis/sdlgoredis_test.go index 7ed7d70..0d8abce 100644 --- a/internal/sdlgoredis/sdlgoredis_test.go +++ b/internal/sdlgoredis/sdlgoredis_test.go @@ -1454,6 +1454,34 @@ func TestStateWithPrimaryAndTwoReplicaRedisFailureWhenIntConversionFails(t *test r.AssertExpectations(t) } +// Test case to test ignoring of a sentinel entry with zero port. Implementation has been +// done because we miss the fix for the Redis Bug #9240. +func TestStateWithPrimaryAndTwoReplicaFirstSentinelStateIgnoredBecauseZeroPortBugRedisSuccessfully(t *testing.T) { + _, r, s, db := setupHaEnvWithSentinels(true, "3") + + redisPrimaryState := newMockRedisMasterCallResp("master", "10.20.30.30", "6379", "master") + redisReplicasState := newMockRedisSlavesCall() + redisReplicasState.add("slave", "10.20.30.40", "6379", "up", "slave") + redisReplicasState.add("slave", "10.20.30.50", "30000", "up", "slave") + redisSentinelsState := newMockRedisSentinelsCall() + redisSentinelsState.add("10.20.30.40", "0", "s_down,sentinel,disconnected") + redisSentinelsState.add("10.20.30.50", "26379", "sentinel") + + expState := newExpDbState(3, nil) + expState.addPrimary("master", "10.20.30.30", "6379", "master", nil) + expState.addReplica("slave", "10.20.30.40", "6379", "up", "slave", nil) + expState.addReplica("slave", "10.20.30.50", "30000", "up", "slave", nil) + expState.addSentinel("10.20.30.50", "26379", "sentinel", nil) + + s[0].On("Master", "dbaasmaster").Return(redis.NewStringStringMapResult(redisPrimaryState, nil)) + s[0].On("Slaves", "dbaasmaster").Return(redis.NewSliceResult(redisReplicasState.resp, nil)) + s[0].On("Sentinels", "dbaasmaster").Return(redis.NewSliceResult(redisSentinelsState.resp, nil)) + ret, err := db.State() + assert.Nil(t, err) + assert.Equal(t, expState.s, *ret) + r.AssertExpectations(t) +} + func TestStateWithSinglePrimaryRedisSuccessfully(t *testing.T) { _, r, db := setupSingleEnv(true, "1") redisInfo := "# Replication\r\n" + diff --git a/internal/sdlgoredis/sdlgosentinel.go b/internal/sdlgoredis/sdlgosentinel.go index 19468d7..ac56322 100644 --- a/internal/sdlgoredis/sdlgosentinel.go +++ b/internal/sdlgoredis/sdlgosentinel.go @@ -134,7 +134,11 @@ func (s *Sentinel) getSentinelsState() (*SentinelsDbState, error) { if redisErr == nil { for _, redisSentinel := range redisVal { sentinelState := readSentinelState(redisSentinel.([]interface{})) - states.States = append(states.States, sentinelState) + // Ignore a sentinel entry with zero port, because missing of fix + // for the Redis Bug #9240. + if sentinelState.Fields.Port != "0" { + states.States = append(states.States, sentinelState) + } } } states.Err = redisErr -- 2.16.6