mirror of
https://github.com/grafana/grafana.git
synced 2026-08-26 21:37:31 -05:00
Add MFolderIDsServiceCount to count folderIDs in services pkg (#81237)
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/kinds/librarypanel"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/auth/identity"
|
||||
@@ -146,6 +147,7 @@ func (l *LibraryElementService) createLibraryElement(c context.Context, signedIn
|
||||
}
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
element := model.LibraryElement{
|
||||
OrgID: signedInUser.GetOrgID(),
|
||||
FolderID: cmd.FolderID, // nolint:staticcheck
|
||||
@@ -176,6 +178,7 @@ func (l *LibraryElementService) createLibraryElement(c context.Context, signedIn
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
if err := l.requireEditPermissionsOnFolder(c, signedInUser, cmd.FolderID); err != nil {
|
||||
return err
|
||||
@@ -190,6 +193,7 @@ func (l *LibraryElementService) createLibraryElement(c context.Context, signedIn
|
||||
return nil
|
||||
})
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
dto := model.LibraryElementDTO{
|
||||
ID: element.ID,
|
||||
OrgID: element.OrgID,
|
||||
@@ -229,6 +233,7 @@ func (l *LibraryElementService) deleteLibraryElement(c context.Context, signedIn
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
if err := l.requireEditPermissionsOnFolder(c, signedInUser, element.FolderID); err != nil {
|
||||
return err
|
||||
@@ -280,6 +285,7 @@ func (l *LibraryElementService) getLibraryElements(c context.Context, store db.D
|
||||
builder.Write(", ? as folder_name ", cmd.FolderName)
|
||||
builder.Write(", '' as folder_uid ")
|
||||
builder.Write(getFromLibraryElementDTOWithMeta(store.GetDialect()))
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
writeParamSelectorSQL(&builder, append(params, Pair{"folder_id", cmd.FolderID})...)
|
||||
builder.Write(" UNION ")
|
||||
@@ -314,6 +320,7 @@ func (l *LibraryElementService) getLibraryElements(c context.Context, store db.D
|
||||
}
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
leDtos[i] = model.LibraryElementDTO{
|
||||
ID: libraryElement.ID,
|
||||
OrgID: libraryElement.OrgID,
|
||||
@@ -434,6 +441,7 @@ func (l *LibraryElementService) getAllLibraryElements(c context.Context, signedI
|
||||
return err
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
retDTOs := make([]model.LibraryElementDTO, 0)
|
||||
for _, element := range elements {
|
||||
retDTOs = append(retDTOs, model.LibraryElementDTO{
|
||||
@@ -526,6 +534,7 @@ func (l *LibraryElementService) handleFolderIDPatches(ctx context.Context, eleme
|
||||
if err := l.requireEditPermissionsOnFolder(ctx, user, fromFolderID); err != nil {
|
||||
return err
|
||||
}
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
elementToPatch.FolderID = toFolderID
|
||||
|
||||
@@ -573,6 +582,7 @@ func (l *LibraryElementService) patchLibraryElement(c context.Context, signedInU
|
||||
}
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
var libraryElement = model.LibraryElement{
|
||||
ID: elementInDB.ID,
|
||||
OrgID: signedInUser.GetOrgID(),
|
||||
@@ -596,6 +606,7 @@ func (l *LibraryElementService) patchLibraryElement(c context.Context, signedInU
|
||||
if cmd.Model == nil {
|
||||
libraryElement.Model = elementInDB.Model
|
||||
}
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
if err := l.handleFolderIDPatches(c, &libraryElement, elementInDB.FolderID, cmd.FolderID, signedInUser); err != nil {
|
||||
return err
|
||||
@@ -612,6 +623,7 @@ func (l *LibraryElementService) patchLibraryElement(c context.Context, signedInU
|
||||
return model.ErrLibraryElementNotFound
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
dto = model.LibraryElementDTO{
|
||||
ID: libraryElement.ID,
|
||||
OrgID: libraryElement.OrgID,
|
||||
@@ -711,6 +723,7 @@ func (l *LibraryElementService) getElementsForDashboardID(c context.Context, das
|
||||
return err
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
for _, element := range libraryElements {
|
||||
libraryElementMap[element.UID] = model.LibraryElementDTO{
|
||||
ID: element.ID,
|
||||
@@ -761,6 +774,7 @@ func (l *LibraryElementService) connectElementsToDashboardID(c context.Context,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
if err := l.requireViewPermissionsOnFolder(c, signedInUser, element.FolderID); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user