Add MFolderIDsAPICount metric to count FolderIDs in api package (#80866)
* Add MFolderIDsAPICount metric to cound FolderIDs in api package * Change counter to counter vector with method names as string values
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/api/response"
|
"github.com/grafana/grafana/pkg/api/response"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||||
"github.com/grafana/grafana/pkg/services/alerting"
|
"github.com/grafana/grafana/pkg/services/alerting"
|
||||||
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
|
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
|
||||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||||
@@ -101,6 +102,7 @@ func (hs *HTTPServer) GetAlerts(c *contextmodel.ReqContext) response.Response {
|
|||||||
folderID, err := strconv.ParseInt(id, 10, 64)
|
folderID, err := strconv.ParseInt(id, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
folderIDs = append(folderIDs, folderID)
|
folderIDs = append(folderIDs, folderID)
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues(metrics.GetAlerts).Inc()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,12 +172,13 @@ func (hs *HTTPServer) GetDashboard(c *contextmodel.ReqContext) response.Response
|
|||||||
AnnotationsPermissions: annotationPermissions,
|
AnnotationsPermissions: annotationPermissions,
|
||||||
PublicDashboardEnabled: publicDashboardEnabled,
|
PublicDashboardEnabled: publicDashboardEnabled,
|
||||||
}
|
}
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues(metrics.GetDashboard).Inc()
|
||||||
// lookup folder title
|
// lookup folder title
|
||||||
// nolint:staticcheck
|
// nolint:staticcheck
|
||||||
if dash.FolderID > 0 {
|
if dash.FolderID > 0 {
|
||||||
// nolint:staticcheck
|
// nolint:staticcheck
|
||||||
query := dashboards.GetDashboardQuery{ID: dash.FolderID, OrgID: c.SignedInUser.GetOrgID()}
|
query := dashboards.GetDashboardQuery{ID: dash.FolderID, OrgID: c.SignedInUser.GetOrgID()}
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues(metrics.GetDashboard).Inc()
|
||||||
queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, dashboards.ErrFolderNotFound) {
|
if errors.Is(err, dashboards.ErrFolderNotFound) {
|
||||||
@@ -974,6 +975,7 @@ func (hs *HTTPServer) RestoreDashboardVersion(c *contextmodel.ReqContext) respon
|
|||||||
saveCmd.Message = fmt.Sprintf("Restored from version %d", version.Version)
|
saveCmd.Message = fmt.Sprintf("Restored from version %d", version.Version)
|
||||||
// nolint:staticcheck
|
// nolint:staticcheck
|
||||||
saveCmd.FolderID = dash.FolderID
|
saveCmd.FolderID = dash.FolderID
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues(metrics.RestoreDashboardVersion).Inc()
|
||||||
saveCmd.FolderUID = dash.FolderUID
|
saveCmd.FolderUID = dash.FolderUID
|
||||||
|
|
||||||
return hs.postDashboard(c, saveCmd)
|
return hs.postDashboard(c, saveCmd)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/api/response"
|
"github.com/grafana/grafana/pkg/api/response"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/auth/identity"
|
"github.com/grafana/grafana/pkg/services/auth/identity"
|
||||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||||
@@ -193,6 +194,7 @@ func (hs *HTTPServer) getDashboardACL(ctx context.Context, user identity.Request
|
|||||||
|
|
||||||
permission := dashboardPermissionMap[hs.dashboardPermissionsService.MapActions(p)]
|
permission := dashboardPermissionMap[hs.dashboardPermissionsService.MapActions(p)]
|
||||||
|
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues(metrics.GetDashboardACL).Inc()
|
||||||
acl = append(acl, &dashboards.DashboardACLInfoDTO{
|
acl = append(acl, &dashboards.DashboardACLInfoDTO{
|
||||||
OrgID: dashboard.OrgID,
|
OrgID: dashboard.OrgID,
|
||||||
DashboardID: dashboard.ID,
|
DashboardID: dashboard.ID,
|
||||||
|
|||||||
+5
-1
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/api/apierrors"
|
"github.com/grafana/grafana/pkg/api/apierrors"
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/api/response"
|
"github.com/grafana/grafana/pkg/api/response"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/auth/identity"
|
"github.com/grafana/grafana/pkg/services/auth/identity"
|
||||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||||
@@ -64,6 +65,7 @@ func (hs *HTTPServer) GetFolders(c *contextmodel.ReqContext) response.Response {
|
|||||||
Title: f.Title,
|
Title: f.Title,
|
||||||
ParentUID: f.ParentUID,
|
ParentUID: f.ParentUID,
|
||||||
})
|
})
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues("GetFolders").Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.JSON(http.StatusOK, hits)
|
return response.JSON(http.StatusOK, hits)
|
||||||
@@ -122,6 +124,7 @@ func (hs *HTTPServer) GetFolderByID(c *contextmodel.ReqContext) response.Respons
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||||
}
|
}
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues("GetFolderByID").Inc()
|
||||||
// nolint:staticcheck
|
// nolint:staticcheck
|
||||||
folder, err := hs.folderService.Get(c.Req.Context(), &folder.GetFolderQuery{ID: &id, OrgID: c.SignedInUser.GetOrgID(), SignedInUser: c.SignedInUser})
|
folder, err := hs.folderService.Get(c.Req.Context(), &folder.GetFolderQuery{ID: &id, OrgID: c.SignedInUser.GetOrgID(), SignedInUser: c.SignedInUser})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -369,7 +372,7 @@ func (hs *HTTPServer) newToFolderDto(c *contextmodel.ReqContext, f *folder.Folde
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues("newToFolderDto").Inc()
|
||||||
return dtos.Folder{
|
return dtos.Folder{
|
||||||
ID: f.ID, // nolint:staticcheck
|
ID: f.ID, // nolint:staticcheck
|
||||||
UID: f.UID,
|
UID: f.UID,
|
||||||
@@ -469,6 +472,7 @@ func (hs *HTTPServer) searchFolders(c *contextmodel.ReqContext) ([]dtos.FolderSe
|
|||||||
UID: hit.UID,
|
UID: hit.UID,
|
||||||
Title: hit.Title,
|
Title: hit.Title,
|
||||||
})
|
})
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues("searchFolders").Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
return folderHits, nil
|
return folderHits, nil
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/api/apierrors"
|
"github.com/grafana/grafana/pkg/api/apierrors"
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/api/response"
|
"github.com/grafana/grafana/pkg/api/response"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||||
"github.com/grafana/grafana/pkg/services/auth/identity"
|
"github.com/grafana/grafana/pkg/services/auth/identity"
|
||||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
@@ -45,7 +46,7 @@ func (hs *HTTPServer) GetFolderPermissionList(c *contextmodel.ReqContext) respon
|
|||||||
if perm.UserID > 0 && dtos.IsHiddenUser(perm.UserLogin, c.SignedInUser, hs.Cfg) {
|
if perm.UserID > 0 && dtos.IsHiddenUser(perm.UserLogin, c.SignedInUser, hs.Cfg) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues(metrics.GetFolderPermissionList).Inc()
|
||||||
// nolint:staticcheck
|
// nolint:staticcheck
|
||||||
perm.FolderID = folder.ID
|
perm.FolderID = folder.ID
|
||||||
perm.DashboardID = 0
|
perm.DashboardID = 0
|
||||||
@@ -103,6 +104,7 @@ func (hs *HTTPServer) UpdateFolderPermissions(c *contextmodel.ReqContext) respon
|
|||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
Updated: time.Now(),
|
Updated: time.Now(),
|
||||||
})
|
})
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues(metrics.UpdateFolderPermissions).Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
acl, err := hs.getFolderACL(c.Req.Context(), c.SignedInUser, folder)
|
acl, err := hs.getFolderACL(c.Req.Context(), c.SignedInUser, folder)
|
||||||
@@ -166,6 +168,7 @@ func (hs *HTTPServer) getFolderACL(ctx context.Context, user identity.Requester,
|
|||||||
IsFolder: true,
|
IsFolder: true,
|
||||||
Inherited: false,
|
Inherited: false,
|
||||||
})
|
})
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues(metrics.GetFolderPermissionList).Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
return acl, nil
|
return acl, nil
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ func (hs *HTTPServer) Search(c *contextmodel.ReqContext) response.Response {
|
|||||||
folderID, err := strconv.ParseInt(id, 10, 64)
|
folderID, err := strconv.ParseInt(id, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
folderIDs = append(folderIDs, folderID)
|
folderIDs = append(folderIDs, folderID)
|
||||||
|
metrics.MFolderIDsAPICount.WithLabelValues(metrics.Search).Inc()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ var (
|
|||||||
|
|
||||||
// MPublicDashboardDatasourceQuerySuccess is a metric counter for successful queries labelled by datasource
|
// MPublicDashboardDatasourceQuerySuccess is a metric counter for successful queries labelled by datasource
|
||||||
MPublicDashboardDatasourceQuerySuccess *prometheus.CounterVec
|
MPublicDashboardDatasourceQuerySuccess *prometheus.CounterVec
|
||||||
|
|
||||||
|
// MFolderIDsAPICount is a metric counter for folder ids count in the api package
|
||||||
|
MFolderIDsAPICount *prometheus.CounterVec
|
||||||
)
|
)
|
||||||
|
|
||||||
// Timers
|
// Timers
|
||||||
@@ -216,9 +219,24 @@ var (
|
|||||||
MStatTotalCorrelations prometheus.Gauge
|
MStatTotalCorrelations prometheus.Gauge
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
GetAlerts string = "GetAlerts"
|
||||||
|
GetDashboard string = "GetDashboard"
|
||||||
|
RestoreDashboardVersion string = "RestoreDashboardVersion"
|
||||||
|
GetFolderByID string = "GetFolderByID"
|
||||||
|
GetFolderDescendantCounts string = "GetFolderDescendantCounts"
|
||||||
|
SearchFolders string = "searchFolders"
|
||||||
|
GetFolderPermissionList string = "GetFolderPermissionList"
|
||||||
|
UpdateFolderPermissions string = "UpdateFolderPermissions"
|
||||||
|
GetFolderACL string = "getFolderACL"
|
||||||
|
Search string = "Search"
|
||||||
|
GetDashboardACL string = "getDashboardACL"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
httpStatusCodes := []string{"200", "404", "500", "unknown"}
|
httpStatusCodes := []string{"200", "404", "500", "unknown"}
|
||||||
objectiveMap := map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
|
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}
|
||||||
|
|
||||||
MInstanceStart = prometheus.NewCounter(prometheus.CounterOpts{
|
MInstanceStart = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
Name: "instance_start_total",
|
Name: "instance_start_total",
|
||||||
@@ -456,6 +474,12 @@ func init() {
|
|||||||
Namespace: ExporterName,
|
Namespace: ExporterName,
|
||||||
}, []string{"datasource", "status"}, map[string][]string{"status": pubdash.QueryResultStatuses})
|
}, []string{"datasource", "status"}, map[string][]string{"status": pubdash.QueryResultStatuses})
|
||||||
|
|
||||||
|
MFolderIDsAPICount = metricutil.NewCounterVecStartingAtZero(prometheus.CounterOpts{
|
||||||
|
Name: "folder_id_api_count",
|
||||||
|
Help: "counter for folder id usage in api package",
|
||||||
|
Namespace: ExporterName,
|
||||||
|
}, []string{"method"}, map[string][]string{"method": apiFolderIDMethods})
|
||||||
|
|
||||||
MStatTotalDashboards = prometheus.NewGauge(prometheus.GaugeOpts{
|
MStatTotalDashboards = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "stat_totals_dashboard",
|
Name: "stat_totals_dashboard",
|
||||||
Help: "total amount of dashboards",
|
Help: "total amount of dashboards",
|
||||||
@@ -747,5 +771,6 @@ func initMetricVars(reg prometheus.Registerer) {
|
|||||||
MPublicDashboardRequestCount,
|
MPublicDashboardRequestCount,
|
||||||
MPublicDashboardDatasourceQuerySuccess,
|
MPublicDashboardDatasourceQuerySuccess,
|
||||||
MStatTotalCorrelations,
|
MStatTotalCorrelations,
|
||||||
|
MFolderIDsAPICount,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user