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

[FIXED] Service imports reporting for Accountz() when mapping to local subjects. #4158

Merged
merged 1 commit into from May 15, 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
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)
}