From 44654a83499cee124c77c2f13e128532ffe7cfa8 Mon Sep 17 00:00:00 2001 From: Alexandre Lamarre Date: Wed, 4 Oct 2023 14:24:41 -0400 Subject: [PATCH] fix copy lock issues in alerting runner --- plugins/alerting/pkg/alerting/alarms/v1/runner.go | 10 +++++----- plugins/alerting/pkg/alerting/alarms/v1/streams.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/alerting/pkg/alerting/alarms/v1/runner.go b/plugins/alerting/pkg/alerting/alarms/v1/runner.go index e66543efe3..a178d3329f 100644 --- a/plugins/alerting/pkg/alerting/alarms/v1/runner.go +++ b/plugins/alerting/pkg/alerting/alarms/v1/runner.go @@ -9,22 +9,22 @@ import ( type EvaluatorContext struct { Ctx context.Context Cancel context.CancelFunc - running atomic.Bool + running *atomic.Bool } type Runner struct { // conditionId -> subsriber pull context cancel func - systemConditionUpdateListeners map[string]EvaluatorContext - systemConditionMu sync.Mutex + systemConditionUpdateListeners map[string]*EvaluatorContext + systemConditionMu *sync.Mutex } func NewRunner() *Runner { return &Runner{ - systemConditionUpdateListeners: make(map[string]EvaluatorContext), + systemConditionUpdateListeners: make(map[string]*EvaluatorContext), } } -func (n *Runner) AddSystemConfigListener(conditionId string, eCtx EvaluatorContext) { +func (n *Runner) AddSystemConfigListener(conditionId string, eCtx *EvaluatorContext) { n.systemConditionMu.Lock() defer n.systemConditionMu.Unlock() if oldContext, ok := n.systemConditionUpdateListeners[conditionId]; ok { diff --git a/plugins/alerting/pkg/alerting/alarms/v1/streams.go b/plugins/alerting/pkg/alerting/alarms/v1/streams.go index 85819e1e00..b6e1ab85f8 100644 --- a/plugins/alerting/pkg/alerting/alarms/v1/streams.go +++ b/plugins/alerting/pkg/alerting/alarms/v1/streams.go @@ -156,7 +156,7 @@ func (p *AlarmServerComponent) onSystemConditionCreate(conditionId, conditionNam defer cancel() // cancel parent context, if we return (non-recoverable) evaluator.EvaluateLoop() }() - p.runner.AddSystemConfigListener(conditionId, EvaluatorContext{ + p.runner.AddSystemConfigListener(conditionId, &EvaluatorContext{ Ctx: evaluator.evaluationCtx, Cancel: evaluator.cancelEvaluation, }) @@ -248,7 +248,7 @@ func (p *AlarmServerComponent) onDownstreamCapabilityConditionCreate(conditionId defer cancel() // cancel parent context, if we return (non-recoverable) evaluator.EvaluateLoop() }() - p.runner.AddSystemConfigListener(conditionId, EvaluatorContext{ + p.runner.AddSystemConfigListener(conditionId, &EvaluatorContext{ Ctx: evaluator.evaluationCtx, Cancel: evaluator.cancelEvaluation, }) @@ -486,7 +486,7 @@ func (p *AlarmServerComponent) onCortexClusterStatusCreate(conditionId, conditio defer cancel() // cancel parent context, if we return (non-recoverable) evaluator.EvaluateLoop() }() - p.runner.AddSystemConfigListener(conditionId, EvaluatorContext{ + p.runner.AddSystemConfigListener(conditionId, &EvaluatorContext{ Ctx: evaluator.evaluationCtx, Cancel: evaluator.cancelEvaluation, })