Merge pull request #12251 from prymitive/query_samples_total

Add query_samples_total metric
This commit is contained in:
Julien Pivotto 2023-04-20 15:48:24 +02:00 committed by GitHub
commit f7c6130ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -70,6 +70,7 @@ type engineMetrics struct {
queryPrepareTime prometheus.Observer queryPrepareTime prometheus.Observer
queryInnerEval prometheus.Observer queryInnerEval prometheus.Observer
queryResultSort prometheus.Observer queryResultSort prometheus.Observer
querySamples prometheus.Counter
} }
// convertibleToInt64 returns true if v does not over-/underflow an int64. // convertibleToInt64 returns true if v does not over-/underflow an int64.
@ -333,6 +334,12 @@ func NewEngine(opts EngineOpts) *Engine {
Name: "queries_concurrent_max", Name: "queries_concurrent_max",
Help: "The max number of concurrent queries.", Help: "The max number of concurrent queries.",
}), }),
querySamples: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "query_samples_total",
Help: "The total number of samples loaded by all queries.",
}),
queryQueueTime: queryResultSummary.WithLabelValues("queue_time"), queryQueueTime: queryResultSummary.WithLabelValues("queue_time"),
queryPrepareTime: queryResultSummary.WithLabelValues("prepare_time"), queryPrepareTime: queryResultSummary.WithLabelValues("prepare_time"),
queryInnerEval: queryResultSummary.WithLabelValues("inner_eval"), queryInnerEval: queryResultSummary.WithLabelValues("inner_eval"),
@ -358,6 +365,7 @@ func NewEngine(opts EngineOpts) *Engine {
metrics.maxConcurrentQueries, metrics.maxConcurrentQueries,
metrics.queryLogEnabled, metrics.queryLogEnabled,
metrics.queryLogFailures, metrics.queryLogFailures,
metrics.querySamples,
queryResultSummary, queryResultSummary,
) )
} }
@ -538,7 +546,10 @@ func (ng *Engine) newTestQuery(f func(context.Context) error) Query {
// statements are not handled by the Engine. // statements are not handled by the Engine.
func (ng *Engine) exec(ctx context.Context, q *query) (v parser.Value, ws storage.Warnings, err error) { func (ng *Engine) exec(ctx context.Context, q *query) (v parser.Value, ws storage.Warnings, err error) {
ng.metrics.currentQueries.Inc() ng.metrics.currentQueries.Inc()
defer ng.metrics.currentQueries.Dec() defer func() {
ng.metrics.currentQueries.Dec()
ng.metrics.querySamples.Add(float64(q.sampleStats.TotalSamples))
}()
ctx, cancel := context.WithTimeout(ctx, ng.timeout) ctx, cancel := context.WithTimeout(ctx, ng.timeout)
q.cancel = cancel q.cancel = cancel