Skip to content

[FIXED] Monitoring: Issue with Connz filters "cid" and "state=all" #6849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions server/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,17 @@ func (s *Server) Connz(opts *ConnzOptions) (*Connz, error) {

// Search by individual CID.
if cid > 0 {
if state == ConnClosed || state == ConnAll {
// Let's first check if user also selects on ConnOpen or ConnAll
// and look for opened connections.
if state == ConnOpen || state == ConnAll {
if client := s.clients[cid]; client != nil {
openClients = append(openClients, client)
closedClients = nil
}
}
// If we did not find, and the user selected for ConnClosed or ConnAll,
// look for closed connections.
if len(openClients) == 0 && (state == ConnClosed || state == ConnAll) {
copyClosed := closedClients
closedClients = nil
for _, cc := range copyClosed {
Expand All @@ -349,11 +359,6 @@ func (s *Server) Connz(opts *ConnzOptions) (*Connz, error) {
break
}
}
} else if state == ConnOpen || state == ConnAll {
client := s.clients[cid]
if client != nil {
openClients = append(openClients, client)
}
}
} else {
// Gather all open clients.
Expand Down
6 changes: 6 additions & 0 deletions server/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,12 @@ func TestMonitorConnzWithStateForClosedConns(t *testing.T) {
if lc := len(c.Conns); lc != 1 {
return fmt.Errorf("Expected a connection in open array, got %d", lc)
}
// It should also work if we ask for "state=all"
c = pollConnz(t, s, mode, url+"connz?cid=2&state=all", &ConnzOptions{CID: 2, State: ConnAll})
if lc := len(c.Conns); lc != 1 {
return fmt.Errorf("Expected a connection in open array, got %d", lc)
}
// But not for "state=closed"
c = pollConnz(t, s, mode, url+"connz?cid=2&state=closed", &ConnzOptions{CID: 2, State: ConnClosed})
if lc := len(c.Conns); lc != 0 {
return fmt.Errorf("Expected no connections in closed array, got %d", lc)
Expand Down