Access control: Add permissions cache hit/miss metrics (#80883)
* Access control: Add permissions cache hit/miss metrics * Add metrics to OSS * Fix imports
This commit is contained in:
@@ -151,11 +151,13 @@ func (s *Service) getCachedUserPermissions(ctx context.Context, user identity.Re
|
||||
if !options.ReloadCache {
|
||||
permissions, ok := s.cache.Get(key)
|
||||
if ok {
|
||||
metrics.MAccessPermissionsCacheUsage.WithLabelValues(accesscontrol.CacheHit).Inc()
|
||||
s.log.Debug("Using cached permissions", "key", key)
|
||||
return permissions.([]accesscontrol.Permission), nil
|
||||
}
|
||||
}
|
||||
|
||||
metrics.MAccessPermissionsCacheUsage.WithLabelValues(accesscontrol.CacheMiss).Inc()
|
||||
s.log.Debug("Fetch permissions from store", "key", key)
|
||||
permissions, err := s.getUserPermissions(ctx, user, options)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,7 +13,15 @@ import (
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
)
|
||||
|
||||
var ErrInternal = errutil.Internal("accesscontrol.internal")
|
||||
const (
|
||||
CacheHit = "hit"
|
||||
CacheMiss = "miss"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInternal = errutil.Internal("accesscontrol.internal")
|
||||
CacheUsageStatuses = []string{CacheHit, CacheMiss}
|
||||
)
|
||||
|
||||
// RoleRegistration stores a role and its assignments to built-in roles
|
||||
// (Viewer, Editor, Admin, Grafana Admin)
|
||||
|
||||
Reference in New Issue
Block a user