Repurpose FederatedContextFunc into GroupEvaluationContextFunc

This commit is contained in:
Dimitar Dimitrov 2021-11-26 14:03:40 +01:00
parent 42a7f1e210
commit 75d3c11278
No known key found for this signature in database
GPG key ID: 4541B04E6C90EBC3
2 changed files with 19 additions and 19 deletions

View file

@ -903,7 +903,7 @@ type Manager struct {
// NotifyFunc sends notifications about a set of alerts generated by the given expression. // NotifyFunc sends notifications about a set of alerts generated by the given expression.
type NotifyFunc func(ctx context.Context, expr string, alerts ...*Alert) type NotifyFunc func(ctx context.Context, expr string, alerts ...*Alert)
type ContextFunc func(g *Group) context.Context type ContextWrapFunc func(ctx context.Context, g *Group) context.Context
// ManagerOptions bundles options for the Manager. // ManagerOptions bundles options for the Manager.
type ManagerOptions struct { type ManagerOptions struct {
@ -911,16 +911,17 @@ type ManagerOptions struct {
QueryFunc QueryFunc QueryFunc QueryFunc
NotifyFunc NotifyFunc NotifyFunc NotifyFunc
Context context.Context Context context.Context
// FederatedContextFunc will be called to obtain a context when evaluating rules with non-empty SourceTenants // GroupEvaluationContextFunc will be called to wrap Context based on the group being evaluated.
FederatedContextFunc ContextFunc // Will be skipped if nil.
Appendable storage.Appendable GroupEvaluationContextFunc ContextWrapFunc
Queryable storage.Queryable Appendable storage.Appendable
Logger log.Logger Queryable storage.Queryable
Registerer prometheus.Registerer Logger log.Logger
OutageTolerance time.Duration Registerer prometheus.Registerer
ForGracePeriod time.Duration OutageTolerance time.Duration
ResendDelay time.Duration ForGracePeriod time.Duration
GroupLoader GroupLoader ResendDelay time.Duration
GroupLoader GroupLoader
Metrics *Metrics Metrics *Metrics
} }
@ -1014,8 +1015,8 @@ func (m *Manager) Update(interval time.Duration, files []string, externalLabels
wg.Done() wg.Done()
ctx := m.opts.Context ctx := m.opts.Context
if len(newg.sourceTenants) > 0 { if m.opts.GroupEvaluationContextFunc != nil {
ctx = m.opts.FederatedContextFunc(newg) ctx = m.opts.GroupEvaluationContextFunc(ctx, newg)
} }
// Wait with starting evaluation until the rule manager // Wait with starting evaluation until the rule manager
// is told to run. This is necessary to avoid running // is told to run. This is necessary to avoid running

View file

@ -718,12 +718,11 @@ func TestUpdate(t *testing.T) {
} }
engine := promql.NewEngine(opts) engine := promql.NewEngine(opts)
ruleManager := NewManager(&ManagerOptions{ ruleManager := NewManager(&ManagerOptions{
Appendable: st, Appendable: st,
Queryable: st, Queryable: st,
QueryFunc: EngineQueryFunc(engine, st), QueryFunc: EngineQueryFunc(engine, st),
Context: context.Background(), Context: context.Background(),
FederatedContextFunc: func(*Group) context.Context { return context.Background() }, Logger: log.NewNopLogger(),
Logger: log.NewNopLogger(),
}) })
ruleManager.start() ruleManager.start()
defer ruleManager.Stop() defer ruleManager.Stop()