Skip to content

Commit

Permalink
Fix possible error in integer conversion
Browse files Browse the repository at this point in the history
realisticly we would never have more than 65536 sentinels in a cluster...
  • Loading branch information
Saremox committed Jun 6, 2024
1 parent f0a278b commit 54d15b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
SLAVE_WRONG_MASTER = "SLAVE_IS_CONFIGURED_WITH_WRONG_MASTER_IP"
SENTINEL_NOT_READY = "SENTINEL_NOT_READY"
REGEX_NOT_FOUND = "SENTINEL_REGEX_NOT_FOUND"
SENTINEL_TOO_MANY = "SENTINEL_TOO_MANY"
MISC = "MISC_ERROR"
SENTINEL_NUMBER_IN_MEMORY_MISMATCH = "SENTINEL_NUMBER_IN_MEMORY_MISMATCH"
REDIS_SLAVES_NUMBER_IN_MEMORY_MISMATCH = "REDIS_SLAVES_NUMBER_IN_MEMORY_MISMATCH"
Expand Down
8 changes: 8 additions & 0 deletions service/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (c *client) GetNumberSentinelsInMemory(ip string) (int32, error) {
c.metricsRecorder.RecordRedisOperation(metrics.KIND_SENTINEL, ip, metrics.GET_NUM_SENTINELS_IN_MEM, metrics.FAIL, metrics.MISC)
return 0, err
}
if nSentinels > 65536 {
c.metricsRecorder.RecordRedisOperation(metrics.KIND_SENTINEL, ip, metrics.GET_NUM_SENTINELS_IN_MEM, metrics.FAIL, metrics.SENTINEL_TOO_MANY)
return 0, err
}
c.metricsRecorder.RecordRedisOperation(metrics.KIND_SENTINEL, ip, metrics.GET_NUM_SENTINELS_IN_MEM, metrics.SUCCESS, metrics.NOT_APPLICABLE)
return int32(nSentinels), nil
}
Expand Down Expand Up @@ -125,6 +129,10 @@ func (c *client) GetNumberSentinelSlavesInMemory(ip string) (int32, error) {
c.metricsRecorder.RecordRedisOperation(metrics.KIND_SENTINEL, ip, metrics.GET_NUM_REDIS_SLAVES_IN_MEM, metrics.FAIL, metrics.MISC)
return 0, err
}
if nSlaves > 65536 {
c.metricsRecorder.RecordRedisOperation(metrics.KIND_SENTINEL, ip, metrics.GET_NUM_SENTINELS_IN_MEM, metrics.FAIL, metrics.SENTINEL_TOO_MANY)
return 0, err
}
c.metricsRecorder.RecordRedisOperation(metrics.KIND_SENTINEL, ip, metrics.GET_NUM_REDIS_SLAVES_IN_MEM, metrics.SUCCESS, metrics.NOT_APPLICABLE)
return int32(nSlaves), nil
}
Expand Down

0 comments on commit 54d15b2

Please sign in to comment.