mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 18:32:28 +08:00
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:
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/metrics/metricutil"
|
"github.com/grafana/grafana/pkg/infra/metrics/metricutil"
|
||||||
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
pubdash "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
pubdash "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
@ -104,6 +105,9 @@ var (
|
|||||||
// MAccessEvaluationCount is a metric gauge for total number of evaluation requests
|
// MAccessEvaluationCount is a metric gauge for total number of evaluation requests
|
||||||
MAccessEvaluationCount prometheus.Counter
|
MAccessEvaluationCount prometheus.Counter
|
||||||
|
|
||||||
|
// MAccessPermissionsCacheUsage is a metric counter for cache usage
|
||||||
|
MAccessPermissionsCacheUsage *prometheus.CounterVec
|
||||||
|
|
||||||
// MPublicDashboardRequestCount is a metric counter for public dashboards requests
|
// MPublicDashboardRequestCount is a metric counter for public dashboards requests
|
||||||
MPublicDashboardRequestCount prometheus.Counter
|
MPublicDashboardRequestCount prometheus.Counter
|
||||||
|
|
||||||
@ -590,6 +594,12 @@ func init() {
|
|||||||
Buckets: prometheus.ExponentialBuckets(0.001, 10, 6),
|
Buckets: prometheus.ExponentialBuckets(0.001, 10, 6),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
MAccessPermissionsCacheUsage = metricutil.NewCounterVecStartingAtZero(prometheus.CounterOpts{
|
||||||
|
Name: "access_permissions_cache_usage",
|
||||||
|
Help: "access control permissions cache hit/miss",
|
||||||
|
Namespace: ExporterName,
|
||||||
|
}, []string{"status"}, map[string][]string{"status": accesscontrol.CacheUsageStatuses})
|
||||||
|
|
||||||
StatsTotalLibraryPanels = prometheus.NewGauge(prometheus.GaugeOpts{
|
StatsTotalLibraryPanels = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "stat_totals_library_panels",
|
Name: "stat_totals_library_panels",
|
||||||
Help: "total amount of library panels in the database",
|
Help: "total amount of library panels in the database",
|
||||||
@ -708,6 +718,8 @@ func initMetricVars(reg prometheus.Registerer) {
|
|||||||
MAccessPermissionsSummary,
|
MAccessPermissionsSummary,
|
||||||
MAccessEvaluationsSummary,
|
MAccessEvaluationsSummary,
|
||||||
MAccessSearchPermissionsSummary,
|
MAccessSearchPermissionsSummary,
|
||||||
|
MAccessEvaluationCount,
|
||||||
|
MAccessPermissionsCacheUsage,
|
||||||
MAlertingActiveAlerts,
|
MAlertingActiveAlerts,
|
||||||
MStatTotalDashboards,
|
MStatTotalDashboards,
|
||||||
MStatTotalFolders,
|
MStatTotalFolders,
|
||||||
@ -728,7 +740,6 @@ func initMetricVars(reg prometheus.Registerer) {
|
|||||||
StatsTotalAnnotations,
|
StatsTotalAnnotations,
|
||||||
StatsTotalAlertRules,
|
StatsTotalAlertRules,
|
||||||
StatsTotalRuleGroups,
|
StatsTotalRuleGroups,
|
||||||
MAccessEvaluationCount,
|
|
||||||
StatsTotalLibraryPanels,
|
StatsTotalLibraryPanels,
|
||||||
StatsTotalLibraryVariables,
|
StatsTotalLibraryVariables,
|
||||||
StatsTotalDataKeys,
|
StatsTotalDataKeys,
|
||||||
|
@ -151,11 +151,13 @@ func (s *Service) getCachedUserPermissions(ctx context.Context, user identity.Re
|
|||||||
if !options.ReloadCache {
|
if !options.ReloadCache {
|
||||||
permissions, ok := s.cache.Get(key)
|
permissions, ok := s.cache.Get(key)
|
||||||
if ok {
|
if ok {
|
||||||
|
metrics.MAccessPermissionsCacheUsage.WithLabelValues(accesscontrol.CacheHit).Inc()
|
||||||
s.log.Debug("Using cached permissions", "key", key)
|
s.log.Debug("Using cached permissions", "key", key)
|
||||||
return permissions.([]accesscontrol.Permission), nil
|
return permissions.([]accesscontrol.Permission), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metrics.MAccessPermissionsCacheUsage.WithLabelValues(accesscontrol.CacheMiss).Inc()
|
||||||
s.log.Debug("Fetch permissions from store", "key", key)
|
s.log.Debug("Fetch permissions from store", "key", key)
|
||||||
permissions, err := s.getUserPermissions(ctx, user, options)
|
permissions, err := s.getUserPermissions(ctx, user, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,7 +13,15 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/util/errutil"
|
"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
|
// RoleRegistration stores a role and its assignments to built-in roles
|
||||||
// (Viewer, Editor, Admin, Grafana Admin)
|
// (Viewer, Editor, Admin, Grafana Admin)
|
||||||
|
Reference in New Issue
Block a user