mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 07:34:04 -08:00
promql: refactor: extract fn to wait on concurrency limit
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
21c605a264
commit
621d29795d
|
@ -589,18 +589,11 @@ func (ng *Engine) exec(ctx context.Context, q *query) (v parser.Value, ws storag
|
|||
execSpanTimer, ctx := q.stats.GetSpanTimer(ctx, stats.ExecTotalTime)
|
||||
defer execSpanTimer.Finish()
|
||||
|
||||
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
|
||||
// MaxConcurrent queries.
|
||||
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)
|
||||
if finish, err := ng.queueActive(ctx, q); err != nil {
|
||||
return nil, nil, err
|
||||
} else {
|
||||
defer finish()
|
||||
}
|
||||
queueSpanTimer.Finish()
|
||||
|
||||
// Cancel when execution is done or an error was raised.
|
||||
defer q.cancel()
|
||||
|
@ -623,6 +616,18 @@ func (ng *Engine) exec(ctx context.Context, q *query) (v parser.Value, ws storag
|
|||
panic(fmt.Errorf("promql.Engine.exec: unhandled statement of type %T", q.Statement()))
|
||||
}
|
||||
|
||||
// Log query in active log. The active log guarantees that we don't run over
|
||||
// MaxConcurrent queries.
|
||||
func (ng *Engine) queueActive(ctx context.Context, q *query) (func(), error) {
|
||||
if ng.activeQueryTracker == nil {
|
||||
return func() {}, nil
|
||||
}
|
||||
queueSpanTimer, _ := q.stats.GetSpanTimer(ctx, stats.ExecQueueTime, ng.metrics.queryQueueTime)
|
||||
queryIndex, err := ng.activeQueryTracker.Insert(ctx, q.q)
|
||||
queueSpanTimer.Finish()
|
||||
return func() { ng.activeQueryTracker.Delete(queryIndex) }, err
|
||||
}
|
||||
|
||||
func timeMilliseconds(t time.Time) int64 {
|
||||
return t.UnixNano() / int64(time.Millisecond/time.Nanosecond)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue