mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
Service accounts: add usagestats for teams (#51585)
* remove enabled service account count * add service account count in teams * removed unnessecary comment
This commit is contained in:
parent
b45c71c9ca
commit
c5089f1595
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *ServiceAccountsStoreImpl) GetUsageMetrics(ctx context.Context) (map[string]interface{}, error) {
|
||||
stats := map[string]interface{}{"stats.serviceaccounts.enabled.count": int64(1)}
|
||||
stats := map[string]interface{}{}
|
||||
|
||||
sb := &sqlstore.SQLBuilder{}
|
||||
dialect := s.sqlStore.Dialect
|
||||
@ -15,11 +15,16 @@ func (s *ServiceAccountsStoreImpl) GetUsageMetrics(ctx context.Context) (map[str
|
||||
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("user") +
|
||||
` WHERE is_service_account = ` + dialect.BooleanStr(true) + `) AS serviceaccounts,`)
|
||||
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("api_key") +
|
||||
` WHERE service_account_id IS NOT NULL ) AS serviceaccount_tokens`)
|
||||
` WHERE service_account_id IS NOT NULL ) AS serviceaccount_tokens,`)
|
||||
// Add count to how many service accounts are in teams
|
||||
sb.Write(`(SELECT COUNT(*) FROM team_member
|
||||
JOIN ` + dialect.Quote("user") + ` on team_member.user_id=` + dialect.Quote("user") + `.id
|
||||
WHERE ` + dialect.Quote("user") + `.is_service_account=` + dialect.BooleanStr(true) + ` ) as serviceaccounts_in_teams`)
|
||||
|
||||
type saStats struct {
|
||||
ServiceAccounts int64 `xorm:"serviceaccounts"`
|
||||
Tokens int64 `xorm:"serviceaccount_tokens"`
|
||||
InTeams int64 `xorm:"serviceaccounts_in_teams"`
|
||||
}
|
||||
|
||||
var sqlStats saStats
|
||||
@ -32,6 +37,7 @@ func (s *ServiceAccountsStoreImpl) GetUsageMetrics(ctx context.Context) (map[str
|
||||
|
||||
stats["stats.serviceaccounts.count"] = sqlStats.ServiceAccounts
|
||||
stats["stats.serviceaccounts.tokens.count"] = sqlStats.Tokens
|
||||
stats["stats.serviceaccounts.in_teams.count"] = sqlStats.InTeams
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
@ -37,5 +37,5 @@ func TestStore_UsageStats(t *testing.T) {
|
||||
|
||||
assert.Equal(t, int64(1), stats["stats.serviceaccounts.count"].(int64))
|
||||
assert.Equal(t, int64(1), stats["stats.serviceaccounts.tokens.count"].(int64))
|
||||
assert.Equal(t, int64(1), stats["stats.serviceaccounts.enabled.count"].(int64))
|
||||
assert.Equal(t, int64(0), stats["stats.serviceaccounts.in_teams.count"].(int64))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user