|
|
@ -33,7 +33,6 @@ import (
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/common/model"
|
|
|
|
"github.com/prometheus/common/model"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/prometheus/prometheus/pkg/gate"
|
|
|
|
|
|
|
|
"github.com/prometheus/prometheus/pkg/labels"
|
|
|
|
"github.com/prometheus/prometheus/pkg/labels"
|
|
|
|
"github.com/prometheus/prometheus/pkg/timestamp"
|
|
|
|
"github.com/prometheus/prometheus/pkg/timestamp"
|
|
|
|
"github.com/prometheus/prometheus/pkg/value"
|
|
|
|
"github.com/prometheus/prometheus/pkg/value"
|
|
|
@ -189,12 +188,6 @@ func (q *query) Exec(ctx context.Context) *Result {
|
|
|
|
span.SetTag(queryTag, q.stmt.String())
|
|
|
|
span.SetTag(queryTag, q.stmt.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Log query in active log.
|
|
|
|
|
|
|
|
if q.ng.activeQueryTracker != nil {
|
|
|
|
|
|
|
|
queryIndex := q.ng.activeQueryTracker.Insert(q.q)
|
|
|
|
|
|
|
|
defer q.ng.activeQueryTracker.Delete(queryIndex)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Exec query.
|
|
|
|
// Exec query.
|
|
|
|
res, warnings, err := q.ng.exec(ctx, q)
|
|
|
|
res, warnings, err := q.ng.exec(ctx, q)
|
|
|
|
|
|
|
|
|
|
|
@ -236,7 +229,6 @@ type Engine struct {
|
|
|
|
logger log.Logger
|
|
|
|
logger log.Logger
|
|
|
|
metrics *engineMetrics
|
|
|
|
metrics *engineMetrics
|
|
|
|
timeout time.Duration
|
|
|
|
timeout time.Duration
|
|
|
|
gate *gate.Gate
|
|
|
|
|
|
|
|
maxSamplesPerQuery int
|
|
|
|
maxSamplesPerQuery int
|
|
|
|
activeQueryTracker *ActiveQueryTracker
|
|
|
|
activeQueryTracker *ActiveQueryTracker
|
|
|
|
queryLogger QueryLogger
|
|
|
|
queryLogger QueryLogger
|
|
|
@ -323,7 +315,6 @@ func NewEngine(opts EngineOpts) *Engine {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return &Engine{
|
|
|
|
return &Engine{
|
|
|
|
gate: gate.New(opts.MaxConcurrent),
|
|
|
|
|
|
|
|
timeout: opts.Timeout,
|
|
|
|
timeout: opts.Timeout,
|
|
|
|
logger: opts.Logger,
|
|
|
|
logger: opts.Logger,
|
|
|
|
metrics: metrics,
|
|
|
|
metrics: metrics,
|
|
|
@ -466,12 +457,16 @@ func (ng *Engine) exec(ctx context.Context, q *query) (v Value, w storage.Warnin
|
|
|
|
defer execSpanTimer.Finish()
|
|
|
|
defer execSpanTimer.Finish()
|
|
|
|
|
|
|
|
|
|
|
|
queueSpanTimer, _ := q.stats.GetSpanTimer(ctx, stats.ExecQueueTime, ng.metrics.queryQueueTime)
|
|
|
|
queueSpanTimer, _ := q.stats.GetSpanTimer(ctx, stats.ExecQueueTime, ng.metrics.queryQueueTime)
|
|
|
|
|
|
|
|
// Log query in active log. The active log guarantees that we don't run over
|
|
|
|
if err := ng.gate.Start(ctx); err != nil {
|
|
|
|
// MaxConcurrent queries.
|
|
|
|
return nil, nil, contextErr(err, "query queue")
|
|
|
|
if ng.activeQueryTracker != nil {
|
|
|
|
|
|
|
|
queryIndex, err := ng.activeQueryTracker.Insert(ctx, q.q)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
queueSpanTimer.Finish()
|
|
|
|
|
|
|
|
return nil, nil, contextErr(err, "query queue")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer ng.activeQueryTracker.Delete(queryIndex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer ng.gate.Done()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queueSpanTimer.Finish()
|
|
|
|
queueSpanTimer.Finish()
|
|
|
|
|
|
|
|
|
|
|
|
// Cancel when execution is done or an error was raised.
|
|
|
|
// Cancel when execution is done or an error was raised.
|
|
|
|