Skip to content
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

Update LEAFZ to include leafnode server/connection name #3923

Merged
merged 1 commit into from Feb 28, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion server/leafnode.go
Expand Up @@ -888,7 +888,13 @@ func (s *Server) createLeafNode(conn net.Conn, rURL *url.URL, remote *leafNodeCf
}
now := time.Now().UTC()

c := &client{srv: s, nc: conn, kind: LEAF, opts: defaultOpts, mpay: maxPay, msubs: maxSubs, start: now, last: now}
var clientOpts = ClientOpts{
Name: opts.ServerName,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only bit I'm not feeling 100% about. For outgoing connections I set the Name as the current server name. I believe this is probably what we want, since folks looking at LEAFZ should be able to tell the difference between incoming and outgoing connections here, but would like some feedback

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LMK if you want me to merge it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go for it!

Verbose: defaultOpts.Verbose,
Pedantic: defaultOpts.Pedantic,
Echo: defaultOpts.Echo,
}
c := &client{srv: s, nc: conn, kind: LEAF, opts: clientOpts, mpay: maxPay, msubs: maxSubs, start: now, last: now}
// Do not update the smap here, we need to do it in initLeafNodeSmapAndSendSubs
c.leaf = &leaf{}

Expand Down
2 changes: 2 additions & 0 deletions server/monitor.go
Expand Up @@ -2094,6 +2094,7 @@ type LeafzOptions struct {

// LeafInfo has detailed information on each remote leafnode connection.
type LeafInfo struct {
Name string `json:"name"`
Account string `json:"account"`
IP string `json:"ip"`
Port int `json:"port"`
Expand Down Expand Up @@ -2133,6 +2134,7 @@ func (s *Server) Leafz(opts *LeafzOptions) (*Leafz, error) {
for _, ln := range lconns {
ln.mu.Lock()
lni := &LeafInfo{
Name: ln.opts.Name,
Account: ln.acc.Name,
IP: ln.host,
Port: int(ln.port),
Expand Down
9 changes: 9 additions & 0 deletions server/monitor_test.go
Expand Up @@ -3707,11 +3707,13 @@ func TestMonitorLeafz(t *testing.T) {
}
acc1, mycreds1 := createAcc(t)
acc2, mycreds2 := createAcc(t)
leafName := "my-leaf-node"

content = `
port: -1
http: "127.0.0.1:-1"
ping_interval = 1
server_name: %s
accounts {
%s {
users [
Expand Down Expand Up @@ -3740,6 +3742,7 @@ func TestMonitorLeafz(t *testing.T) {
}
`
config := fmt.Sprintf(content,
leafName,
acc1.Name, acc2.Name,
acc1.Name, ob.LeafNode.Port, mycreds1,
acc2.Name, ob.LeafNode.Port, mycreds2)
Expand Down Expand Up @@ -3814,6 +3817,9 @@ func TestMonitorLeafz(t *testing.T) {
} else {
t.Fatalf("Expected account to be %q or %q, got %q", acc1.Name, acc2.Name, ln.Account)
}
if ln.Name != leafName {
t.Fatalf("Expected name to be %q, got %q", leafName, ln.Name)
}
if ln.RTT == "" {
t.Fatalf("RTT not tracked?")
}
Expand Down Expand Up @@ -3902,6 +3908,9 @@ func TestMonitorLeafz(t *testing.T) {
} else {
t.Fatalf("Expected account to be %q or %q, got %q", acc1.Name, acc2.Name, ln.Account)
}
if ln.Name != leafName {
t.Fatalf("Expected name to be %q, got %q", leafName, ln.Name)
}
if ln.RTT == "" {
t.Fatalf("RTT not tracked?")
}
Expand Down