Skip to content

Commit

Permalink
[FIXED] Service imports reporting for Accountz() when mapping to loca…
Browse files Browse the repository at this point in the history
…l subjects. (#4158)

Signed-off-by: Derek Collison <derek@nats.io>

Resolves #4144
  • Loading branch information
derekcollison committed May 15, 2023
2 parents ea75bea + d293af1 commit fe71ef5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
17 changes: 10 additions & 7 deletions server/monitor.go
Expand Up @@ -2446,19 +2446,20 @@ func (s *Server) Accountz(optz *AccountzOptions) (*Accountz, error) {
if sacc := s.SystemAccount(); sacc != nil {
a.SystemAccount = sacc.GetName()
}
if optz.Account == "" {
if optz == nil || optz.Account == _EMPTY_ {
a.Accounts = []string{}
s.accounts.Range(func(key, value interface{}) bool {
a.Accounts = append(a.Accounts, key.(string))
return true
})
return a, nil
} else if aInfo, err := s.accountInfo(optz.Account); err != nil {
}
aInfo, err := s.accountInfo(optz.Account)
if err != nil {
return nil, err
} else {
a.Account = aInfo
return a, nil
}
a.Account = aInfo
return a, nil
}

func newExtImport(v *serviceImport) ExtImport {
Expand All @@ -2471,10 +2472,12 @@ func newExtImport(v *serviceImport) ExtImport {
imp.Tracking = v.tracking
imp.Invalid = v.invalid
imp.Import = jwt.Import{
Subject: jwt.Subject(v.from),
Subject: jwt.Subject(v.to),
Account: v.acc.Name,
Type: jwt.Service,
To: jwt.Subject(v.to),
// Deprecated so we duplicate. Use LocalSubject.
To: jwt.Subject(v.from),
LocalSubject: jwt.RenamingSubject(v.from),
}
imp.TrackingHdr = v.trackingHdr
imp.Latency = newExtServiceLatency(v.latency)
Expand Down
33 changes: 33 additions & 0 deletions server/monitor_test.go
Expand Up @@ -4734,3 +4734,36 @@ func TestMonitorConnzSortByRTT(t *testing.T) {
}
}
}

// https://github.com/nats-io/nats-server/issues/4144
func TestMonitorAccountszMappingOrderReporting(t *testing.T) {
conf := createConfFile(t, []byte(`
listen: 127.0.0.1:-1
server_name: SR22
accounts {
CLOUD {
exports [ { service: "downlink.>" } ]
}
APP {
imports [ { service: { account: CLOUD, subject: "downlink.>"}, to: "event.>"} ]
}
}`))

s, _ := RunServerWithConfig(conf)
defer s.Shutdown()

az, err := s.Accountz(&AccountzOptions{"APP"})
require_NoError(t, err)
require_NotNil(t, az.Account)
require_True(t, len(az.Account.Imports) > 0)

var found bool
for _, si := range az.Account.Imports {
if si.Import.Subject == "downlink.>" {
found = true
require_True(t, si.Import.LocalSubject == "event.>")
break
}
}
require_True(t, found)
}

0 comments on commit fe71ef5

Please sign in to comment.