Skip to content

Commit 61cc852

Browse files
committed
proxy: fix bug of issue #1078 & #1080
json doesn't support map[int]string, using map[string]string instead
1 parent 1941982 commit 61cc852

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

pkg/proxy/proxy.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os/exec"
1212
"path/filepath"
1313
"runtime"
14+
"strconv"
1415
"strings"
1516
"sync"
1617
"time"
@@ -455,9 +456,9 @@ type Stats struct {
455456
Closed bool `json:"closed"`
456457

457458
Sentinels struct {
458-
Servers []string `json:"servers,omitempty"`
459-
Masters map[int]string `json:"masters,omitempty"`
460-
Switched bool `json:"switched,omitempty"`
459+
Servers []string `json:"servers,omitempty"`
460+
Masters map[string]string `json:"masters,omitempty"`
461+
Switched bool `json:"switched,omitempty"`
461462
} `json:"sentinels"`
462463

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

554555
servers, masters := s.GetSentinels()
555-
stats.Sentinels.Servers = servers
556-
stats.Sentinels.Masters = masters
556+
if servers != nil {
557+
stats.Sentinels.Servers = servers
558+
}
559+
if masters != nil {
560+
stats.Sentinels.Masters = make(map[string]string)
561+
for gid, addr := range masters {
562+
stats.Sentinels.Masters[strconv.Itoa(gid)] = addr
563+
}
564+
}
557565
stats.Sentinels.Switched = s.HasSwitched()
558566

559567
stats.Ops.Total = OpTotal()

pkg/topom/topom.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"os"
1111
"os/exec"
12+
"strconv"
1213
"strings"
1314
"sync"
1415
"time"
@@ -309,8 +310,12 @@ func (s *Topom) Stats() (*Stats, error) {
309310
stats.HA.Stats[server] = v
310311
}
311312
}
312-
stats.HA.Masters = s.ha.masters
313-
313+
stats.HA.Masters = make(map[string]string)
314+
if s.ha.masters != nil {
315+
for gid, addr := range s.ha.masters {
316+
stats.HA.Masters[strconv.Itoa(gid)] = addr
317+
}
318+
}
314319
return stats, nil
315320
}
316321

@@ -342,10 +347,9 @@ type Stats struct {
342347
} `json:"slot_action"`
343348

344349
HA struct {
345-
Model *models.Sentinel `json:"model"`
346-
Stats map[string]*RedisStats `json:"stats"`
347-
348-
Masters map[int]string `json:"masters,omitempty"`
350+
Model *models.Sentinel `json:"model"`
351+
Stats map[string]*RedisStats `json:"stats"`
352+
Masters map[string]string `json:"masters"`
349353
} `json:"sentinels"`
350354
}
351355

0 commit comments

Comments
 (0)