mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Usagestats: Add interface for stats for user.Service and add Usagestats for case_insensitive_login
(#66742)
* add interface for stats * add user service to registry
This commit is contained in:
parent
75fc678d8a
commit
6b8c77c70c
@ -3,13 +3,16 @@ package usagestatssvcs
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/registry"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
|
||||
func ProvideUsageStatsProvidersRegistry(
|
||||
accesscontrol accesscontrol.Service,
|
||||
user user.Service,
|
||||
) *UsageStatsProvidersRegistry {
|
||||
return NewUsageStatsProvidersRegistry(
|
||||
accesscontrol,
|
||||
user,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,12 @@ package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/registry"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
registry.ProvidesUsageStats
|
||||
Create(context.Context, *CreateUserCommand) (*User, error)
|
||||
CreateServiceAccount(context.Context, *CreateUserCommand) (*User, error)
|
||||
Delete(context.Context, *DeleteUserCommand) error
|
||||
|
@ -67,6 +67,17 @@ func ProvideService(
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetUsageStats(ctx context.Context) map[string]interface{} {
|
||||
stats := map[string]interface{}{}
|
||||
caseInsensitiveLoginVal := 0
|
||||
if s.cfg.CaseInsensitiveLogin {
|
||||
caseInsensitiveLoginVal = 1
|
||||
}
|
||||
|
||||
stats["stats.case_insensitive_login.count"] = caseInsensitiveLoginVal
|
||||
return stats
|
||||
}
|
||||
|
||||
func (s *Service) Usage(ctx context.Context, _ *quota.ScopeParameters) (*quota.Map, error) {
|
||||
u := "a.Map{}
|
||||
if used, err := s.store.Count(ctx); err != nil {
|
||||
|
@ -14,6 +14,7 @@ type FakeUserService struct {
|
||||
ExpectedSearchUsers user.SearchUserQueryResult
|
||||
ExpectedUserProfileDTO *user.UserProfileDTO
|
||||
ExpectedUserProfileDTOs []*user.UserProfileDTO
|
||||
ExpectedUsageStats map[string]interface{}
|
||||
|
||||
GetSignedInUserFn func(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error)
|
||||
CreateFn func(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error)
|
||||
@ -26,6 +27,10 @@ func NewUserServiceFake() *FakeUserService {
|
||||
return &FakeUserService{}
|
||||
}
|
||||
|
||||
func (f FakeUserService) GetUsageStats(ctx context.Context) map[string]interface{} {
|
||||
return f.ExpectedUsageStats
|
||||
}
|
||||
|
||||
func (f *FakeUserService) Create(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
|
||||
if f.CreateFn != nil {
|
||||
return f.CreateFn(ctx, cmd)
|
||||
|
Loading…
Reference in New Issue
Block a user