Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Hanel <mh@synadia.com>
  • Loading branch information
matthiashanel committed Jul 12, 2022
1 parent 58171a8 commit 0b50828
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
11 changes: 6 additions & 5 deletions server/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const DisconnectEventMsgType = "io.nats.server.advisory.v1.client_disconnect"
type AccountNumConns struct {
TypedEvent
Server ServerInfo `json:"server"`
*AccountStat
AccountStat
}

// AccountStat contains the data common between AccountNumConns and AccountStatz
Expand Down Expand Up @@ -901,7 +901,7 @@ func (s *Server) initEventTracking() {
return _EMPTY_, fmt.Errorf("bad request")
}
}
return tk[accReqAccIndex], nil
return acc, nil
}
}
monAccSrvc := map[string]msgHandler{
Expand Down Expand Up @@ -968,7 +968,7 @@ func (s *Server) initEventTracking() {
s.zReq(c, reply, msg, &optz.EventFilterOptions, optz, func() (interface{}, error) {
if acc, err := extractAccount(c, subject, msg); err != nil {
return nil, err
} else if acc == "PING" { // Filter ping subject, this happens for server too, but filter is less explicit
} else if acc == "PING" { // Filter PING subject. Happens for server as well. But wildcards are not used
return nil, errSkipZreq
} else {
optz.Accounts = []string{acc}
Expand Down Expand Up @@ -1701,13 +1701,14 @@ func (s *Server) sendAccConnsUpdate(a *Account, subj ...string) {
// Build event with account name and number of local clients and leafnodes.
eid := s.nextEventID()
a.mu.Lock()
stat := a.statz()
m := AccountNumConns{
TypedEvent: TypedEvent{
Type: AccountNumConnsMsgType,
ID: eid,
Time: time.Now().UTC(),
},
AccountStat: a.accConns(),
AccountStat: *stat,
}
// Set timer to fire again unless we are at zero, but only if the account
// is not configured for JetStream.
Expand All @@ -1729,7 +1730,7 @@ func (s *Server) sendAccConnsUpdate(a *Account, subj ...string) {
}

// Lock shoulc be held on entry
func (a *Account) accConns() *AccountStat {
func (a *Account) statz() *AccountStat {
localConns := a.numLocalConnections()
leafConns := a.numLocalLeafNodes()
return &AccountStat{
Expand Down
13 changes: 3 additions & 10 deletions server/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ type ConnzOptions struct {

// Filter by subject interest
FilterSubject string `json:"filter_subject"`

// Private indication that this request is from an account and not a system account.
// Used to not leak system level information to the account.
isAccountReq bool
}

// ConnState is for filtering states of connections. We will only have two, open and closed.
Expand Down Expand Up @@ -256,9 +252,6 @@ func (s *Server) Connz(opts *ConnzOptions) (*Connz, error) {

var clist map[uint64]*client

// If this is an account scoped request from a no $SYS account.
isAccReq := acc != _EMPTY_ && opts.isAccountReq

if acc != _EMPTY_ {
var err error
a, err = s.lookupAccount(acc)
Expand Down Expand Up @@ -300,7 +293,7 @@ func (s *Server) Connz(opts *ConnzOptions) (*Connz, error) {
}

// We may need to filter these connections.
if isAccReq && len(closedClients) > 0 {
if acc != _EMPTY_ && len(closedClients) > 0 {
var ccc []*closedClient
for _, cc := range closedClients {
if cc.acc == acc {
Expand Down Expand Up @@ -2183,7 +2176,7 @@ func (s *Server) AccountStatz(opts *AccountStatzOptions) (*AccountStatz, error)
acc := a.(*Account)
acc.mu.RLock()
if opts.IncludeUnused || acc.numLocalConnections() != 0 {
stz.Accounts = append(stz.Accounts, acc.accConns())
stz.Accounts = append(stz.Accounts, acc.statz())
}
acc.mu.RUnlock()
return true
Expand All @@ -2194,7 +2187,7 @@ func (s *Server) AccountStatz(opts *AccountStatzOptions) (*AccountStatz, error)
acc := acc.(*Account)
acc.mu.RLock()
if opts.IncludeUnused || acc.numLocalConnections() != 0 {
stz.Accounts = append(stz.Accounts, acc.accConns())
stz.Accounts = append(stz.Accounts, acc.statz())
}
acc.mu.RUnlock()
}
Expand Down

0 comments on commit 0b50828

Please sign in to comment.