Skip to content

Commit

Permalink
[added] system_account to varz/accounts and is_system to accountz (#1898
Browse files Browse the repository at this point in the history
)


Signed-off-by: Matthias Hanel <mh@synadia.com>
  • Loading branch information
matthiashanel authored Feb 8, 2021
1 parent 71b8425 commit 10154c5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ func TestServerEventsPingMonitorz(t *testing.T) {
respField []string
}{
{"VARZ", nil, &Varz{},
[]string{"now", "cpu"}},
[]string{"now", "cpu", "system_account"}},
{"SUBSZ", nil, &Subsz{},
[]string{"num_subscriptions", "num_cache"}},
{"CONNZ", nil, &Connz{},
Expand Down
19 changes: 15 additions & 4 deletions server/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ type Varz struct {
Tags jwt.TagList `json:"tags,omitempty"`
TrustedOperatorsJwt []string `json:"trusted_operators_jwt,omitempty"`
TrustedOperatorsClaim []*jwt.OperatorClaims `json:"trusted_operators_claim,omitempty"`
SystemAccount string `json:"system_account,omitempty"`
}

// JetStreamVarz contains basic runtime information about jetstream
Expand Down Expand Up @@ -1334,6 +1335,9 @@ func (s *Server) updateVarzConfigReloadableFields(v *Varz) {
v.Cluster.URLs = urlsToStrings(opts.Routes)
s.varzUpdateRouteURLs = false
}
if s.sys != nil && s.sys.account != nil {
v.SystemAccount = s.sys.account.GetName()
}
}

// Updates the runtime Varz fields, that is, fields that change during
Expand Down Expand Up @@ -1989,6 +1993,7 @@ type ExtMap map[string][]*MapDest
type AccountInfo struct {
AccountName string `json:"account_name"`
LastUpdate time.Time `json:"update_time,omitempty"`
IsSystem bool `json:"is_system,omitempty"`
Expired bool `json:"expired"`
Complete bool `json:"complete"`
JetStream bool `json:"jetstream_enabled"`
Expand All @@ -2011,10 +2016,11 @@ type AccountInfo struct {
}

type Accountz struct {
ID string `json:"server_id"`
Now time.Time `json:"now"`
Accounts []string `json:"accounts,omitempty"`
Account *AccountInfo `json:"account_detail,omitempty"`
ID string `json:"server_id"`
Now time.Time `json:"now"`
SystemAccount string `json:"system_account,omitempty"`
Accounts []string `json:"accounts,omitempty"`
Account *AccountInfo `json:"account_detail,omitempty"`
}

// HandleAccountz process HTTP requests for account information.
Expand All @@ -2039,6 +2045,9 @@ func (s *Server) Accountz(optz *AccountzOptions) (*Accountz, error) {
ID: s.ID(),
Now: time.Now(),
}
if sacc := s.SystemAccount(); sacc != nil {
a.SystemAccount = sacc.GetName()
}
if optz.Account == "" {
a.Accounts = []string{}
s.accounts.Range(func(key, value interface{}) bool {
Expand Down Expand Up @@ -2086,6 +2095,7 @@ func (s *Server) accountInfo(accName string) (*AccountInfo, error) {
} else {
a = v.(*Account)
}
isSys := a == s.SystemAccount()
a.mu.RLock()
defer a.mu.RUnlock()
var vrIssues []ExtVrIssues
Expand Down Expand Up @@ -2190,6 +2200,7 @@ func (s *Server) accountInfo(accName string) (*AccountInfo, error) {
return &AccountInfo{
accName,
a.updated,
isSys,
a.expired,
!a.incomplete,
a.js != nil,
Expand Down
6 changes: 6 additions & 0 deletions server/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3783,6 +3783,8 @@ func TestMonitorAccountz(t *testing.T) {
t.Fatalf("Body missing value. Contains: %s", body)
} else if !strings.Contains(body, `"accounts": [`) {
t.Fatalf("Body missing value. Contains: %s", body)
} else if !strings.Contains(body, `"system_account": "$SYS"`) {
t.Fatalf("Body missing value. Contains: %s", body)
}
body = string(readBody(t, fmt.Sprintf("http://127.0.0.1:%d/accountz?acc=$SYS", s.MonitorAddr().Port)))
if !strings.Contains(body, `"account_detail": {`) {
Expand All @@ -3791,6 +3793,10 @@ func TestMonitorAccountz(t *testing.T) {
t.Fatalf("Body missing value. Contains: %s", body)
} else if !strings.Contains(body, `"subscriptions": 36,`) {
t.Fatalf("Body missing value. Contains: %s", body)
} else if !strings.Contains(body, `"is_system": true,`) {
t.Fatalf("Body missing value. Contains: %s", body)
} else if !strings.Contains(body, `"system_account": "$SYS"`) {
t.Fatalf("Body missing value. Contains: %s", body)
}
}

Expand Down

0 comments on commit 10154c5

Please sign in to comment.