mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Search: add request metrics (#53028)
* Search: add request metrics * Search: consistent naming * Search: remove success counter * Search: update buckets * Search: remove log
This commit is contained in:
parent
cea4b3fb19
commit
784cfcf2b0
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
@ -13,10 +14,40 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/services/store"
|
"github.com/grafana/grafana/pkg/services/store"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
|
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
namespace = "grafana"
|
||||||
|
subsystem = "search"
|
||||||
|
dashboardSearchFailureRequestsCounter = promauto.NewCounterVec(
|
||||||
|
prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "dashboard_search_failures_total",
|
||||||
|
Help: "A counter for failed dashboard search requests",
|
||||||
|
},
|
||||||
|
[]string{"reason"},
|
||||||
|
)
|
||||||
|
dashboardSearchSuccessRequestsDuration = promauto.NewHistogram(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "dashboard_search_successes_duration_seconds",
|
||||||
|
Buckets: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 50, 100},
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
})
|
||||||
|
dashboardSearchFailureRequestsDuration = promauto.NewHistogram(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "dashboard_search_failures_duration_seconds",
|
||||||
|
Buckets: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 50, 100},
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
type StandardSearchService struct {
|
type StandardSearchService struct {
|
||||||
registry.BackgroundService
|
registry.BackgroundService
|
||||||
|
|
||||||
@ -150,27 +181,53 @@ func (s *StandardSearchService) getUser(ctx context.Context, backendUser *backen
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *StandardSearchService) DoDashboardQuery(ctx context.Context, user *backend.User, orgID int64, q DashboardQuery) *backend.DataResponse {
|
func (s *StandardSearchService) DoDashboardQuery(ctx context.Context, user *backend.User, orgID int64, q DashboardQuery) *backend.DataResponse {
|
||||||
|
start := time.Now()
|
||||||
|
query := s.doDashboardQuery(ctx, user, orgID, q)
|
||||||
|
|
||||||
|
duration := time.Since(start).Seconds()
|
||||||
|
if query.Error != nil {
|
||||||
|
dashboardSearchFailureRequestsDuration.Observe(duration)
|
||||||
|
} else {
|
||||||
|
dashboardSearchSuccessRequestsDuration.Observe(duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StandardSearchService) doDashboardQuery(ctx context.Context, user *backend.User, orgID int64, q DashboardQuery) *backend.DataResponse {
|
||||||
rsp := &backend.DataResponse{}
|
rsp := &backend.DataResponse{}
|
||||||
signedInUser, err := s.getUser(ctx, user, orgID)
|
signedInUser, err := s.getUser(ctx, user, orgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
dashboardSearchFailureRequestsCounter.With(prometheus.Labels{
|
||||||
|
"reason": "get_user_error",
|
||||||
|
}).Inc()
|
||||||
rsp.Error = err
|
rsp.Error = err
|
||||||
return rsp
|
return rsp
|
||||||
}
|
}
|
||||||
|
|
||||||
filter, err := s.auth.GetDashboardReadFilter(signedInUser)
|
filter, err := s.auth.GetDashboardReadFilter(signedInUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
dashboardSearchFailureRequestsCounter.With(prometheus.Labels{
|
||||||
|
"reason": "get_dashboard_filter_error",
|
||||||
|
}).Inc()
|
||||||
rsp.Error = err
|
rsp.Error = err
|
||||||
return rsp
|
return rsp
|
||||||
}
|
}
|
||||||
|
|
||||||
index, err := s.dashboardIndex.getOrCreateOrgIndex(ctx, orgID)
|
index, err := s.dashboardIndex.getOrCreateOrgIndex(ctx, orgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
dashboardSearchFailureRequestsCounter.With(prometheus.Labels{
|
||||||
|
"reason": "get_index_error",
|
||||||
|
}).Inc()
|
||||||
rsp.Error = err
|
rsp.Error = err
|
||||||
return rsp
|
return rsp
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.dashboardIndex.sync(ctx)
|
err = s.dashboardIndex.sync(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
dashboardSearchFailureRequestsCounter.With(prometheus.Labels{
|
||||||
|
"reason": "dashboard_index_sync_error",
|
||||||
|
}).Inc()
|
||||||
rsp.Error = err
|
rsp.Error = err
|
||||||
return rsp
|
return rsp
|
||||||
}
|
}
|
||||||
@ -183,5 +240,11 @@ func (s *StandardSearchService) DoDashboardQuery(ctx context.Context, user *back
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if response.Error != nil {
|
||||||
|
dashboardSearchFailureRequestsCounter.With(prometheus.Labels{
|
||||||
|
"reason": "search_query_error",
|
||||||
|
}).Inc()
|
||||||
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user