Skip to content

Commit

Permalink
fix copy lock issues in alerting runner
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreLamarre committed Oct 24, 2023
1 parent 67948bb commit 44654a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions plugins/alerting/pkg/alerting/alarms/v1/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions plugins/alerting/pkg/alerting/alarms/v1/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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,
})
Expand Down

0 comments on commit 44654a8

Please sign in to comment.