Skip to content

Commit

Permalink
fix:修复sentinel指标上报缺失 (#1011)
Browse files Browse the repository at this point in the history
masterNames未赋值,master名列表为空,导致sentinel  replica和sentinels相关指标未上报
  • Loading branch information
ttbug authored Jul 19, 2024
1 parent 931d25d commit 4cde593
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions inputs/redis_sentinel/redis_sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,21 +335,20 @@ func convertSentinelReplicaOutput(
}

func (client *RedisSentinelClient) gatherMasterStats(slist *types.SampleList) ([]string, error) {
var masterNames []string

mastersCmd := redis.NewSliceCmd(context.Background(), "sentinel", "masters")
if err := client.sentinel.Process(context.Background(), mastersCmd); err != nil {
return masterNames, err
return nil, err
}

masters, err := mastersCmd.Result()
if err != nil {
return masterNames, err
return nil, err
}

// Break out of the loop if one of the items comes out malformed
// It's safe to assume that if we fail parsing one item that the rest will fail too
// This is because we are iterating over a single server response
masterNames := make([]string, 0, len(masters))
for _, master := range masters {
master, ok := master.([]interface{})
if !ok {
Expand All @@ -363,6 +362,7 @@ func (client *RedisSentinelClient) gatherMasterStats(slist *types.SampleList) ([
return masterNames, fmt.Errorf("unable to resolve master name")
}

masterNames = append(masterNames, masterName)
quorumCmd := redis.NewStringCmd(context.Background(), "sentinel", "ckquorum", masterName)
quorumErr := client.sentinel.Process(context.Background(), quorumCmd)

Expand Down

0 comments on commit 4cde593

Please sign in to comment.