mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 01:16:31 -06:00
Expressions: Measure total transformation requests and elapsed time (#30514)
* Measure transformation number and elapsed time * Change histogram to summary * Apply suggestions from code review Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
This commit is contained in:
parent
a3d765830e
commit
2f394a219b
@ -11,11 +11,30 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/tsdb"
|
"github.com/grafana/grafana/pkg/tsdb"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
expressionsQuerySummary *prometheus.SummaryVec
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
expressionsQuerySummary = prometheus.NewSummaryVec(
|
||||||
|
prometheus.SummaryOpts{
|
||||||
|
Name: "expressions_queries_duration_milliseconds",
|
||||||
|
Help: "Expressions query summary",
|
||||||
|
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
||||||
|
},
|
||||||
|
[]string{"status"},
|
||||||
|
)
|
||||||
|
|
||||||
|
prometheus.MustRegister(expressionsQuerySummary)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapTransformData creates and executes transform requests
|
||||||
func (s *Service) WrapTransformData(ctx context.Context, query *tsdb.TsdbQuery) (*tsdb.Response, error) {
|
func (s *Service) WrapTransformData(ctx context.Context, query *tsdb.TsdbQuery) (*tsdb.Response, error) {
|
||||||
sdkReq := &backend.QueryDataRequest{
|
sdkReq := &backend.QueryDataRequest{
|
||||||
PluginContext: backend.PluginContext{
|
PluginContext: backend.PluginContext{
|
||||||
@ -69,11 +88,24 @@ func (s *Service) WrapTransformData(ctx context.Context, query *tsdb.TsdbQuery)
|
|||||||
|
|
||||||
// TransformData takes Queries which are either expressions nodes
|
// TransformData takes Queries which are either expressions nodes
|
||||||
// or are datasource requests.
|
// or are datasource requests.
|
||||||
func (s *Service) TransformData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
func (s *Service) TransformData(ctx context.Context, req *backend.QueryDataRequest) (r *backend.QueryDataResponse, err error) {
|
||||||
if s.isDisabled() {
|
if s.isDisabled() {
|
||||||
return nil, status.Error(codes.PermissionDenied, "Expressions are disabled")
|
return nil, status.Error(codes.PermissionDenied, "Expressions are disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
defer func() {
|
||||||
|
var respStatus string
|
||||||
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
respStatus = "success"
|
||||||
|
default:
|
||||||
|
respStatus = "failure"
|
||||||
|
}
|
||||||
|
duration := float64(time.Since(start).Nanoseconds()) / float64(time.Millisecond)
|
||||||
|
expressionsQuerySummary.WithLabelValues(respStatus).Observe(duration)
|
||||||
|
}()
|
||||||
|
|
||||||
// Build the pipeline from the request, checking for ordering issues (e.g. loops)
|
// Build the pipeline from the request, checking for ordering issues (e.g. loops)
|
||||||
// and parsing graph nodes from the queries.
|
// and parsing graph nodes from the queries.
|
||||||
pipeline, err := s.BuildPipeline(req)
|
pipeline, err := s.BuildPipeline(req)
|
||||||
|
Loading…
Reference in New Issue
Block a user