Add MFolderIDsServiceCount to count folderIDs in services pkg (#81237)
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
@@ -62,6 +63,7 @@ func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) respon
|
||||
|
||||
if cmd.FolderUID != nil {
|
||||
if *cmd.FolderUID == "" {
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
cmd.FolderID = 0
|
||||
generalFolderUID := ac.GeneralFolderUID
|
||||
@@ -71,6 +73,7 @@ func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) respon
|
||||
if err != nil || folder == nil {
|
||||
return response.ErrOrFallback(http.StatusBadRequest, "failed to get folder", err)
|
||||
}
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
cmd.FolderID = folder.ID
|
||||
}
|
||||
@@ -81,8 +84,10 @@ func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) respon
|
||||
return toLibraryElementError(err, "Failed to create library element")
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
if element.FolderID != 0 {
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
folder, err := l.folderService.Get(c.Req.Context(), &folder.GetFolderQuery{OrgID: c.SignedInUser.GetOrgID(), ID: &element.FolderID, SignedInUser: c.SignedInUser})
|
||||
if err != nil {
|
||||
@@ -210,6 +215,7 @@ func (l *LibraryElementService) patchHandler(c *contextmodel.ReqContext) respons
|
||||
|
||||
if cmd.FolderUID != nil {
|
||||
if *cmd.FolderUID == "" {
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
cmd.FolderID = 0
|
||||
} else {
|
||||
@@ -217,6 +223,7 @@ func (l *LibraryElementService) patchHandler(c *contextmodel.ReqContext) respons
|
||||
if err != nil || folder == nil {
|
||||
return response.Error(http.StatusBadRequest, "failed to get folder", err)
|
||||
}
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
cmd.FolderID = folder.ID
|
||||
}
|
||||
@@ -227,8 +234,10 @@ func (l *LibraryElementService) patchHandler(c *contextmodel.ReqContext) respons
|
||||
return toLibraryElementError(err, "Failed to update library element")
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
if element.FolderID != 0 {
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
folder, err := l.folderService.Get(c.Req.Context(), &folder.GetFolderQuery{OrgID: c.SignedInUser.GetOrgID(), ID: &element.FolderID, SignedInUser: c.SignedInUser})
|
||||
if err != nil {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/services/libraryelements/model"
|
||||
)
|
||||
|
||||
@@ -84,6 +85,7 @@ func parseFolderFilter(query model.SearchLibraryElementsQuery) FolderFilter {
|
||||
hasFolderFilter := len(strings.TrimSpace(query.FolderFilter)) > 0
|
||||
hasFolderFilterUID := len(strings.TrimSpace(query.FolderFilterUIDs)) > 0
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
result := FolderFilter{
|
||||
includeGeneralFolder: true,
|
||||
folderIDs: folderIDs, // nolint:staticcheck
|
||||
@@ -99,6 +101,7 @@ func parseFolderFilter(query model.SearchLibraryElementsQuery) FolderFilter {
|
||||
if hasFolderFilter {
|
||||
result.includeGeneralFolder = false
|
||||
folderIDs = strings.Split(query.FolderFilter, ",")
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
result.folderIDs = folderIDs
|
||||
for _, filter := range folderIDs {
|
||||
@@ -132,6 +135,7 @@ func parseFolderFilter(query model.SearchLibraryElementsQuery) FolderFilter {
|
||||
func (f *FolderFilter) writeFolderFilterSQL(includeGeneral bool, builder *db.SQLBuilder) error {
|
||||
var sql bytes.Buffer
|
||||
params := make([]any, 0)
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
|
||||
// nolint:staticcheck
|
||||
for _, filter := range f.folderIDs {
|
||||
folderID, err := strconv.ParseInt(filter, 10, 64)
|
||||
|
||||
Reference in New Issue
Block a user