Skip to content
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
5 changes: 4 additions & 1 deletion server/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"expvar"
"fmt"
"maps"
"math"
"net"
"net/http"
Expand Down Expand Up @@ -282,7 +283,9 @@ func (s *Server) Connz(opts *ConnzOptions) (*Connz, error) {
s.mu.RLock()
// Default to all client unless filled in above.
if clist == nil {
clist = s.clients
clist = make(map[uint64]*client, len(s.clients)+len(s.leafs))
maps.Copy(clist, s.clients)
maps.Copy(clist, s.leafs)
}

// copy the server id for monitoring
Expand Down
90 changes: 88 additions & 2 deletions server/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path/filepath"
"reflect"
"runtime"
"slices"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -5700,8 +5701,11 @@ func TestMonitorConnzOperatorAccountNames(t *testing.T) {
for pollMode := 0; pollMode < 2; pollMode++ {
url := fmt.Sprintf("http://127.0.0.1:%d/connz?auth=1", s.MonitorAddr().Port)
connz := pollConnz(t, s, pollMode, url, &ConnzOptions{Username: true})
require_Equal(t, connz.NumConns, 1)
ci := connz.Conns[0]
require_Equal(t, connz.NumConns, 2)
idx := slices.IndexFunc(connz.Conns, func(c *ConnInfo) bool {
return c.Kind == kindStringMap[CLIENT]
})
ci := connz.Conns[idx]
require_Equal(t, ci.Account, accPub)
require_Equal(t, ci.NameTag, accName)
}
Expand Down Expand Up @@ -5822,6 +5826,88 @@ func TestMonitorConnzSortByRTT(t *testing.T) {
}
}

func TestMonitorConnzIncludesLeafnodes(t *testing.T) {
content := `
server_name: "hub"
listen: "127.0.0.1:-1"
http: "127.0.0.1:-1"
operator = "../test/configs/nkeys/op.jwt"
resolver = MEMORY
ping_interval = 1
leafnodes {
listen: "127.0.0.1:-1"
}
`
conf := createConfFile(t, []byte(content))
sb, ob := RunServerWithConfig(conf)
defer sb.Shutdown()

createAcc := func(t *testing.T) (*Account, string) {
t.Helper()
acc, akp := createAccount(sb)
kp, _ := nkeys.CreateUser()
pub, _ := kp.PublicKey()
nuc := jwt.NewUserClaims(pub)
ujwt, err := nuc.Encode(akp)
if err != nil {
t.Fatalf("Error generating user JWT: %v", err)
}
seed, _ := kp.Seed()
creds := genCredsFile(t, ujwt, seed)
return acc, creds
}
acc, mycreds := createAcc(t)
leafName := "my-leaf-node"

content = `
port: -1
http: "127.0.0.1:-1"
ping_interval = 1
server_name: %s
accounts {
%s {
users [
{user: user1, password: pwd}
]
}
}
leafnodes {
remotes = [
{
account: "%s"
url: nats-leaf://127.0.0.1:%d
credentials: '%s'
}
]
}
`
config := fmt.Sprintf(content,
leafName,
acc.Name,
acc.Name, ob.LeafNode.Port, mycreds)
conf = createConfFile(t, []byte(config))
sa, _ := RunServerWithConfig(conf)
defer sa.Shutdown()

checkFor(t, time.Second, 15*time.Millisecond, func() error {
if n := sa.NumLeafNodes(); n != 1 {
return fmt.Errorf("Expected 1 leaf connection, got %v", n)
}
return nil
})

for test, options := range map[string]*ConnzOptions{
"WithoutAccount": {},
"WithAccount": {Account: acc.Name},
} {
t.Run(test, func(t *testing.T) {
c := pollConnz(t, sb, 1, "http://127.0.0.1:%d/connz", options)
require_Equal(t, c.NumConns, 1)
require_Equal(t, c.Conns[0].Kind, kindStringMap[LEAF])
})
}
}

// https://github.com/nats-io/nats-server/issues/4144
func TestMonitorAccountszMappingOrderReporting(t *testing.T) {
conf := createConfFile(t, []byte(`
Expand Down
Loading