Add leftover metrics for FolderID (#81246)

This commit is contained in:
idafurjes 2024-01-25 12:14:18 +01:00 committed by GitHub
parent 85429f7bd0
commit 0880a239f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 9 deletions

View File

@ -65,7 +65,7 @@ func (hs *HTTPServer) GetFolders(c *contextmodel.ReqContext) response.Response {
Title: f.Title,
ParentUID: f.ParentUID,
})
metrics.MFolderIDsAPICount.WithLabelValues("GetFolders").Inc()
metrics.MFolderIDsAPICount.WithLabelValues(metrics.GetFolders).Inc()
}
return response.JSON(http.StatusOK, hits)
@ -124,7 +124,7 @@ func (hs *HTTPServer) GetFolderByID(c *contextmodel.ReqContext) response.Respons
if err != nil {
return response.Error(http.StatusBadRequest, "id is invalid", err)
}
metrics.MFolderIDsAPICount.WithLabelValues("GetFolderByID").Inc()
metrics.MFolderIDsAPICount.WithLabelValues(metrics.GetFolderByID).Inc()
// nolint:staticcheck
folder, err := hs.folderService.Get(c.Req.Context(), &folder.GetFolderQuery{ID: &id, OrgID: c.SignedInUser.GetOrgID(), SignedInUser: c.SignedInUser})
if err != nil {
@ -372,7 +372,7 @@ func (hs *HTTPServer) newToFolderDto(c *contextmodel.ReqContext, f *folder.Folde
}, nil
}
}
metrics.MFolderIDsAPICount.WithLabelValues("newToFolderDto").Inc()
metrics.MFolderIDsAPICount.WithLabelValues(metrics.NewToFolderDTO).Inc()
return dtos.Folder{
ID: f.ID, // nolint:staticcheck
UID: f.UID,
@ -472,7 +472,7 @@ func (hs *HTTPServer) searchFolders(c *contextmodel.ReqContext) ([]dtos.FolderSe
UID: hit.UID,
Title: hit.Title,
})
metrics.MFolderIDsAPICount.WithLabelValues("searchFolders").Inc()
metrics.MFolderIDsAPICount.WithLabelValues(metrics.SearchFolders).Inc()
}
return folderHits, nil

View File

@ -235,6 +235,8 @@ const (
GetFolderACL string = "getFolderACL"
Search string = "Search"
GetDashboardACL string = "getDashboardACL"
NewToFolderDTO string = "newToFolderDto"
GetFolders string = "GetFolders"
// FolderID services
Folder string = "folder"
Dashboard string = "dashboards"
@ -245,13 +247,14 @@ const (
PublicDashboards string = "publicdashboards"
AccessControl string = "accesscontrol"
Guardian string = "guardian"
DashboardImport string = "dashboardimport"
)
func init() {
httpStatusCodes := []string{"200", "404", "500", "unknown"}
objectiveMap := map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
apiFolderIDMethods := []string{GetAlerts, GetDashboard, RestoreDashboardVersion, GetFolderByID, GetFolderDescendantCounts, SearchFolders, GetFolderPermissionList, UpdateFolderPermissions, GetFolderACL, Search, GetDashboardACL}
serviceFolderIDMethods := []string{Folder, Dashboard, LibraryElements, LibraryPanels, NGAlerts, Provisioning, PublicDashboards, AccessControl, Guardian, Search}
apiFolderIDMethods := []string{GetAlerts, GetDashboard, RestoreDashboardVersion, GetFolderByID, GetFolderDescendantCounts, SearchFolders, GetFolderPermissionList, UpdateFolderPermissions, GetFolderACL, Search, GetDashboardACL, NewToFolderDTO, GetFolders}
serviceFolderIDMethods := []string{Folder, Dashboard, LibraryElements, LibraryPanels, NGAlerts, Provisioning, PublicDashboards, AccessControl, Guardian, Search, DashboardImport}
MInstanceStart = prometheus.NewCounter(prometheus.CounterOpts{
Name: "instance_start_total",

View File

@ -84,7 +84,7 @@ func (s *ImportDashboardService) ImportDashboard(ctx context.Context, req *dashb
generatedDash.Del("__inputs")
generatedDash.Del("__requires")
metrics.MFolderIDsServiceCount.WithLabelValues("dashboardimport").Inc()
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.DashboardImport).Inc()
// here we need to get FolderId from FolderUID if it present in the request, if both exist, FolderUID would overwrite FolderID
if req.FolderUid != "" {
folder, err := s.folderService.Get(ctx, &folder.GetFolderQuery{
@ -139,7 +139,7 @@ func (s *ImportDashboardService) ImportDashboard(ctx context.Context, req *dashb
return nil, err
}
metrics.MFolderIDsServiceCount.WithLabelValues("dashboardimport").Inc()
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.DashboardImport).Inc()
// nolint:staticcheck
err = s.libraryPanelService.ImportLibraryPanelsForDashboard(ctx, req.User, libraryElements, generatedDash.Get("panels").MustArray(), req.FolderId)
if err != nil {
@ -152,7 +152,7 @@ func (s *ImportDashboardService) ImportDashboard(ctx context.Context, req *dashb
}
revision := savedDashboard.Data.Get("revision").MustInt64(0)
metrics.MFolderIDsServiceCount.WithLabelValues("dashboardimport").Inc()
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.DashboardImport).Inc()
return &dashboardimport.ImportDashboardResponse{
UID: savedDashboard.UID,
PluginId: req.PluginId,