Add MFolderIDsServiceCount to count folderIDs in services pkg (#81237)

This commit is contained in:
idafurjes
2024-01-25 11:10:35 +01:00
committed by GitHub
parent 0d66ad68f8
commit 7e5544ab21
25 changed files with 129 additions and 3 deletions
+12 -1
View File
@@ -17,6 +17,7 @@ import (
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/auth/identity"
"github.com/grafana/grafana/pkg/services/dashboards"
@@ -171,6 +172,7 @@ func (s *Service) Get(ctx context.Context, q *folder.GetFolderQuery) (*folder.Fo
}
// nolint:staticcheck
case q.ID != nil:
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
dashFolder, err = s.getFolderByID(ctx, *q.ID, q.OrgID)
if err != nil {
return nil, err
@@ -206,7 +208,7 @@ func (s *Service) Get(ctx context.Context, q *folder.GetFolderQuery) (*folder.Fo
if !s.features.IsEnabled(ctx, featuremgmt.FlagNestedFolders) {
return dashFolder, nil
}
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
// nolint:staticcheck
if q.ID != nil {
q.ID = nil
@@ -219,6 +221,7 @@ func (s *Service) Get(ctx context.Context, q *folder.GetFolderQuery) (*folder.Fo
}
// always expose the dashboard store sequential ID
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
// nolint:staticcheck
f.ID = dashFolder.ID
f.Version = dashFolder.Version
@@ -287,6 +290,7 @@ func (s *Service) GetChildren(ctx context.Context, q *folder.GetChildrenQuery) (
}
// always expose the dashboard store sequential ID
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
// nolint:staticcheck
f.ID = dashFolder.ID
}
@@ -336,6 +340,7 @@ func (s *Service) getRootFolders(ctx context.Context, q *folder.GetChildrenQuery
s.log.Error("failed to fetch folder by UID from dashboard store", "orgID", f.OrgID, "uid", f.UID)
}
// always expose the dashboard store sequential ID
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
// nolint:staticcheck
f.ID = dashFolder.ID
@@ -591,6 +596,7 @@ func (s *Service) Update(ctx context.Context, cmd *folder.UpdateFolderCommand) (
if cmd.NewTitle != nil {
namespace, id := cmd.SignedInUser.GetNamespacedID()
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
if err := s.bus.Publish(context.Background(), &events.FolderTitleUpdated{
Timestamp: foldr.Updated,
Title: foldr.Title,
@@ -616,6 +622,7 @@ func (s *Service) Update(ctx context.Context, cmd *folder.UpdateFolderCommand) (
}
// always expose the dashboard store sequential ID
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
// nolint:staticcheck
foldr.ID = dashFolder.ID
foldr.Version = dashFolder.Version
@@ -788,6 +795,7 @@ func (s *Service) deleteChildrenInFolder(ctx context.Context, orgID int64, folde
}
func (s *Service) legacyDelete(ctx context.Context, cmd *folder.DeleteFolderCommand, dashFolder *folder.Folder) error {
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
// nolint:staticcheck
deleteCmd := dashboards.DeleteDashboardCommand{OrgID: cmd.OrgID, ID: dashFolder.ID, ForceDeleteFolderRules: cmd.ForceDeleteRules}
@@ -1020,6 +1028,7 @@ func (s *Service) buildSaveDashboardCommand(ctx context.Context, dto *dashboards
}
if dash.ID == 0 {
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
// nolint:staticcheck
if canCreate, err := guard.CanCreate(dash.FolderID, dash.IsFolder); err != nil || !canCreate {
if err != nil {
@@ -1047,6 +1056,7 @@ func (s *Service) buildSaveDashboardCommand(ctx context.Context, dto *dashboards
}
}
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
cmd := &dashboards.SaveDashboardCommand{
Dashboard: dash.Data,
Message: dto.Message,
@@ -1073,6 +1083,7 @@ func getGuardianForSavePermissionCheck(ctx context.Context, d *dashboards.Dashbo
if newDashboard {
// if it's a new dashboard/folder check the parent folder permissions
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
// nolint:staticcheck
guard, err := guardian.New(ctx, d.FolderID, d.OrgID, user)
if err != nil {