mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Rule Concurrency: Simpler loop for sequential (default) executions (#15801)
Some checks failed
buf.build / lint and publish (push) Has been cancelled
CI / Go tests (push) Has been cancelled
CI / More Go tests (push) Has been cancelled
CI / Go tests with previous Go version (push) Has been cancelled
CI / UI tests (push) Has been cancelled
CI / Go tests on Windows (push) Has been cancelled
CI / Mixins tests (push) Has been cancelled
CI / Build Prometheus for common architectures (0) (push) Has been cancelled
CI / Build Prometheus for common architectures (1) (push) Has been cancelled
CI / Build Prometheus for common architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (0) (push) Has been cancelled
CI / Build Prometheus for all architectures (1) (push) Has been cancelled
CI / Build Prometheus for all architectures (10) (push) Has been cancelled
CI / Build Prometheus for all architectures (11) (push) Has been cancelled
CI / Build Prometheus for all architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (3) (push) Has been cancelled
CI / Build Prometheus for all architectures (4) (push) Has been cancelled
CI / Build Prometheus for all architectures (5) (push) Has been cancelled
CI / Build Prometheus for all architectures (6) (push) Has been cancelled
CI / Build Prometheus for all architectures (7) (push) Has been cancelled
CI / Build Prometheus for all architectures (8) (push) Has been cancelled
CI / Build Prometheus for all architectures (9) (push) Has been cancelled
CI / Check generated parser (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / fuzzing (push) Has been cancelled
CI / codeql (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CI / Report status of build Prometheus for all architectures (push) Has been cancelled
CI / Publish main branch artifacts (push) Has been cancelled
CI / Publish release artefacts (push) Has been cancelled
CI / Publish UI on npm Registry (push) Has been cancelled
Some checks failed
buf.build / lint and publish (push) Has been cancelled
CI / Go tests (push) Has been cancelled
CI / More Go tests (push) Has been cancelled
CI / Go tests with previous Go version (push) Has been cancelled
CI / UI tests (push) Has been cancelled
CI / Go tests on Windows (push) Has been cancelled
CI / Mixins tests (push) Has been cancelled
CI / Build Prometheus for common architectures (0) (push) Has been cancelled
CI / Build Prometheus for common architectures (1) (push) Has been cancelled
CI / Build Prometheus for common architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (0) (push) Has been cancelled
CI / Build Prometheus for all architectures (1) (push) Has been cancelled
CI / Build Prometheus for all architectures (10) (push) Has been cancelled
CI / Build Prometheus for all architectures (11) (push) Has been cancelled
CI / Build Prometheus for all architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (3) (push) Has been cancelled
CI / Build Prometheus for all architectures (4) (push) Has been cancelled
CI / Build Prometheus for all architectures (5) (push) Has been cancelled
CI / Build Prometheus for all architectures (6) (push) Has been cancelled
CI / Build Prometheus for all architectures (7) (push) Has been cancelled
CI / Build Prometheus for all architectures (8) (push) Has been cancelled
CI / Build Prometheus for all architectures (9) (push) Has been cancelled
CI / Check generated parser (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / fuzzing (push) Has been cancelled
CI / codeql (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CI / Report status of build Prometheus for all architectures (push) Has been cancelled
CI / Publish main branch artifacts (push) Has been cancelled
CI / Publish release artefacts (push) Has been cancelled
CI / Publish UI on npm Registry (push) Has been cancelled
This commit is contained in:
parent
f030894c2c
commit
0a19f1268e
|
@ -643,28 +643,46 @@ func (g *Group) Eval(ctx context.Context, ts time.Time) {
|
||||||
if ctrl == nil {
|
if ctrl == nil {
|
||||||
ctrl = sequentialRuleEvalController{}
|
ctrl = sequentialRuleEvalController{}
|
||||||
}
|
}
|
||||||
for _, batch := range ctrl.SplitGroupIntoBatches(ctx, g) {
|
|
||||||
for _, ruleIndex := range batch {
|
batches := ctrl.SplitGroupIntoBatches(ctx, g)
|
||||||
|
if len(batches) == 0 {
|
||||||
|
// Sequential evaluation when batches aren't set.
|
||||||
|
// This is the behaviour without a defined RuleConcurrencyController
|
||||||
|
for i, rule := range g.rules {
|
||||||
|
// Check if the group has been stopped.
|
||||||
select {
|
select {
|
||||||
case <-g.done:
|
case <-g.done:
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
eval(i, rule, nil)
|
||||||
rule := g.rules[ruleIndex]
|
}
|
||||||
if len(batch) > 1 && ctrl.Allow(ctx, g, rule) {
|
} else {
|
||||||
wg.Add(1)
|
// Concurrent evaluation.
|
||||||
|
for _, batch := range batches {
|
||||||
go eval(ruleIndex, rule, func() {
|
for _, ruleIndex := range batch {
|
||||||
wg.Done()
|
// Check if the group has been stopped.
|
||||||
ctrl.Done(ctx)
|
select {
|
||||||
})
|
case <-g.done:
|
||||||
} else {
|
wg.Wait()
|
||||||
eval(ruleIndex, rule, nil)
|
return
|
||||||
}
|
default:
|
||||||
|
}
|
||||||
|
rule := g.rules[ruleIndex]
|
||||||
|
if len(batch) > 1 && ctrl.Allow(ctx, g, rule) {
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
|
go eval(ruleIndex, rule, func() {
|
||||||
|
wg.Done()
|
||||||
|
ctrl.Done(ctx)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
eval(ruleIndex, rule, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// It is important that we finish processing any rules in this current batch - before we move into the next one.
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
// It is important that we finish processing any rules in this current batch - before we move into the next one.
|
|
||||||
wg.Wait()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g.metrics.GroupSamples.WithLabelValues(GroupKey(g.File(), g.Name())).Set(samplesTotal.Load())
|
g.metrics.GroupSamples.WithLabelValues(GroupKey(g.File(), g.Name())).Set(samplesTotal.Load())
|
||||||
|
|
|
@ -550,11 +550,7 @@ func (c sequentialRuleEvalController) Allow(_ context.Context, _ *Group, _ Rule)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c sequentialRuleEvalController) SplitGroupIntoBatches(_ context.Context, g *Group) []ConcurrentRules {
|
func (c sequentialRuleEvalController) SplitGroupIntoBatches(_ context.Context, g *Group) []ConcurrentRules {
|
||||||
order := make([]ConcurrentRules, len(g.rules))
|
return nil
|
||||||
for i := range g.rules {
|
|
||||||
order[i] = []int{i}
|
|
||||||
}
|
|
||||||
return order
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c sequentialRuleEvalController) Done(_ context.Context) {}
|
func (c sequentialRuleEvalController) Done(_ context.Context) {}
|
||||||
|
|
|
@ -1989,12 +1989,7 @@ func TestAsyncRuleEvaluation(t *testing.T) {
|
||||||
|
|
||||||
// Expected evaluation order
|
// Expected evaluation order
|
||||||
order := group.opts.RuleConcurrencyController.SplitGroupIntoBatches(ctx, group)
|
order := group.opts.RuleConcurrencyController.SplitGroupIntoBatches(ctx, group)
|
||||||
require.Equal(t, []ConcurrentRules{
|
require.Nil(t, order)
|
||||||
{0},
|
|
||||||
{1},
|
|
||||||
{2},
|
|
||||||
{3},
|
|
||||||
}, order)
|
|
||||||
|
|
||||||
// Never expect more than 1 inflight query at a time.
|
// Never expect more than 1 inflight query at a time.
|
||||||
require.EqualValues(t, 1, maxInflight.Load())
|
require.EqualValues(t, 1, maxInflight.Load())
|
||||||
|
|
Loading…
Reference in a new issue