Skip to content

Commit

Permalink
Default sort by cid for connz
Browse files Browse the repository at this point in the history
  • Loading branch information
derekcollison committed Feb 5, 2016
1 parent 703f928 commit c0ba6c2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
6 changes: 3 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- [ ] Dynamic socket buffer sizes
- [ ] Switch to 1.4/1.5 and use maps vs hashmaps in sublist
- [ ] brew, apt-get, rpm, chocately (windows)
- [ ] Sublist better at high concurrency, cache uses writelock currently
- [ ] Sublist better at high concurrency, cache uses writelock always currently
- [ ] Buffer pools/sync pools?
- [ ] IOVec pools and writev for high fanout?
- [ ] Add ability to reload config on signal
Expand All @@ -18,9 +18,9 @@
- [ ] Memory limits/warnings?
- [ ] Limit number of subscriptions a client can have, total memory usage etc.
- [ ] Info updates contain other implicit route servers
- [ ] Pedantic state
- [ ] Multi-tenant accounts with isolation of subject space
- [ ] Default sort by cid on connz
- [ ] Pedantic state
- [X] Default sort by cid on connz
- [X] Track last activity time per connection?
- [X] Add total connections to varz so we won't miss spikes, etc.
- [X] Add starttime and uptime to connz list.
Expand Down
5 changes: 5 additions & 0 deletions server/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (s *Server) HandleConnz(w http.ResponseWriter, r *http.Request) {
c.Limit, _ = strconv.Atoi(r.URL.Query().Get("limit"))
sortOpt := SortOpt(r.URL.Query().Get("sort"))

// If no sort option given, sort by cid
if sortOpt == "" {
sortOpt = byCid
}

if c.Limit == 0 {
c.Limit = DefaultConnListSize
}
Expand Down
40 changes: 38 additions & 2 deletions server/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,42 @@ func TestConnzWithOffsetAndLimit(t *testing.T) {

}

func TestConnzDefaultSorted(t *testing.T) {
s := runMonitorServer(DEFAULT_HTTP_PORT)
defer s.Shutdown()

clients := make([]*nats.Conn, 4)
for i, _ := range clients {
clients[i] = createClientConnSubscribeAndPublish(t)
defer clients[i].Close()
}

url := fmt.Sprintf("http://localhost:%d/", DEFAULT_HTTP_PORT)
resp, err := http.Get(url + "connz")
if err != nil {
t.Fatalf("Expected no error: Got %v\n", err)
}
if resp.StatusCode != 200 {
t.Fatalf("Expected a 200 response, got %d\n", resp.StatusCode)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatalf("Got an error reading the body: %v\n", err)
}

c := Connz{}
if err := json.Unmarshal(body, &c); err != nil {
t.Fatalf("Got an error unmarshalling the body: %v\n", err)
}

if c.Conns[0].Cid > c.Conns[1].Cid ||
c.Conns[1].Cid > c.Conns[2].Cid ||
c.Conns[2].Cid > c.Conns[3].Cid {
t.Fatalf("Expected conns sorted in ascending order by cid, got %v < %v\n", c.Conns[0].Cid, c.Conns[3].Cid)
}
}

func TestConnzSortedByCid(t *testing.T) {
s := runMonitorServer(DEFAULT_HTTP_PORT)
defer s.Shutdown()
Expand Down Expand Up @@ -774,8 +810,8 @@ func TestConnzSortedByLast(t *testing.T) {
}

if c.Conns[0].LastActivity.UnixNano() < c.Conns[1].LastActivity.UnixNano() ||
c.Conns[0].LastActivity.UnixNano() < c.Conns[2].LastActivity.UnixNano() ||
c.Conns[0].LastActivity.UnixNano() < c.Conns[3].LastActivity.UnixNano() {
c.Conns[1].LastActivity.UnixNano() < c.Conns[2].LastActivity.UnixNano() ||
c.Conns[2].LastActivity.UnixNano() < c.Conns[3].LastActivity.UnixNano() {
t.Fatalf("Expected conns sorted in descending order by lastActivity, got %v < one of [%v, %v, %v]\n",
c.Conns[0].LastActivity, c.Conns[1].LastActivity, c.Conns[2].LastActivity, c.Conns[3].LastActivity)
}
Expand Down

0 comments on commit c0ba6c2

Please sign in to comment.