Fix SDLCLI healthcheck to ignore ghost Sentinels 47/7447/2 v0.9.2
authorTimo Tietavainen <timo.tietavainen@nokia.com>
Tue, 21 Dec 2021 22:46:03 +0000 (00:46 +0200)
committerTimo Tietavainen <timo.tietavainen@nokia.com>
Wed, 22 Dec 2021 05:14:35 +0000 (07:14 +0200)
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 <timo.tietavainen@nokia.com>
Change-Id: I4ba075cf66af98a59da8c558e9602ba1427fb8d9

docs/release-notes.rst
internal/sdlgoredis/sdlgoredis_test.go
internal/sdlgoredis/sdlgosentinel.go

index dfaf2e0..6a1074b 100644 (file)
@@ -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
index 7ed7d70..0d8abce 100644 (file)
@@ -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" +
index 19468d7..ac56322 100644 (file)
@@ -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