Skip to content

Commit

Permalink
proxy: fix bug of issue #1078 & #1080
Browse files Browse the repository at this point in the history
    json doesn't support map[int]string, using map[string]string instead
  • Loading branch information
spinlock committed Dec 15, 2016
1 parent 1941982 commit 61cc852
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
18 changes: 13 additions & 5 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -455,9 +456,9 @@ type Stats struct {
Closed bool `json:"closed"`

Sentinels struct {
Servers []string `json:"servers,omitempty"`
Masters map[int]string `json:"masters,omitempty"`
Switched bool `json:"switched,omitempty"`
Servers []string `json:"servers,omitempty"`
Masters map[string]string `json:"masters,omitempty"`
Switched bool `json:"switched,omitempty"`
} `json:"sentinels"`

Ops struct {
Expand Down Expand Up @@ -552,8 +553,15 @@ func (s *Proxy) Stats(flags StatsFlags) *Stats {
stats.Closed = s.IsClosed()

servers, masters := s.GetSentinels()
stats.Sentinels.Servers = servers
stats.Sentinels.Masters = masters
if servers != nil {
stats.Sentinels.Servers = servers
}
if masters != nil {
stats.Sentinels.Masters = make(map[string]string)
for gid, addr := range masters {
stats.Sentinels.Masters[strconv.Itoa(gid)] = addr
}
}
stats.Sentinels.Switched = s.HasSwitched()

stats.Ops.Total = OpTotal()
Expand Down
16 changes: 10 additions & 6 deletions pkg/topom/topom.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"os/exec"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -309,8 +310,12 @@ func (s *Topom) Stats() (*Stats, error) {
stats.HA.Stats[server] = v
}
}
stats.HA.Masters = s.ha.masters

stats.HA.Masters = make(map[string]string)
if s.ha.masters != nil {
for gid, addr := range s.ha.masters {
stats.HA.Masters[strconv.Itoa(gid)] = addr
}
}
return stats, nil
}

Expand Down Expand Up @@ -342,10 +347,9 @@ type Stats struct {
} `json:"slot_action"`

HA struct {
Model *models.Sentinel `json:"model"`
Stats map[string]*RedisStats `json:"stats"`

Masters map[int]string `json:"masters,omitempty"`
Model *models.Sentinel `json:"model"`
Stats map[string]*RedisStats `json:"stats"`
Masters map[string]string `json:"masters"`
} `json:"sentinels"`
}

Expand Down

0 comments on commit 61cc852

Please sign in to comment.